[Haskell-cafe] Intuition to understand poor man's concurrency

Chris Wong lambda.fairy at gmail.com
Sun Jul 27 11:30:19 UTC 2014

That looks like a continuation monad to me. `C m a` can also be expressed
as `Cont (Action m) a`, where Cont is from the transformers library.

In this case, I suggest looking at how the C type is used, rather than
focusing on the Monad instance. Since it's all bog standard continuation
passing so far, most likely the interesting part is elsewhere.

I'm on my phone so I can't supply links, but I hope this helps a bit.
On Jul 27, 2014 10:48 PM, "martin" <martin.drautzburg at web.de> wrote:

> Hello all,
> I am trying to understand the ideas of Koen Klaessen, published in
> Functional Pearls: "A poor man's concurrency" (1993).
> The code in the paper doesn't compile. E.g. uses "lambda dot" instead of
> "labmda arrow", i.e. the way the labmda
> calculus guys write things. Was that ever legal haskell or is this the
> result of some lhs2lex pretty printer?
> Anyways, I believe I was able to convert that into modern haskell syntax -
> at least it compiles. But I have trouble to
> understand the Monad instance presented there. Could anyobody walk me
> through the bind function?
> But even more important: how do you guys develop an intuition about what
> the bind operator does in a specific monad. I
> saw a Google tech talk where Douglas Crockford explains mondads in terms
> of Objects in javascript
> (https://www.youtube.com/watch?v=b0EF0VTs9Dc), which was certainly
> enlightening, but I couldn't apply it to this
> particular modad.
> I also tried using something like Data Flow Diagrams. This kinda works for
> simple Mondads such as the state mondad, but
> I couldn't apply it to the concurrency mondad. In general DFDs are not
> very good when it comes to higher order functions.
> In any case here is the code. I made it more verbose than necessary in
> order to understand it (bind was originally just
> one line), but to no avail.
> newtype C m a = C ((a -> Action m) -> Action m)
> instance Monad m => Monad (C m) where
>         (C m) >>= k = C cont
>                 where
>                     cont c = m (\a ->
>                                         let C h = k a
>                                         in h c)
>         return x = C $ \c -> c x
> data Action m =
>         Atom (m (Action m))
>         | Fork (Action m) (Action m)
>         | Stop
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140727/7861f3ac/attachment.html>

More information about the Haskell-Cafe mailing list