While trying to familiarize myself with Control.Arrow, I have noticed that the Kleisli newtype would seem to admit a Functor instance, something like:
instance Monad m => Functor (Kleisli m a) where
fmap f (Kleisli k) = Kleisli $ liftM f . k
Is there a reason why this instance isn't provided? Does it exist in some package as an orphan instance?
Every arrow can be made into a valid
Functor
by definingHowever it's not possible to declare a
Functor
to be a superclass ofArrow
because of their different kinds (Functor
needs* -> *
whileArrow
needs* -> * -> *
). So every arrow needs to define the instance separately.You can wrap any arrow with
ArrowMonad
, which then gives anApplicative
instance (and therefore also aFunctor
):instance Arrow a => Applicative (ArrowMonad a) where ...
.I don't see any particular reason why
Kleisli
lacks theFunctor
instance. The most probable seems to be that you don't need it. If you want to use functorial (or applicative or monadic) operations, you do it on the original monad. You only wrap the monad intoKleisli
when you need the arrow interface.UPDATE
in
Control.Arrow
is already defined:UPDATE 2
If you wish to insert
Free
Monad intoKleisli
- it is impossible,Free
has one extra parameterf
.So you need to use
Arrow Transformer
or create a newArrow
class, likePackage arrows consist some examples, but it not implement
Free