aboutsummaryrefslogtreecommitdiff
path: root/src/nbc/promise.sml
diff options
context:
space:
mode:
authorCalvin <calvin@EESI>2013-03-15 15:26:20 -0400
committerCalvin <calvin@EESI>2013-03-15 15:26:20 -0400
commitb632667ce57af89691407bb8668e1512775278ae (patch)
treeb5742cef185f1cc4a7ba6005b5b4116ce7558a01 /src/nbc/promise.sml
parent39e39f82cc38d71018882b0aaaf58255858a7c56 (diff)
nbc added
Diffstat (limited to 'src/nbc/promise.sml')
-rw-r--r--src/nbc/promise.sml24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/nbc/promise.sml b/src/nbc/promise.sml
new file mode 100644
index 0000000..6bb2655
--- /dev/null
+++ b/src/nbc/promise.sml
@@ -0,0 +1,24 @@
+structure Promise
+:> sig
+ type 'fulfillment promise
+ val delay: (unit -> 'fulfillment) -> 'fulfillment promise
+ val force: 'fulfillment promise -> 'fulfillment
+end = struct
+ local
+ datatype 'expectation lazy =
+ Delayed of unit -> 'expectation
+ | Forced of 'expectation
+ in
+ type 'expectation promise = 'expectation lazy ref
+ fun delay fulfill = ref (Delayed fulfill)
+ fun force promise = case !promise of
+ Delayed fulfill =>
+ let
+ val expectation = fulfill ()
+ in
+ promise := Forced expectation
+ ; expectation
+ end
+ | Forced expectation => expectation
+ end
+end