independant monads used together?
Sat, 10 Nov 2001 15:00:11 -0500
Pixel <email@example.com> asks:
> I'm trying to achieve something like (ocaml)
> [code deleted]
> which is a foldl on 2 iterators. I've managed to use monads for one iterator,
> but i completly miss the way to work with 2 monads. Is there really no other
> solution than creating a monad over the 2 iterators??
Why monadic iterators at all? One of the great things about lazy
lists is they encapsulate iteration nicely: Elements can be generated
as they're consumed. This is pretty much what a regular folding zip
would buy you:
zipFoldl f z a b = foldl (\sofar (a,b) -> f sofar a b) z (zip a b)
You're having trouble combining the results of two state monads
precisely because they're manipulating two *independent* pieces of
state, and you're trying to combine the *states* of the monads in some
fashion. What should the type of the result of the manipulation be?
Where are the initial states of each computation coming from?
Some computations really are much more easily done in the value domain
then under a wrapper like a monad which obscures their real structure.