In Slicing It, Conor McBride develops indexed functors, and then describes their sums and products on a slide "Sum and Product" (slides are unlabelled, about 90% into the presentation). This slide begins
-- sum - choose between compatible structures
data (:+:) :: (i ->- o) -> (i ->- o) -> (i ->- o) where
L :: s x :-> (s :+: t) x
R :: t x :-> (s :+: t) x
instance (IFunctor s, IFunctor t) => IFunctor (s :+: t) where
imap f (L sx) = L (imap f sx)
imap f (R tx) = R (imap f tx)
In particular, this definition of :+:
requires that both indexed functors have the same source index i
. I wonder why this is the case. Can this be relaxed e.g. to allowing
-- sum - choose between compatible structures
data (:+:) :: (i ->- o) -> (j ->- o) -> (Either i j ->- o) where
L :: s x :-> (s :+: t) x
R :: t x :-> (s :+: t) x
where i
and j
are now different types?
@chi Thanks for your pointer. It turns out I was wrong -- my suggestion doesn't work, it is not possible to combine different inputs. However, it is possible to use
Either
for the output kinds, leading to the constructor @chi suggested:Both the
:+:
and the:*:
types on the slides take two types as arguments, i.e. essentially a pair of arguments. I believe my suggestion might work if they took an alternative (i.e. anEither
) of type arguments, as in