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