# How to have a static member on a record type that is only evaluated once?

**URL:** <https://forums.fsharp.org/t/how-to-have-a-static-member-on-a-record-type-that-is-only-evaluated-once/465>\
**Category:** General\
**Created:** [September 8, 2018, 5:26pm UTC](https://forums.fsharp.org/t/how-to-have-a-static-member-on-a-record-type-that-is-only-evaluated-once/465 "2018-09-08T17:26:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nelkins](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/nelkins/32/173_2.png) [@Nelkins](https://forums.fsharp.org/u/Nelkins)\
**Post date:** [September 8, 2018, 5:26pm UTC](https://forums.fsharp.org/t/how-to-have-a-static-member-on-a-record-type-that-is-only-evaluated-once/465/1 "2018-09-08T17:26:18Z")

</div>

Consider the following snippet:

```auto
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?

---

<div class="post-metadata">

**Author:** ![HoraceGonzalez](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/horacegonzalez/32/352_2.png) [@HoraceGonzalez](https://forums.fsharp.org/u/HoraceGonzalez)\
**Post date:** [September 8, 2018, 5:48pm UTC](https://forums.fsharp.org/t/how-to-have-a-static-member-on-a-record-type-that-is-only-evaluated-once/465/2 "2018-09-08T17:48:34Z")

</div>

Have you considered using a `lazy` value? Eg.

```auto
let backingField =
    lazy (
        printfn "constructing value"
        "hi"
    )

let sayHi() = backingField.Force()

sayHi() // prints "constructing value"
sayHi() // doesn't print

```
