module Cf_flow:sig..end
Lazy stream procesors and their operators.
A Cf_flow value is like a Cf_seq value that can take intermediate input
to continue generating output. Many of the other modules in the cf
library use this module.
The semantics of this module are derived from the stream processors in the Fudgets system, as described by Magnus Carlsson and Thomas Hallgren in their joint Ph.D. thesis, chapter 16.
type('i, 'o)t =('i, 'o) cell Stdlib.Lazy.t
A stream processor
type ('i, 'o) cell =
| |
P of |
(* | Output a value | *) |
| |
Q of |
(* | Input a value | *) |
| |
Z |
(* | Finish processing stream | *) |
val nil : ('y, 'x) tA stream processor that reads no input and writes no output.
val nop : ('x, 'x) tA stream processor that outputs every input value without change.
val filter : ('x -> bool) -> ('x, 'x) tUse filter f to construct a stream processor that applies f to every
input value and outputs only those for which the function result is true.
val map : ('i -> 'o) -> ('i, 'o) tUse map f to construct a stream processor that applies f to every input
value and outputs the result.
val optmap : ('i -> 'o option) -> ('i, 'o) tUse optmap f to construct a stream processor that applies f to every
input value and outputs the result if there is one.
val listmap : ('i -> 'o list) -> ('i, 'o) tUse listmap f to construct a stream processor that applies f to every
input value and outputs every element of the resulting list.
val seqmap : ('i -> 'o Cf_seq.t) -> ('i, 'o) tUse listmap f to construct a stream processor that applies f to every
input value and outputs every element of the resulting sequence.
val broadcast : ('i, 'o) t list -> ('i, 'o) tUse broadcast ws to construct a stream processor that combines the input
and output of every stream processor in the list ws by first rendering
all the output from each stream in turn, then ingesting all the input to
each stream in turn, until all streams are completed.
val mapstate : ('s -> 'i -> 's * 'o) -> 's -> ('i, 'o) tUse mapstate f s with an initial state value s and a folding function
f to construct a stream processor that folds the state into every input
value to produce an output value and a new state.
val machine : ('s -> 'i -> ('s * 'o Cf_seq.t) option) -> 's -> ('i, 'o) tUse machine f s with an initial state value s and a folding function
f to construct a stream processor that folds the state into every input
value to produce either a sequence of values to output and a new state or
the end of stream processing.
module Op:sig..end
Open this module to bring the operator functions into the current scope.
val to_seq : (unit, 'o) t -> 'o Cf_seq.tUse to_seq w to convert a stream processor w into the equivalent
sequence. This can only work when the stream processor ingests input of
the unit type.
val of_seq : 'o Cf_seq.t -> ('i, 'o) tUse of_seq z to convert a sequence into the equivalent stream processor
(which never ingests any input).
val upcase : (char, char) tA stream processor that converts uppercase US-ASCII characters into lowercase characters. All other characters are unchanged.
val dncase : (char, char) tA stream processor that converts lowercase US-ASCII characters into uppercase characters. All other characters are unchanged.
val commute : ('i, 'o) t -> 'i Cf_seq.t -> 'o Cf_seq.tUse commute w z to produce an output sequence from a flow w that
ingests its input from the sequence z.
val commute_string : (char, char) t -> string -> stringUse commute_string w s to commute the sequence of characters in the string
s with the flow w and compose a new string from the resulting sequence.
val drain : ('i, 'o) t -> 'o Cf_seq.tUse drain w to produce an output sequence comprised of all the values
output from the stream processor w until the first input is required.
val flush : ('i, 'o) t -> ('i, 'o) tUse flush w to discard all the output from the flow w until the first
input is required.
val ingestor : ('a Cf_seq.t option, 'a) tA stream processor that copies to its output every element of its input
sequences. The stream processor finishes when it ingests None.
This stream processor is helpful for placing at the end of a serial composition to produce a transcoder.
val transcode : ('i Cf_seq.t option, 'o) t -> 'i Cf_seq.t -> 'o Cf_seq.tUse transcode w z to produce the sequence of output values obtained by
executing the transcoder stream processor w to ingest every element of
the sequence z.
module Transcode:sig..end
A namespace for the more and last transcoder functions.
val readC : (('i, 'o) t, 'i) Cf_cmonad.tThe continuation monad that returns a value obtained from the flow produced by its evaluation.
val writeC : 'o -> (('i, 'o) t, unit) Cf_cmonad.tUse writeC x to compose a continuation monad that puts x into the
flow produced by evaluation and returns the unit value.
val evalC : (('i, 'o) t, unit) Cf_cmonad.t -> ('i, 'o) tUse evalC m to evaluate the continuation monad m, computing the
encapsulated flow.
val readSC : ('s, ('i, 'o) t, 'i) Cf_scmonad.tThe state-continuation monad that returns a value obtained from the flow produced by its evaluation.
val writeSC : 'o -> ('s, ('i, 'o) t, unit) Cf_scmonad.tUse writeSC x to compose a state-continuation monad that puts x into
the flow produced by evaluation and returns the unit value.
val evalSC : ('s, ('i, 'o) t, unit) Cf_scmonad.t -> 's -> ('i, 'o) tUse evalSC m s to evaluate the state-continuation monad m with the
initial state s, computing the encapsulated flow.