[Haskell-cafe] Parsec float

wren ng thornton wren at freegeek.org
Sun May 31 18:22:44 EDT 2009

Jason Dusek wrote:
> 2009/05/30 Bartosz Wójcik <bartek at sudety.it>:
>> ...reading RWH I could not memorize what those liftM funtions
>> meant.
>   The basic one, `liftM`, means `fmap`, though specialized for
>   functors that are monads.
>     Prelude Control.Monad> :t liftM
>     liftM :: forall a b (m :: * -> *). (Monad m) => (a -> b) -> m a -> m b
>     Prelude Control.Monad> :t fmap
>     fmap :: forall a b (f :: * -> *). (Functor f) => (a -> b) -> f a -> f b

Category theoretically, all the following are (or should be!) equal: 
fmap, (<$>), liftA, liftM.

Type theoretically, they differ in whether they require Functor, 
Applicative, or Monad. Unfortunately there's a clash between the current 
types and their CT backing. That is, Monad doesn't require Applicative 
(or Functor), so people will often use liftM to avoid extra type 

Operationally, fmap and (<$>) are potentially more efficient. The liftA 
and liftM functions re-engineer fmap by using pure/(<*>) or return/ap, 
thanks to CT. The (<$>) function is just an alias for fmap. But the fmap 
function is part of a type class and so it may have a specific 
implementation which is more efficient than the generic one provided by CT.

Live well,

More information about the Haskell-Cafe mailing list