Extending the do-notation
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
I think the biggest problem with this extension is the choice of a proper symbol. Does this extension already exist ? (I only checked the Haskell 98 report).
Sun, 7 Jan 2001 15:03:07 +0100, Sebastien Carlier <sebc@posse42.net> pisze:
Does this extension already exist ?
Yes. import Monad ... do y <- liftM unzip m1 -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK
On Sun, 7 Jan 2001, 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
I think the biggest problem with this extension is the choice of a proper symbol.
Why not just use a user defined operator. eg: infixr # (#) :: Monad m => (a -> b) -> m a -> m b f # p = p >>= (return . f) Alternatively, define it to be "fmap", and be a bit more general. -Rob
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 jenglish@flightlab.com
participants (4)
-
Joe English -
qrczak@knm.org.pl -
Robert Ennals -
Sebastien Carlier