
On 11/29/10 8:58 AM, Maciej Piechotka wrote:
class Pointed f => Applicative f where (<*>) :: f (a -> b) -> f a -> f b (*>) :: f a -> f b -> f b (<*) :: f a -> f b -> f a
a *> b = flip const<$> a<*> b a<* b = const<$> a<*> b
I assume you're meaning default implementations, rather than that they should be removed from the class? (the reason to be in the class is performance issues.)
class Applicative m => Monad m where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b join :: m (m a) -> m a
f>>= x = join (fmap f x) m>> k = m>>= \_ -> k join x = x>>= id
This would eliminate the necessity of declaring a Monad instance for every Applicative, and eliminate the need for sets of duplicate functions such as [fmap,liftM,map,liftA], [(<*>),ap], and [concat,join].
Technically (>>) and (*>) are duplicates assumin (<*>) and ap are, I believe:
Yes. Assuming the free applicative instance from the monad ---with pure=return; (<*>)=ap--- then (>>) = (*>). Due to legacy reasons it might be nice to keep both names around since (>>) looks like (>>=), whereas (*>) looks like (<*>) and the related (<*) ---which is not (<<). Perhaps we should just move (>>) out of Monad via: (>>) :: (Monad m) => m a -> m b -> m b (>>) = (*>) Which fits with (=<<), (<<), (<=<), and (>=>) being outside of the class too. -- Live well, ~wren