[Haskell-cafe] Parsec float

David Menendez dave at zednenem.com
Fri May 29 18:28:18 EDT 2009


On Fri, May 29, 2009 at 8:04 PM, Bartosz Wójcik <bartek at sudety.it> wrote:
> 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?

For some monads, fmap (or <$>) has a more efficient definition than
liftM. Otherwise, it's just a style thing.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Haskell-Cafe mailing list