Functor instance of ReaderT

Benja Fallenstein benja.fallenstein at gmail.com
Tue Aug 5 10:51:28 EDT 2008


On Tue, Aug 5, 2008 at 2:19 PM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
>
> The Functor instance of ReaderT has the header:
>  Monad m => Functor (ReaderT r m)
>
> I thought (Functor m) must be the appropriate constraint.

Note that there *is* an advantage to having Monad as the context: not
every monad implements Functor, even though it could. So having
Functor as the context isn't *trivially* superior.

Taking this into consideration, and taking into consideration that
ReaderT is usually thought of as related to monads (e.g., it's in
Control.Monad.Reader), I'm not sure that the preferred way of
transforming a functor wouldn't be

(r ->) :.: f

where :.: is functor composition. But then, functor composition
apparently isn't actually in the library, which surprised me (it's in
the applicative functor paper, but not in Control.Applicative), so
maybe changing ReaderT to be usable with functors is more warranted.
Or perhaps adding functor composition is the way to go?

All the best,
- Benja


More information about the Libraries mailing list