3 people like it.

F# Class Ctors

F# Class constructors with wierd behaviour if more then two are present.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
// Does not compile
type A (a : int option, b : string option) =

    new a = A (a, None)
    new b = A (None, b)

    member __.X = ""


// Compiles
type A (a : int option, b : string option) =

    new (a) = A (a, None)
    new b = A (None, b)

    member __.X = ""
type A =
  new : a:int option -> A
  new : a:int option * b:string option -> A
  member X : string

Full name: Script.A
val a : int option
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
type 'T option = Option<'T>

Full name: Microsoft.FSharp.Core.option<_>
val b : string option
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
new : a:int option * b:string option -> A
union case Option.None: Option<'T>
Multiple items
type A =
  new : a:int option -> A
  new : a:int option * b:string option -> A
  member X : string

Full name: Script.A

--------------------
new : a:int option -> A
new : a:int option * b:string option -> A
member A.X : string

Full name: Script.A.X
val __ : A
property A.X: string
Raw view Test code New version

More information

Link:http://fssnip.net/7Ut
Posted:6 years ago
Author:ChrSt
Tags: constructor;f#