ekmett / profunctors

Haskell 98 Profunctors
http://hackage.haskell.org/package/profunctors
Other
70 stars 43 forks source link

Cokleisli does not satisfy Choice laws #99

Open viercc opened 2 years ago

viercc commented 2 years ago

The instance instance Comonad w => Choice (Cokleisli w) doesn't follow the Choice laws. It would have been if Cokleisli w was a conforming ArrowChoice, but it isn't (although it has the instance.)

https://github.com/ekmett/comonad/issues/36

Maybe it's already alarmed by the notice 'extract' approximates 'costrength' attached to the Choice instance, but it wasn't clear for me.

jasoncarr0 commented 2 years ago

To copy it out here, this is an alternate, explicit implementation:

left (Cokleisli f) = Cokleisli (\fac ->
  case extract fac of
    Right c -> Right c
    Left a -> Left . f $ fmap (either id (const a)) fac)

which has also been mentioned in a few other forums. I have previously verified that it meets the definition for co-cartesian co-strength manually, and it appears that these could be equivalent to the laws for Choice at first glance, and likewise this should meet the laws, although it would be a breaking change in the implementation.

It's not clear why the implementation would appear to not be the same, if the linked issue is to be believed.