I'm not sure if this helps, but you can generally avoid using the lazy keyword if you really want for some reason:
type ('a, 'b) lazyT = Lz of 'a * ('a -> 'b) let force (Lz (a, e)) = ea let pack x = Lz(x, (fun i -> i)) type MyLazyBuilder = | Mylazy member this.Bind(x, f) = match x with | Lz(xa, xe) -> Lz(xa, fun x -> force (f (xe x))) member this.Return(x) = pack x let sth = Mylazy { let! x = pack 12 let! y = pack (x + 1) return y * x } let res = force sth
(there is no part where the force only evaluates it once).
Late, but thought it was worth the suggestion.
source share