All Monads are Functors
Jon Fairbairn
jon.fairbairn at cl.cam.ac.uk
Sat Aug 26 11:56:45 EDT 2006
On 2006-08-25 at 19:09PDT Ashley Yakeley wrote:
> Jon Fairbairn wrote:
>
> > There has been discussion in the past about whether Monad
> > should be defined as
> >
> >> class Functor m => Monad m where ...
>
> It's more complicated now that we have Ross Patterson's "Applicative".
>
> http://haskell.org/ghc/dist/current/docs/libraries/base/Control-Applicative.html
FSVO "complicated"... it looks like a Good Thing to me,
although I don't like the names much. [It would be nice if
there were a bit more commentary in the Haddock -- referring
to a paper is fine, but in day to day programming a scan
through several modules to find what one wants is hampered
by having to step out to read the papers.]
> The correct decl I think is this:
>
> class Applicative m => Monad m where
> -- remove "return"
> ...
>
> and changing the names of the Applicative functions:
>
> class Functor f => Applicative f where
> return :: a -> f a
> ap :: f (a -> b) -> f a -> f b
Better, I think, and though I can see a case for using
“unit” instead of return (as it's more neutral; “return (+1)
<*> [1..10]” looks a bit odd) using “return” would be less
of a shock to the system.
> This would mean moving Applicative into the Prelude.
Good, though I'm still very much in favour of moving as much
out of the Prelude as possible.
> I think "joining up the classes" is a good idea,
Definitely -- as is slicing them into finer layers (of which
this is also an example).
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-prime
mailing list