Friday, December 16, 2011

C# type and F# representation


Today I got a question about how to map the following structure to F#. Nothing fancy, but it might help somebody transfer C# skill to F#.

namespace OuterNamespace
{    public sealed class PublicSealedClass { }
     internal sealed class FriendSealedClass { }
     public abstract class PublicAbstractClass { }
     internal abstract class FriendAbstractClass { }
     public class PublicClass { }
     internal class FriendClass { }
     public interface PublicInterface { }
     internal interface FriendInterface { }
     public struct PublicStructure { }
     internal struct FriendStructure { }
     public enum PublicEnum { }
     internal enum FriendEnum { }
}


F# code:



namespace OuterNamespace

[ < Sealed > ]
type PublicSealedClass() = class end

[ < Sealed > ]
type internal FriendSealedClass() = class end

[ < Sealed > ]
type PublicAbstractClass () = class end

[ < AbstractClass > ]
type internal FriendAbstractClass  () = class end

type PublicClass () = class end
type internal FriendClass () = class end

type PublicInterface = interface end
type internal FriendInterface = interface end

[ < StructAttribute > ]
type PublicStructure = struct end

[ < StructAttribute > ]
type internal FriendStructure  = struct end

//we do not support empty enum, so must have something inside.
type PublicEnum =
    Element = 0

type internal FriendEnum  =
    Element = 0


No comments: