One more 'do' pattern

Jesse Tov tov at
Sat Mar 28 13:04:27 EDT 2009

Bulat Ziganshin wrote:
>> • The syntax gains very little over the nice consistent syntax we  
>> already have – all you do is move a symbol a little to the left.
> action x y >>= \v -> do
> action x y $ \v -> do

One way to settle this kind of dispute would be a real macro system. 
Bulat could define and use the desired syntax without modifying the 
language definition in a way that would disturb others.  Template 
Haskell is great for some things, but it's unsuitable and unsatisfying 
in a case like this.

This is out of scope for Haskell', of course, but it's something the 
community should consider adding at some point.

I've uploaded a package called preprocessor-tools[1] to Hackage that 
provides very quick-and-dirty syntax extension using a preprocessor.  I 
used it to define a do-notation for parameterized monads, back before 
GHC supported that.

At one point I used it to define syntax for a "continuation let", which 
binds the "result" of a CPS-style function [2]:

   clet P = E1 in E   ===   E1 (\P -> E)

I think this is what Bulat wants.  (Bulat, if you want to try this, let 
me know and I'll try to resurrect the code.)



[2] It seems to generalize nicely:

   clet P1 = E1
        Pn = En
     in E
   E1 (\P1 -> ... -> En (\Pn -> E) ... )
   flip runCont id $ do
     P1 <- Cont E1
     Pn <- Cont En
     return E

More information about the Haskell-prime mailing list