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       force  x  forces  the  suspension  x  and returns its result.  If x has
57       already been forced, Lazy.force x returns the same value again  without
58       recomputing  it.   If  it  raised  an  exception, the same exception is
59       raised again.  Raise Undefined if the forcing of x  tries  to  force  x
60       itself recursively.
61
62
63
64
65       val force_val : 'a t -> 'a
66
67
68       force_val  x  forces the suspension x and returns its result.  If x has
69       already been forced, force_val x returns the same value  again  without
70       recomputing  it.   Raise Undefined if the forcing of x tries to force x
71       itself recursively.  If the computation of x raises an exception, it is
72       unspecified  whether force_val x raises the same exception or Undefined
73       .
74
75
76
77
78       val lazy_from_fun : (unit -> 'a) -> 'a t
79
80
81       lazy_from_fun f is the same as lazy (f ()) but slightly more efficient.
82
83
84
85
86       val lazy_from_val : 'a -> 'a t
87
88
89       lazy_from_val v returns an already-forced suspension of v This  is  for
90       special purposes only and should not be confused with lazy (v) .
91
92
93
94
95       val lazy_is_val : 'a t -> bool
96
97
98       lazy_is_val  x  returns  true  if x has already been forced and did not
99       raise an exception.
100
101
102
103
104
105
106OCamldoc                          2007-05-24                           Lazy(3)
Impressum