src/Tools/Metis/src/Stream.sig
author blanchet
Thu, 16 Sep 2010 07:30:15 +0200
changeset 39444 beabb8443ee4
parent 39443 e330437cd22a
child 39501 aaa7078fff55
permissions -rw-r--r--
MIT license -> BSD License
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     1
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     2
(* A POSSIBLY-INFINITE STREAM DATATYPE FOR ML                                *)
39444
beabb8443ee4 MIT license -> BSD License
blanchet
parents: 39443
diff changeset
     3
(* Copyright (c) 2001 Joe Hurd, distributed under the BSD License            *)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     4
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     5
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     6
signature Stream =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     7
sig
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     8
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     9
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    10
(* The stream type.                                                          *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    11
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    12
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    13
datatype 'a stream = Nil | Cons of 'a * (unit -> 'a stream)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    14
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    15
(* If you're wondering how to create an infinite stream: *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    16
(* val stream4 = let fun s4 () = Stream.Cons (4,s4) in s4 () end; *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    17
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    18
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    19
(* Stream constructors.                                                      *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    20
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    21
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    22
val repeat : 'a -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    23
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    24
val count : int -> int stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    25
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    26
val funpows : ('a -> 'a) -> 'a -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    27
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    28
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    29
(* Stream versions of standard list operations: these should all terminate.  *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    30
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    31
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    32
val cons : 'a -> (unit -> 'a stream) -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    33
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    34
val null : 'a stream -> bool
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    35
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    36
val hd : 'a stream -> 'a  (* raises Empty *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    37
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    38
val tl : 'a stream -> 'a stream  (* raises Empty *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    39
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    40
val hdTl : 'a stream -> 'a * 'a stream  (* raises Empty *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    41
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    42
val singleton : 'a -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    43
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    44
val append : 'a stream -> (unit -> 'a stream) -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    45
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    46
val map : ('a -> 'b) -> 'a stream -> 'b stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    47
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    48
val maps :
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    49
    ('a -> 's -> 'b * 's) -> ('s -> 'b stream) -> 's -> 'a stream -> 'b stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    50
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    51
val zipwith : ('a -> 'b -> 'c) -> 'a stream -> 'b stream -> 'c stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    52
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    53
val zip : 'a stream -> 'b stream -> ('a * 'b) stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    54
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    55
val take : int -> 'a stream -> 'a stream  (* raises Subscript *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    56
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    57
val drop : int -> 'a stream -> 'a stream  (* raises Subscript *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    58
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    59
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    60
(* Stream versions of standard list operations: these might not terminate.   *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    61
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    62
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    63
val length : 'a stream -> int
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    64
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    65
val exists : ('a -> bool) -> 'a stream -> bool
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    66
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    67
val all : ('a -> bool) -> 'a stream -> bool
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    68
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    69
val filter : ('a -> bool) -> 'a stream -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    70
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    71
val foldl : ('a * 's -> 's) -> 's -> 'a stream -> 's
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    72
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    73
val concat : 'a stream stream -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    74
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    75
val mapPartial : ('a -> 'b option) -> 'a stream -> 'b stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    76
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    77
val mapsPartial :
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    78
    ('a -> 's -> 'b option * 's) -> ('s -> 'b stream) -> 's ->
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    79
    'a stream -> 'b stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    80
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    81
val mapConcat : ('a -> 'b stream) -> 'a stream -> 'b stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    82
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    83
val mapsConcat :
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    84
    ('a -> 's -> 'b stream * 's) -> ('s -> 'b stream) -> 's ->
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    85
    'a stream -> 'b stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    86
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    87
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    88
(* Stream operations.                                                        *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    89
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    90
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    91
val memoize : 'a stream -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    92
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    93
val listConcat : 'a list stream -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    94
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    95
val concatList : 'a stream list -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    96
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    97
val toList : 'a stream -> 'a list
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    98
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    99
val fromList : 'a list -> 'a stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   100
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   101
val toString : char stream -> string
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   102
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   103
val fromString : string -> char stream
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   104
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   105
val toTextFile : {filename : string} -> string stream -> unit
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   106
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   107
val fromTextFile : {filename : string} -> string stream  (* line by line *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   108
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
   109
end