HeinrichApfelmus / reactive-banana

Library for functional reactive programming in Haskell.
https://wiki.haskell.org/Reactive-banana
522 stars 71 forks source link

Add role annotations to `Behavior` and `Event` #219

Open ocharles opened 3 years ago

ocharles commented 3 years ago

Currently these are inferred as nominal, but I think the parameter should be representational. This would let us say

newtype CheckboxEvent = CheckboxEvent { toEvent :: Event Bool }
  deriving (Monoid, Semigroup) via Event Any

which seems a perfectly reasonable thought.

HeinrichApfelmus commented 3 years ago

Huh. Based on a cursory understanding of type roles, I would also say that its role should be representational. However, I'm hesitant to change the role manually if the compile inferred nominal for a good reason — why did that happen? 🤔

ocharles commented 3 years ago

I think it happened because way down in what a Behavior actually is is something with a GADT or something that forces us to be nominal. This means we'll probably need to employ a trick to get this to be representational (usually I do this with a Coyoneda-like existential mapping function). I'll give this a shot and open up a PR!