
On Thu, Jan 1, 2009 at 5:17 AM, Ryan Ingram
It might be possible to build a "lazy-ify" monad transformer which would make this work. In particular, I think Oleg's LogicT transformer[1] does something of the sort, only applying side effects where they are required in order to get "the next result" in a nondeterministic computation.
LogicT is continuation-based, so it's strict in the first argument to (>>=).
observeT $ undefined >>= \_ -> return ()
will throw an exception.
On the other hand, LogicT is non-strict in the second argument to
mplus if the transformed monad is non-strict in (>>=).
take 4 . runIdentity . observeAllT . msum $ map return [0..]
should return [0,1,2,3].
(My implementation does. I assume the LogicT on Hackage is the same.)
--
Dave Menendez