1(* ========================================================================= *)
2(* A POSSIBLY-INFINITE STREAM DATATYPE FOR ML                                *)
3(* Copyright (c) 2001-2004 Joe Hurd.                                         *)
4(* ========================================================================= *)
5
6signature mlibStream =
7sig
8
9datatype 'a stream = NIL | CONS of 'a * (unit -> 'a stream)
10
11(* If you're wondering how to create an infinite stream: *)
12(* val stream4 = let fun s4 () = CONS 4 s4 in s4 () end; *)
13
14(* mlibStream constructors *)
15val repeat : 'a -> 'a stream
16val count  : int -> int stream
17val powers : ('a -> 'a) -> 'a -> 'a stream
18
19(* mlibStream versions of standard list operations: these should all terminate *)
20val cons        : 'a -> (unit -> 'a stream) -> 'a stream
21val null        : 'a stream -> bool
22val hd          : 'a stream -> 'a                      (* raises Empty *)
23val tl          : 'a stream -> 'a stream               (* raises Empty *)
24val hd_tl       : 'a stream -> 'a * 'a stream          (* raises Empty *)
25val sing        : 'a -> 'a stream
26val append      : 'a stream -> (unit -> 'a stream) -> 'a stream
27val map         : ('a -> 'b) -> 'a stream -> 'b stream
28val maps        : ('a -> 's -> 'b * 's) -> 's -> 'a stream -> 'b stream
29val zipwith     : ('a -> 'b -> 'c) -> 'a stream -> 'b stream -> 'c stream
30val zip         : 'a stream -> 'b stream -> ('a * 'b) stream
31val take        : int -> 'a stream -> 'a stream        (* raises Subscript *)
32val drop        : int -> 'a stream -> 'a stream        (* raises Subscript *)
33
34(* mlibStream versions of standard list operations: these might not terminate *)
35val length       : 'a stream -> int
36val exists       : ('a -> bool) -> 'a stream -> bool
37val all          : ('a -> bool) -> 'a stream -> bool
38val filter       : ('a -> bool) -> 'a stream -> 'a stream
39val foldl        : ('a * 's -> 's) -> 's -> 'a stream -> 's
40val flatten      : 'a stream stream -> 'a stream
41val partial_map  : ('a -> 'b option) -> 'a stream -> 'b stream
42val partial_maps : ('a -> 's -> 'b option * 's) -> 's -> 'a stream -> 'b stream
43
44(* mlibStream operations *)
45val memoize       : 'a stream -> 'a stream
46val to_list       : 'a stream -> 'a list
47val from_list     : 'a list -> 'a stream
48val to_textfile   : {filename : string} -> string stream -> unit
49val from_textfile : {filename : string} -> string stream  (* line by line *)
50
51end
52