Jon G
Jon G

Reputation: 4164

Compile error when union case has same name as type

In this example on the last line, I want to create an instance of the type A but I get a compile error. When I hover over A("A1") I can see that A is taken to refer to the union case TM.A and not the type A. Can anyone explain what the compiler is doing here and how to avoid this error without needing to change the name of the union case (I'd like it to be the same as the type name)

type A(name:string)
    = member this.Name = name

type T(name:string)
    = member this.Name = name

type TK(t:T, a:List<A>) =
    member this.T = t
    member this.A = a

type TM =
    | T of T 
    | A of A 
    | G of List<T>

let a = A("A1")

Upvotes: 1

Views: 271

Answers (1)

3615
3615

Reputation: 3875

I think the easiest way would be just calling it with new, like new A("A1").

Upvotes: 3

Related Questions