如果我正常操作,它会按预期工作(缓存结果):
let help = let tmp = printfn "oh no"
1+1
fun () -> tmp
help ()
help ()
>oh no
但是,如果我将其作为成员函数,它将不再起作用:
type test =
{ a: float }
member x.help =
let tmp = printfn "oh no"
x.a * 2.
fun () -> tmp
member x.b = x.help ()
let t = { a = 1. }
t.b
t.b
>oh no
>oh no