1 (* Copyright (C
) 2017 Matthew Fluet
.
2 * Copyright (C
) 1999-2005 Henry Cejtin
, Matthew Fluet
, Suresh
3 * Jagannathan
, and Stephen Weeks
.
5 * MLton is released under a BSD
-style license
.
6 * See the file MLton
-LICENSE for details
.
9 structure Promise
: PROMISE
=
12 datatype 'a t
= T
of 'a state ref
14 Unevaluated
of unit
-> 'a
23 Unevaluated _
=> str
"Unevaluated"
24 | Evaluating
=> str
"Evaluating"
25 | Evaluated x
=> seq
[str
"Evaluated ", l x
]
28 fun delay th
= T (ref (Unevaluated th
))
32 Evaluating
=> Error
.bug
"Promise.reset"
33 | _
=> r
:= Unevaluated th
41 val _
= r
:= Evaluating
43 val _
= r
:= Evaluated x
46 end handle exn
=> (r
:= Unevaluated th
; raise exn
))
47 | Evaluating
=> raise Force
54 fun isUnevaluated (T r
) =