Is there a standard type (especially in the stdlib) for a Stream
type (by which I mean a potentially infinite, lazy sequence) which allows for effects when accessing the next element? Something like this pseudocode (for monad m
, element type a
)
m (a, m (a, m (a, m (a, ...
I tried modding Stream
from the stdlib but kept getting
Error: StreamM is not total, not strictly positive
I'm having difficulty remembering the exact implementation, but here's one without the Monad
data StreamM : (Type -> Type) -> Type -> Type where
(::) : a -> Inf (m (StreamM m a)) -> StreamM m a
Apparently it's because it can't be seen as total because for all we know m
is not strictly positive. It works if I make m
something specific like State Nat
.
My knowledge of codata is minimal, and I don't know what polarity (positive etc.) means.
Context
I am producing a stream of uniquely-named values, where each value depends on all the previous values (and some other stuff). The monad m
generates the names.