Speaking of Selective, we need to implement this function (excuse the name clash):

select :: Enumeration (Either a b) -> Enumeration (a -> b) -> Enumeration b

select x y = …

Let’s look at just computing the Cardinality of the result. The answer is:

#x.Left * #y + #x.Right

where #x.Left and #x.Right are the numbers of occurrences of Left and Right values in the first enumeration x, and #y is the cardinality of the second enumeration y. Why? Because whenever we get a value of type Left a, we need to apply one possible function to it. But we have no way of extracting #x.Left and #x.Right from x in the current representation of the Enumeration data type. And I’m not sure how this could be fixed.

Note: I’m being a bit imprecise here, because every Applicative instance can be given a lawful Selective instance simply by using the function selectA, which performs both effects regardless of whether the value is Left or Right. This would essentially duplicate values of type Right b #y times, essentially behaving in an Applicative way. But I think such an implementation would not be very useful; we really want to avoid duplicating values in the result in order to have a useful Selective instance.

]]>I would be interested in anything on this topic as well, but I am not aware of anything.

I’m still trying to understand why there’s no Selective instance — could you elaborate?

]]>Sadly, it looks like there is no efficient Selective instance either. To implement it, we’d need a way to compute the cardinality of Lefts and Rights in an Enumeration (Either a b).

]]>