Library
Module
Module type
Parameter
Class
Class type
Here, we create a stream monad from a definite collection monad Monad
.BaseCollectionM. The inner monad will be used to represent the generations in the stream. The order of elements in each generation should not matter, so you might want to use a set or a bag. If you want to live life on the edge, just remember that your code should not depend on the order of elements within generations (you can, of course, depend on the order that generations appear in the stream). You can enforce this constraint by performing, say, a sort on each generation.
Parameters
module M : sig ... end
Signature
include StreamC
with type 'a t = 'a M.m LazyList.node_t
and type 'a m = 'a M.m LazyList.t
include Stream
with type 'a t = 'a M.m LazyList.node_t
with type 'a m = 'a M.m LazyList.t
type 'a t = 'a M.m LazyList.node_t
include LazyPlus
with type 'a m = 'a t Lazy.t
with type 'a m = 'a M.m LazyList.t
include BaseLazyPlus
with type 'a m = 'a t Lazy.t
with type 'a m = 'a M.m LazyList.t
include BatInterfaces.Monad
with type 'a m = 'a t Lazy.t
with type 'a m = 'a M.m LazyList.t
type 'a m = 'a M.m LazyList.t
The type of a monad producing values of type 'a
.
include MonadPlus with type 'a m := 'a m
include Monad with type 'a m := 'a m
include BatInterfaces.Monad with type 'a m := 'a m
include Applicative.Applicative with type 'a m := 'a m
val of_list : 'a list -> 'a m
Generalises matrix transposition. This will loop infinitely if BasePlus.null
cannot answer true
for zero
es.
val of_llist : 'a LazyList.t -> 'a m
val lsum : 'a LazyList.t m -> 'a m
val lmsum : 'a m LazyList.t -> 'a m
val ltranspose : 'a LazyList.t m -> 'a m LazyList.t
Generalises matrix transposition. You don't necessarily have to worry about correctly implementing BaseLazyPlus.null
for this function, since the return value can happily be infinite.
Delay a stream by one time step. This is needed when you write recursive streams and you have to avoid deadlock. The nice thing about Ocaml here is that it will generally detect deadlock for you, announcing to you that you're writing viciously circular lists!
include BaseCollectionM with type 'a m := 'a m
difference p xs ys
removes all elements from xs
which are less than or equal to some element in ys
, according to the partial order p
.
include BaseLazyPlus with type 'a m := 'a m
val zero : unit -> 'a m
val null : 'a m -> bool
null x implies that x is zero. If you do not want to or cannot answer whether a given x is zero, then null x should be false.
difference p xs ys
removes all elements from xs
which are less than or equal to some element in ys
, according to the partial order p
.
unique eq xs
removes duplicates according to the function cmp
.
maxima p xs
leaves only the maximal elements according to the partial order p
.
nub p xs ys
is the same as maxima, but some values might be treated as greater than others depending on their position in the collection.
For instance, with lists, we treat elements that occur earlier in the list as always greater than elements that occur later, otherwise we use p
. This is really just an optimisation: in order to retrieve any value from maxima p
xs
, the maxima
function will have had to seen every value. Not so with nub
.