Difference between revisions of "Functor hierarchy proposal"
Jump to navigation
Jump to search
(Added link to class system extension proposal) |
|||
Line 20: | Line 20: | ||
</haskell> |
</haskell> |
||
− | The downside of this is that every instance declaration of <tt>Monad</tt> would have to be accompanied by instance declarations for the superclasses. |
+ | The downside of this is that every instance declaration of <tt>Monad</tt> would have to be accompanied by instance declarations for the superclasses, but see [[Class system extension proposal]]. |
[[Category:Proposals]] |
[[Category:Proposals]] |
Revision as of 17:00, 9 January 2007
Currently the standard libraries include a Functor
class and a Monad
class, and Functor
is not a superclass of Monad
, even though logically every monad is a functor. New classes have been added to HEAD to create a richer hierarchy of Functor classes:
class Functor f where
fmap :: (a -> b) -> f a -> f b
class Functor f => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
(*>) :: Applicative f => f a -> f b -> f b
fa *> fb = (fmap (const id) fa) <*> fb
I propose that "pure
" be renamed "return
", "*>
" be renamed ">>
", and that Monad
be made a subclass of Applicative
:
class (Applicative f) => Monad f where
(>>=) :: f a -> (a -> f b) -> f b
The downside of this is that every instance declaration of Monad would have to be accompanied by instance declarations for the superclasses, but see Class system extension proposal.