ekmett / ekmett/adjunctions

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

Open
#47 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
45
Forks
26
PR merge metrics
No merged PRs in 30d

Description

For future reference, once we have `Bicomonad`

```haskell
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)`](https://hackage.haskell.org/package/bifunctors/docs/Data-Bifunctor-Join.html)

```haskell
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)`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.