All Monads are Functors
Jón Fairbairn
jon.fairbairn at cl.cam.ac.uk
Fri Aug 18 09:54:35 EDT 2006
John Meacham <john at repetae.net> writes:
> On Tue, Aug 15, 2006 at 10:34:39PM +0100, Jon Fairbairn wrote:
> > It seems obvious to me that we always use an external
> > definition if one exists, so I suppose the problem is
> > knowing whether an external instance exists -- so this
> > proposal would rely on doing something about scoping for
> > instances, I suppose.
>
> The problem is you can't have working code change its behavior because
> of a module import (other than failing), say, by bringing an instance
> into scope that wasn't before. There is no way to have a monad instance
> 'automatically' declare a functor instance without changing what the mo
> instance looks like somehow which would be a backwards incompatable
> change.
In that case we really ought just to accept that we have to
declare the instances and swallow
class Functor m => Monad m where ...
without any cleverness.
* * *
another, more adventurous path would be to find a set of
restrictions that allow one to define
instance Monad m => Functor m where
fmap f = (>>= f . return)
without it being undecidable.
(I don't really like this, because it seems to be
backwards).
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html (updated 2006-07-14)
More information about the Haskell-prime
mailing list