# non-deterministic monad of streams easier in Ocaml?

Submitted by metaperl on Tue, 04/18/2006 - 7:13am.

::

I was reading Cale Gibbard's Monads as Containers and thought "now this is what I learned Haskell for" and then I began to wonder about Ocaml and monads, which led me to google which led me to this post on non-deterministic monad of streams which the author says "cannot be (naively) done in either Prolog or in Haskell's

|MonadPlus monad, both of which would go into an infinite loop on this example."

- metaperl's blog
- Login to post comments

In Haskell of course, we have laziness, so we can write runStream without the somewhat pointless length parameter. (Composition with take would handle that)

We can also make Stream a Functor:

Which lets us define numb as:

Oh, almost forgot, you're also allowed to use the mplus from the MonadPlus instance in the instance for Monad, so we can delete plus, and get rid of the distinction: