# Functor-Applicative-Monad Proposal

### From HaskellWiki

(Difference between revisions)

(Functor => Applicative => Monad Proposal) |
(pure -> return) |
||

Line 6: | Line 6: | ||

class Functor f => Applicative f where |
class Functor f => Applicative f where |
||

− | pure :: a -> f a |
+ | return :: a -> f a |

(<*>) :: f (a -> b) -> f a -> f b |
(<*>) :: f (a -> b) -> f a -> f b |
||

(*>) :: f a -> f b -> f b |
(*>) :: f a -> f b -> f b |

## Revision as of 06:58, 7 December 2010

The standard class hierarchy is a consequence of Haskell's historical development, rather than logic. TheFunctor

Applicative

Monad

class Functor f where map :: (a -> b) -> f a -> f b class Functor f => Applicative f where return :: a -> f a (<*>) :: f (a -> b) -> f a -> f b (*>) :: f a -> f b -> f b (<*) :: f a -> f b -> f a class Applicative m => Monad m where (>>=) :: m a -> (a -> m b) -> m b f >>= x = join $ map f x join :: m (m a) -> m a join x = x >>= id

fmap

liftM

map

liftA

(<*>)

ap

concat

join

fail

mzero

Pointed

Backward compatibility could be eased with a legacy module, such as:

module Legacy where fmap :: Functor f => (a -> b) -> f a -> f b fmap = map liftA :: Applicative f => (a -> b) -> f a -> f b liftA = map liftM :: Monad m => (a -> b) -> m a -> m b liftM = map ap :: Monad m => m (a -> b) -> m a -> m b ap = (<*>) (>>) :: Monad m => m a -> m b -> m b (>>) = (*>) concat :: [[a]] -> [a] concat = join etc.

And for those who really want a list map,

listMap :: (a -> b) -> [a] -> [b] listMap = map