1 (* ML
-Yacc Parser
Generator (c
) 1989 Andrew W
. Appel
, David R
. Tarditi
*)
3 (* Stream
: a
structure implementing a lazy stream
. The
signature STREAM
4 is found
in base
.sig *)
6 structure Stream
:> STREAM
=
8 datatype 'a str
= EVAL
of 'a
* 'a str ref | UNEVAL
of (unit
->'a
)
10 type 'a stream
= 'a str ref
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
16 fun streamify f
= ref(UNEVAL f
)
17 fun cons(a
,s
) = ref(EVAL(a
,s
))