Proposal: Add Compositor class as superclass of Arrow
apfelmus
apfelmus at quantentunnel.de
Thu Oct 18 04:10:43 EDT 2007
Conal Elliott wrote:
> DeepArrow could benefit from suggestions (perhaps refactoring), and I would
> appreciate such input. In any case, I imagine there's some rich, useful
> structure between Category & Arrow, and now would be a great time to explore
> it before settling on a new class hierarchy.
DeepArrow looks pretty much like a category corresponding to Arrows
("Freyd category" but I don't really know what that is) to me (without a
functor arr that embeds the category of Haskell functions).
I mean, Arrows are just computations a ~> b that allow you to keep
around temporary variables with first and second . Unfortunately, the
Arrow class does not mention all the needed morphisms to do that since
the arr function automatically carries most of them over from the
category of Haskell functions. I have the feeling that DeepArrow wants
to list exactly those necessary morphisms. Perhaps there is something
more to DeepArrows, due to the normal function arrows in types, but
maybe not since perhaps the only thing they can act on are tuples.
In any case, I'd recommend rethinking DeepArrows, maybe there's some
well-known category corresponding to them. For starters, there are
cartesian categories, i.e. categories with products:
class Cartesian cat where
fst :: cat (a,b) a
snd :: cat (a,b) b
(&&&) :: cat c a -> cat c b -> cat c (a,b)
with the conditions
fst . (f &&& g) = f
snd . (f &&& g) = g
Besides fstA and sndA, this gives the morphisms
dupA = id &&& id -- the diagonal
swapA f = snd f &&& fst f
lAssocA f = (fst f &&& fst (snd f)) &&& snd (snd f)
rAssocA f = fst (fst f) &&& (fst (snd f) &&& snd f)
Interestingly, we already get
first :: Cartesian cat => cat a b -> cat (a,d) (b,d)
first f = (f . fst &&& id . snd)
and second and that would be everything we need for arrows (besides
arr ). But IIRC, (&&&) does impose an "order of side effects" on the
arguments, so Arrows are more general (less restrictive) than cartesian
categories. So, it's some (pre?)monoidal category with extra stuff
(Freyd?), I don't know :)
Also, I don't know what to do with the Haskell function arrows in the
objects (= arguments to ~>) of DeepArrow.
Regards,
apfelmus
More information about the Libraries
mailing list