1(*
2 * @TAG(OTHER_PRINCETON_OSS)
3 *)
4(* ML-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi
5 *
6 * $Log$
7 * Revision 1.1  2006/06/23 03:21:27  michaeln
8 * Changed the names of the files in mlyacclib because I want these files
9 * to move into sigobj, and I don't want name-clashes, particularly with
10 * names like stream.sml.  (If you use a parser generated by mlyacc, then
11 * you need to have the files in mlyacclib available too.)
12 *
13 * Revision 1.1  2006/06/22 07:40:27  michaeln
14 * Add a MoscowML compilable implementation of MLyacc, using the MLton sources
15 * as the base.
16 *
17 * Revision 1.2  1997/08/26 19:18:55  jhr
18 *   Replaced used of "abstraction" with ":>".
19 *
20# Revision 1.1.1.1  1997/01/14  01:38:04  george
21#   Version 109.24
22#
23 * Revision 1.1.1.1  1996/01/31  16:01:43  george
24 * Version 109
25 *
26 *)
27
28(* Stream: a structure implementing a lazy stream.  The signature STREAM
29   is found in base.sig *)
30
31structure Stream :> STREAM =
32struct
33   datatype 'a str = EVAL of 'a * 'a str ref | UNEVAL of (unit->'a)
34
35   type 'a stream = 'a str ref
36
37   fun get(ref(EVAL t)) = t
38     | get(s as ref(UNEVAL f)) =
39            let val t = (f(), ref(UNEVAL f)) in s := EVAL t; t end
40
41   fun streamify f = ref(UNEVAL f)
42   fun cons(a,s) = ref(EVAL(a,s))
43
44end;
45