I understand that an Arrow is a Profunctor, where one can transform its input and its output, but can one map an arrow over a Functor?
I understand that as-asked the answer is "no", since the fmap
function type signature is (a -> b) -> f a -> f b
and does not admit Arrow a b
, but I hope what I'm asking is clear.
I am looking for a way to, for example, transform a Maybe
input with an Arrow, where Nothing
goes to Nothing
and Just x
goes to Just y
where y
is the result of applying the Arrow to x
.
This can be implemented for specific
Functor
s (such asMaybe
), thoughArrowChoice
will likely be necessary:See Arrow equivalent of mapM? for a similar function written in proc-notation.
Speaking of
mapM
, profunctors has an interesting class calledTraversing
:The flag-bearer instance of
Traversing
is the one for theStar
profunctor, which provides an alternative encoding of the familiartraverse
function. Note that, while leftaroundabout's answer demonstrates a non-Hask functor for categories which are not necessarily Hask-profunctors, withTraversing
we have a construction forProfunctor
s that do not necessarily have aCategory
instance.