I think it’s almost fine as is. My two cents:
- No point in sugaring it only on the one side:
lazy({})as a sort of built-in, but no accessor (only fully qualifiedLazy.force()) -
forceis a particularly bad name because it signals that an evaluation is being forced no matter if it has before or not (i.e., it actually suggests the opposite of what it does). - For me, I would be happy with:
module Lazy = {
let make: (unit => 'a) => t<'a>
let get: t<'a> => 'a
// and possibly
let isEvaluated: t<'a> => bool
}
I think we could even do type t<'a> ={ get:unit => 'a } since it’s self-mutating anyway
Speaking of sugaring, I would love to see some sugar for deref, i.e. let x = myRef^ instead of let x = myRef.contents which is horribly ugly, leaky and verbose. ;]