Consider the following snippet:
let rnd = Random()
type Schema = private { Value : string }
with
static member create (typ:Type) : Schema =
{
Schema.Value = rnd.Next().ToString()
}
type Test = { value : string }
with
static member Schema : Schema =
printfn "me"
Schema.create typeof<Test>
let s1 = Test.Schema
printfn "%A" s1
let s2 = Test.Schema
printfn "%A" s2
What I’d like to have is the Schema
static member on Test
evaluated only a single time. Is there any way to accomplish this with record types? Or is using the class syntax (type Test() = ...
) the only way?