Extending the do-notation

Joe English [email protected]
Sun, 07 Jan 2001 11:08:32 -0800


Sebastien Carlier wrote:

> Sometimes I need to write code which looks like this:
> >    do x <- m1
> >       let y = unzip x
> >       ... -- never using x anymore 
> 
> I thinks the following extension to do-notation would be useful:
> >    pat <- exp1 # exp2 ; exp3
> would be rewritten as
> >    exp2 >>= ((\pat -> exp3) . exp1)
> 
> so that the above example could be rewritten more compactly:
> >    do y <- unzip # m1

This can be done in Haskell without any changes to the
'do' notation at all:  just define

|	f # m = m >>= (return . f)

and add an appropriate fixity declaration for '#'.


--Joe English

  [email protected]