(.)
and (<=<)
are quite similar:
(.) :: (b -> c) -> (a -> b) -> (a -> c)
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> (a -> m c)
and are available as a method in the Category
type class ((->)
and Kleisli
instances):
(<<<) :: (Category f) => f b c -> f a b -> f a c
($)
and (=<<)
are also quite similar:
($) :: (a -> b) -> a -> b
(=<<) :: Monad m => (a -> m b) -> m a -> m b
Is there a type class that abstracts over these application functions?
Both your examples are arrow mappings of functors (not
Functors
, but functors in the broader categorical sense), just likefmap
is the arrow mapping of aFunctor
.(=<<)
, for instance, is the arrow mapping of a functor fromKleisli m
to(->)
for some monadm
. An appropriate generalisation, then, is one that accounts for functors between different categories.Control.Categorical.Functor
provides that:Armed with that, you would be able to write an instance in the spirit of:
Or, for something you can actually run:
A similar instance might be written, for instance, for
(<*>)
, in terms of theStatic
category. As for($)
, it is the arrow mapping of the identity functor in(->)
, and so it is merelyfmap
forIdentity
sans theIdentity
wrapper (cf. Daniel Wagner's comment to the question).