The FunctorM library
Iavor Diatchki
iavor.diatchki at gmail.com
Mon Mar 21 13:36:14 EST 2005
Hello,
> > For a given type T which has a Monad instance, you can always declare
> >
> > instance Functor T where fmap = liftM
> >
> > so it is not a big burden to have to declare a Functor instance to
> > accompany a Monad instance.
>
> I don't really have a strong view about this, I'm happy to defer to those who know more about it. > But I have a slight preference for not having to define Functor instance if I don't need one - lots of > little monads in my code would be affected. Also, Monad dictionaries would get slightly larger.
These days I never define instances of the monad class, I use a
library to create my monads. I don't know what these "little monads"
you mention are, but it is very likely that you can make your programs
smaller and more readable by simply using one of the monad libraries.
The library already has instances for both "Monad" and "Functor" so
you don't need to define any extra instances at all (not even "Monad"
instances). Sadly because "Functor" is not a superclass of "Monad"
if you have code that is plymorphic in the monad, and you don't try
very hard to not use "fmap" (ah double negations!) you get extra
constraints, that make the type signatures look scary and encourage
people to not write them.
-Iavor
PS: I think John Peterson's post makes a lot of sense.
More information about the Libraries
mailing list