desugaring an example from RWH

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

desugaring an example from RWH

Michael Easter
Folks,

I have an example of the do-syntax that I would like to desugar.  It is an
example from Chapter 28 in RWH.

I think I understand the ideas behind the following STM example, but I would
like to present it to others in a desugared way:

tryBogusSale = do
    players@(alice:bob:_) <- atomically populateWorld
    atomically $ alwaysSucceeds =<< consistentBalance players
    bogusSale Wand 5 alice bob

I'm having problems especially with the 2nd line in the do block (i.e. the
predicate for alwaysSucceeds).  I would like to try and express this in
terms of only bind (->) and return.

thanks!
Michael

--
----------------------
Michael Easter
http://codetojoy.blogspot.com: Putting the thrill back in blog

http://youtube.com/ocitv -> Fun people doing serious software engineering
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090223/ed207ffd/attachment.htm
Reply | Threaded
Open this post in threaded view
|

desugaring an example from RWH

Andrew Wagner
Here's my attempt (without a typechecker):tryBogusSale = atomically
populateWorld >>= \players@(alice:bob:_) ->
                       atomically (consistentBalance players >>=
alwaysSucceeds) >>
                       bogusSale Wand 5 alice bob

On Mon, Feb 23, 2009 at 9:33 AM, Michael Easter <[hidden email]> wrote:

>
> Folks,
>
> I have an example of the do-syntax that I would like to desugar.  It is an
> example from Chapter 28 in RWH.
>
> I think I understand the ideas behind the following STM example, but I
> would like to present it to others in a desugared way:
>
> tryBogusSale = do
>     players@(alice:bob:_) <- atomically populateWorld
>     atomically $ alwaysSucceeds =<< consistentBalance players
>     bogusSale Wand 5 alice bob
>
> I'm having problems especially with the 2nd line in the do block (i.e. the
> predicate for alwaysSucceeds).  I would like to try and express this in
> terms of only bind (->) and return.
>
> thanks!
> Michael
>
> --
> ----------------------
> Michael Easter
> http://codetojoy.blogspot.com: Putting the thrill back in blog
>
> http://youtube.com/ocitv -> Fun people doing serious software engineering
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090223/9c156025/attachment.htm