I am C # dev since ancient times.
I study F # and use it for scientific purposes / research / approbation. I find many of my functionality powerful, but I try to write classes - the main thing I know is to do very well in C #.
Which would help me (and the community) translate the following C # code.
class CoolAttribute : Attribute { } class BaseClass { public BaseClass(int zzz) {
F # translation [work in progress, for updating with answers]:
//// wrong ... //type CoolAtribute = // extend Attribute type BaseClass(zzz : int) = // virtual abstract XHello : unit -> unit default this.XHello() = printfn "I'm BaseClass." // seems Ok type IFirst = abstract Hello : unit type ISecond = abstract MagicNumber : int [<DebuggerDisplay("pubI = {pubI}")>] // ???? type SampleClass() = inherit BaseClass(0) // necessary argument ? 1 constructor // implements IFirst, ISecond let mutable privI = 0 // initialization required // protI // pubI // wrong: //let static mutable s_privStr = "" // static constructor // event OnSomething // seems Ok member this.PubI with get() = privI and set(value) = privI <- value // ?? //static member StatStr // with get() = s_privStr // and set(value) = s_privStr <- value // Default constructor // Other constructor // C#: SampleClass(int a, int b, int c) [<Conditional("DEBUG")>] member this.PubSimpleMethod() = do ignore abstract ProtVirtMethod : unit -> unit //protected default this.ProtVirtMethod() = // raise event OnSomething("From the virt method."); //private //static member this.PrivStatMethod() = do ignore member this.Hello() = printfn "Hello (IFirst)" // override member this.XHello() = printfn "I'm SampleClass" member this.MagicNumber() : int = privI + protI + pubI // apply attribute to the argument member this.Additional( (*[Cool*) i :int) = do ignore // operator +
source share