package monadlib
Module Monad.MakeStream
Create a stream monad from an arbitrary inner monad, which computes the values discovered in each generation. This is pretty abstract, since we're not requiring that the inner monad is a collection. There is a constraint here, since we're strictly supposed to disallow a monad collection where order of elements matters. I think we can characterise this abstractly by saying that the plus operation on the inner monad must be commutative, but don't take my word for it!
Parameters
module M : sig ... endSignature
include Stream
with type 'a t = 'a M.m LazyList.node_t
and type 'a m = 'a M.m LazyList.t
type 'a t = 'a M.m LazyList.node_tinclude 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.tinclude MonadPlus with type 'a m := 'a m
include BasePlus with type 'a m := 'a m
include BatInterfaces.Monad with type 'a m := 'a m
val zero : unit -> 'a mval null : 'a m -> boolnull 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. I have provided this so that streams can be implemented more efficiently.
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
include Applicative.Base with type 'a m := 'a m
val of_list : 'a list -> 'a mGeneralises matrix transposition. This will loop infinitely if BasePlus.null cannot answer true for zeroes.
val of_llist : 'a LazyList.t -> 'a mval lsum : 'a LazyList.t m -> 'a mval lmsum : 'a m LazyList.t -> 'a mval ltranspose : 'a LazyList.t m -> 'a m LazyList.tGeneralises 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!