Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh |
2 | * Jagannathan, and Stephen Weeks. | |
3 | * | |
4 | * MLton is released under a BSD-style license. | |
5 | * See the file MLton-LICENSE for details. | |
6 | *) | |
7 | ||
8 | functor ExnHetContainer():> HET_CONTAINER = | |
9 | struct | |
10 | type t = exn | |
11 | ||
12 | fun 'a new() = | |
13 | let exception E of 'a | |
14 | in {make = E, | |
15 | pred = fn E _ => true | _ => false, | |
16 | peek = fn E x => SOME x | _ => NONE} | |
17 | end | |
18 | end | |
19 | ||
20 | functor RefHetContainer():> HET_CONTAINER = | |
21 | struct | |
22 | type t = unit ref * (unit -> unit) | |
23 | ||
24 | fun 'a new() = | |
25 | let | |
26 | val id = ref() | |
27 | val r: 'a option ref = ref NONE | |
28 | fun make v = (id, fn () => r := SOME v) | |
29 | fun peek ((id', f): t) = | |
30 | if id = id' then (f(); !r before r := NONE) | |
31 | else NONE | |
32 | fun pred(id', _) = id = id' | |
33 | in {make = make, pred = pred, peek = peek} | |
34 | end | |
35 | end |