| 1 | (* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi *) |
| 2 | |
| 3 | (* Stream: a structure implementing a lazy stream. The signature STREAM |
| 4 | is found in base.sig *) |
| 5 | |
| 6 | structure Stream :> STREAM = |
| 7 | struct |
| 8 | datatype 'a str = EVAL of 'a * 'a str ref | UNEVAL of (unit->'a) |
| 9 | |
| 10 | type 'a stream = 'a str ref |
| 11 | |
| 12 | fun get(ref(EVAL t)) = t |
| 13 | | get(s as ref(UNEVAL f)) = |
| 14 | let val t = (f(), ref(UNEVAL f)) in s := EVAL t; t end |
| 15 | |
| 16 | fun streamify f = ref(UNEVAL f) |
| 17 | fun cons(a,s) = ref(EVAL(a,s)) |
| 18 | |
| 19 | end; |