From b632667ce57af89691407bb8668e1512775278ae Mon Sep 17 00:00:00 2001 From: Calvin Date: Fri, 15 Mar 2013 15:26:20 -0400 Subject: nbc added --- src/nbc/promise.sml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/nbc/promise.sml (limited to 'src/nbc/promise.sml') 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 -- cgit v1.2.3