1Lazy(3)                          OCaml library                         Lazy(3)
2
3
4

NAME

6       Lazy - Deferred computations.
7

Module

9       Module   Lazy
10

Documentation

12       Module Lazy
13        : sig end
14
15
16       Deferred computations.
17
18
19
20
21
22
23       type 'a t = 'a lazy_t
24
25
26       A  value  of type 'a Lazy.t is a deferred computation, called a suspen‐
27       sion, that has a result of type 'a .   The  special  expression  syntax
28       lazy  (expr)  makes  a  suspension of the computation of expr , without
29       computing expr itself yet.  "Forcing" the suspension will then  compute
30       expr and return its result.
31
32       Note:  lazy_t is the built-in type constructor used by the compiler for
33       the lazy keyword.  You should not use it directly.  Always  use  Lazy.t
34       instead.
35
36       Note: if the program is compiled with the -rectypes option, ill-founded
37       recursive definitions of the form let rec x = lazy x or  let  rec  x  =
38       lazy(lazy(...(lazy x))) are accepted by the type-checker and lead, when
39       forced, to ill-formed values that trigger infinite loops in the garbage
40       collector  and  other  parts of the run-time system.  Without the -rec‐
41       types option, such ill-founded recursive definitions  are  rejected  by
42       the type-checker.
43
44
45
46
47       exception Undefined
48
49
50
51
52
53       val force : 'a t -> 'a
54
55
56
57
58
59       ===  force  x forces the suspension x and returns its result.  If x has
60       already been forced, Lazy.force x returns the same value again  without
61       recomputing it. If it raised an exception, the same exception is raised
62       again.  Raise Undefined if the forcing of x tries  to  force  x  itself
63       recursively. ===
64
65
66       val force_val : 'a t -> 'a
67
68
69       force_val  x  forces the suspension x and returns its result.  If x has
70       already been forced, force_val x returns the same value  again  without
71       recomputing  it.   Raise Undefined if the forcing of x tries to force x
72       itself recursively.  If the computation of x raises an exception, it is
73       unspecified  whether force_val x raises the same exception or Undefined
74       .
75
76
77
78
79       val lazy_from_fun : (unit -> 'a) -> 'a t
80
81
82       lazy_from_fun f is the same as lazy (f ()) but slightly more efficient.
83
84
85
86
87       val lazy_from_val : 'a -> 'a t
88
89
90       lazy_from_val v returns an already-forced suspension of v This  is  for
91       special purposes only and should not be confused with lazy (v) .
92
93
94
95
96       val lazy_is_val : 'a t -> bool
97
98
99       lazy_is_val  x  returns  true  if x has already been forced and did not
100       raise an exception.
101
102
103
104
105
106
107OCamldoc                          2017-03-22                           Lazy(3)
Impressum