diff options
author | Florian Angeletti <octa@polychoron.fr> | 2018-12-14 17:40:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-14 17:40:43 +0100 |
commit | cbd0753ec62c9e4e71e502c85af0d38c7dfe851c (patch) | |
tree | 2079ec1c0fb66a8a134ee4867cf2c7320bfc57a3 /stdlib/lazy.mli | |
parent | 567d5cc80b66d43dccaf4e3899cc4cde914708f1 (diff) | |
download | ocaml-cbd0753ec62c9e4e71e502c85af0d38c7dfe851c.tar.gz |
manual: move lazy pattern to core (#2198)
Diffstat (limited to 'stdlib/lazy.mli')
-rw-r--r-- | stdlib/lazy.mli | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/stdlib/lazy.mli b/stdlib/lazy.mli index 40bf324705..93b890e231 100644 --- a/stdlib/lazy.mli +++ b/stdlib/lazy.mli @@ -21,7 +21,22 @@ type 'a t = 'a CamlinternalLazy.t expression syntax [lazy (expr)] makes a suspension of the computation of [expr], without computing [expr] itself yet. "Forcing" the suspension will then compute [expr] and return its - result. + result. Matching a suspension with the special pattern syntax + [lazy(pattern)] also computes the underlying expression and + tries to bind it to [pattern]: + + {[ + let lazy_option_map f x = + match x with + | lazy (Some x) -> Some (Lazy.force f x) + | _ -> None + ]} + + Note: If lazy patterns appear in multiple cases in a pattern-matching, + lazy expressions may be forced even outside of the case ultimately selected + by the pattern matching. In the example above, the suspension [x] is always + computed. + Note: [lazy_t] is the built-in type constructor used by the compiler for the [lazy] keyword. You should not use it directly. Always use |