1997-10-14 06:29:58 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml *)
|
|
|
|
(* *)
|
|
|
|
(* Damien Doligez, projet Para, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1997-10-22 06:26:05 -07:00
|
|
|
(* Copyright 1997 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. Distributed only by permission. *)
|
1997-10-14 06:29:58 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* Module [Lazy]: deferred computations. *)
|
|
|
|
|
1997-10-22 06:26:05 -07:00
|
|
|
type 'a status =
|
|
|
|
| Delayed of (unit -> 'a)
|
|
|
|
| Value of 'a
|
|
|
|
| Exception of exn
|
|
|
|
;;
|
1997-10-14 06:29:58 -07:00
|
|
|
|
1997-10-22 06:26:05 -07:00
|
|
|
type 'a t = 'a status ref;;
|
|
|
|
(* A value of type ['a Lazy.t] is a deferred computation (called a
|
|
|
|
suspension) that computes a result of type ['a]. The expression
|
|
|
|
[lazy (expr)] returns a suspension that computes [expr].
|
1997-10-14 06:29:58 -07:00
|
|
|
*)
|
|
|
|
|
1997-10-22 06:26:05 -07:00
|
|
|
val force: 'a t -> 'a;;
|
|
|
|
(* [Lazy.force x] computes the suspension [x] and returns its result.
|
|
|
|
If the suspension was already computed, [Lazy.force x] returns the
|
|
|
|
same value again. If it raised an exception, the same exception is
|
|
|
|
raised again.
|
1997-10-14 06:29:58 -07:00
|
|
|
*)
|