[Haskell-cafe] Re: [Haskell] Simulating client server communication with recursive monads

Ryan Ingram ryani.spam at gmail.com
Wed Jan 16 21:25:01 EST 2008


(redirected to haskell-cafe)

mfix is "value" recursion, not "effect" recursion.  It allows you to
"tie-the-knot" with data being constructed recursively even in a
monadic context.

When you are using the Writer monad like this, the bind operation
between statements in a "do" construct is just ++.

"simulation" in your message is

> simulation:: Writer [String] ()
> simulation = mdo
>         a <- server cr
>         cr <- client $ take 10 a
>         return ()

This is really just the following:

> simulation :: Writer [String] ()
> simulation = Writer result where
>     ( a, a_out ) = runWriter (server cr)
>     ( cr, cr_out ) = runWriter (client $ take 10 a)
>     result = ( (), a_out ++ cr_out )

With "mdo" you are allowed to have the values refer to each other; the
right hand side of "( a, a_out ) = ..." can refer to "cr" and vice
versa.  But there's no way to follow the thread of computation between
the server and the client with this style.

   -- ryan


More information about the Haskell-Cafe mailing list