[Haskell-cafe] Parsec float

Daniel Fischer daniel.is.fischer at web.de
Fri May 29 18:26:16 EDT 2009


Am Samstag 30 Mai 2009 02:04:29 schrieb Bartosz Wójcik:
> On Friday 29 May 2009 22:10:51 Bryan O'Sullivan wrote:
> > > myFloat = try (symbol "-" >> float >>= return . negate)
> > >     <|>  try float
> > >     <|>  (integer >>= return . fromIntegral)
> >
> > Any time you see ">>= return .", something is being missed. Use liftM or
> > <$> instead, i.e. "fromIntegral <$> integer" instead of "integer >>=
> > return . fromIntegral".
>
> I don't undersdand what is being missed.
>
> liftM f m1              = do { x1 <- m1; return (f x1) }
> so
> liftM fromIntegral integer
> will result the same. Is it then not just a convenience?

Even, desugaring the definition of liftM, we get

liftM f m1 = m1 >>= return . f

or, eta-reducing,

liftM  f= (>>= return . f)

It's a matter of style and readability.
>
> Bartek



More information about the Haskell-Cafe mailing list