| 1 | (************************************************************************) |
| 2 | (* * The Rocq Prover / The Rocq Development Team *) |
| 3 | (* v * Copyright INRIA, CNRS and contributors *) |
| 4 | (* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 | (* \VV/ **************************************************************) |
| 6 | (* // * This file is distributed under the terms of the *) |
| 7 | (* * GNU Lesser General Public License Version 2.1 *) |
| 8 | (* * (see LICENSE file for the text of the license) *) |
| 9 | (************************************************************************) |
| 10 | |
| 11 | (** {5 Purely functional streams} |
| 12 | |
| 13 | Contrarily to OCaml module [Stream], these are meant to be used purely |
| 14 | functionally. This implies in particular that accessing an element does not |
| 15 | discard it. *) |
| 16 | |
| 17 | type +'a t |
| 18 | (** Type of pure streams. *) |
| 19 | |
| 20 | type 'a node = |
| 21 | | Nil |
| 22 | | Cons of 'a * 'a t |
| 23 | (** View type to decompose and build streams. *) |
| 24 | |
| 25 | (** {6 Constructors} *) |
| 26 | |
| 27 | val empty : 'a t |
| 28 | (** The empty stream. *) |
| 29 | |
| 30 | val cons : 'a -> 'a t -> 'a t |
| 31 | (** Append an element in front of a stream. *) |
| 32 | |
| 33 | val thunk : (unit -> 'a node) -> 'a t |
| 34 | (** Internalize the laziness of a stream. *) |
| 35 | |
| 36 | (** {6 Destructors} *) |
| 37 | |
| 38 | val is_empty : 'a t -> bool |
| 39 | (** Whethere a stream is empty. *) |
| 40 | |
| 41 | val peek : 'a t -> 'a node |
| 42 | (** Return the head and the tail of a stream, if any. *) |
| 43 | |
| 44 | (** {6 Standard operations} |
| 45 | |
| 46 | All stream-returning functions are lazy. The other ones are eager. *) |
| 47 | |
| 48 | val app : 'a t -> 'a t -> 'a t |
| 49 | (** Append two streams. Not tail-rec. *) |
| 50 | |
| 51 | val map : ('a -> 'b) -> 'a t -> 'b t |
| 52 | (** Mapping of streams. Not tail-rec. *) |
| 53 | |
| 54 | val iter : ('a -> unit) -> 'a t -> unit |
| 55 | (** Iteration over streams. *) |
| 56 | |
| 57 | val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a |
| 58 | (** Fold over streams. *) |
| 59 | |
| 60 | val concat : 'a t t -> 'a t |
| 61 | (** Appends recursively a stream of streams. *) |
| 62 | |
| 63 | val map_filter : ('a -> 'b option) -> 'a t -> 'b t |
| 64 | (** Mixing [map] and [filter]. Not tail-rec. *) |
| 65 | |
| 66 | val concat_map : ('a -> 'b t) -> 'a t -> 'b t |
| 67 | (** [concat_map f l] is the same as [concat (map f l)]. *) |
| 68 | |
| 69 | (** {6 Conversions} *) |
| 70 | |
| 71 | val of_list : 'a list -> 'a t |
| 72 | (** Convert a list into a stream. *) |
| 73 | |
| 74 | val to_list : 'a t -> 'a list |
| 75 | (** Convert a stream into a list. *) |
| 76 | |
| 77 | (** {6 Other}*) |
| 78 | |
| 79 | val force : 'a t -> 'a t |
| 80 | (** Forces the whole stream. *) |