ekmett / adjunctions

Simple adjunctions
http://hackage.haskell.org/package/adjunctions
Other
44 stars 27 forks source link

Define 'Representable (Join f)' once we have Bicomonad #47

Open Icelandjack opened 6 years ago

Icelandjack commented 6 years ago

For future reference, once we have Bicomonad

class Bifunctor bi => Bicomonad bi where
  fst :: bi a b -> a
  snd :: bi a b -> b

  bidup :: bi a b -> (bi a b `bi` bi a b)

I think we can define a Representable instance for (Join f)

instance (Biapplicative f, Bicomonad f) => Representable (Join f) where
  type Rep (Join f) = Bool

  index :: Join f a -> (Bool -> a)
  index (Join faa) = \case
    False -> fst faa
    True  -> snd faa

  tabulate :: (Bool -> a) -> Join f a
  tabulate gen = Join (False `bipure` True)

unless it's unlawful. It captures the pattern of Representable Pair for newtype Pair a = Pair (a, a).

Icelandjack commented 6 years ago

Or some hypothetical Bipointed, Bicopointed.