ekmett / ekmett/distributive

Sorta representable

Open
#48 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
42
Forks
26
PR merge metrics
No merged PRs in 30d

Description

As we've discussed, everything `Distributive` should be `Representable`, but maybe the librarian doesn't want to commit to a particular `Rep`. I just realize that there's actually a way to get a sort of middle ground, though it's a bit awkward.

```haskell
class Functor f => Distributive f where
data family RepD f -- Must be a newtype if Representable
tabulateD :: (RepD f -> a) -> f a
indexD :: f a -> RepD f -> a

class (Distributive f, Coercible (Rep f) (RepD f) => Representable f where
type Rep f

tabulate :: forall f a. Representable f => (Rep f -> a) -> f a
tabulate = coerce (tabulateD :: (RepD f -> a) -> f a)

index :: forall f a. Representable f => f a -> Rep f -> a
index = coerce (indexD :: f a -> RepD f -> a)
```

If the module defining `f` chooses not to export the `RepD f` newtype constructor, then the choice of representation is hidden.

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue contains a proposed Haskell design for Distributive and Representable, including RepD, tabulateD, indexD, tabulate, and index. No files, tests, or entry points are named, so first determine where these classes are defined and whether the proposal has been accepted. Done would require an agreed implementation scope and corresponding validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.