Is `lazy` gone or what?

According to docs:

But lazy({...}) doesn’t even compile:

The value lazy can't be found

Is this deprecated, or are docs out of date?

What version of rescript do you use?

I’m on 12 alpha.11 right now.

oh yeah, the lazy keyword got removed from v12, the support was not perfect and it was not commonly used but the Lazy module and Lazy.t<'a> are still here. We should likely improve the Lazy module API so it’s more consistent with the rest of the Stdlib and document this before v12 is released.

If you use lazy, we’d definitely welcome your feedback and/or contribution!

I think it’s almost fine as is. My two cents:

  1. No point in sugaring it only on the one side: lazy({}) as a sort of built-in, but no accessor (only fully qualified Lazy.force())
  2. force is 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).
  3. 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. ;]

1 Like

The API you suggest is nice, looks like a good base for Stdlib.Lazy, we’d then deprecate the existing API which is not very idiomatic. I think we’ll keep Lazy.t abstract though.

Regarding deref, we’re open to an operator, the current syntax is a bit cumbersome, but this is a different topic!

1 Like