Closed arsalan0c closed 2 years ago
Possible solutions (as suggested by Jasper):
data PageWindowOpen = ...
class Event a where eventName :: Proxy a -> String
instance Event PageWindowOpen where eventName _ = "pageWindowOpen"
subscribe :: Event a => ? -> (a -> IO b) -> IO ..
2. GADTs
```hs
data EventName a where
PageWindowOpenName :: EventName PageWindowOpen
...
data PageWindowOpen = ...
subscribe :: ? -> EventName a -> (a -> IO b) -> IO ...
Standealone example of a solution: https://gist.github.com/jaspervdj/d1a1ee08e7fab819e2631180185ad62d
Implemented in this commit with the following:
The set of all event results are represented as a tagged union (
EventReturn
). For a particular event received, deconstruction is required in the user's code, in order to obtain the result.For example:
An event handler is defined as:
type Handler = EventReturn -> IO ()
The deconstruction function can be used as part of the handler:doSomethingWithValue . f
Ideally,
f
would not be required of a user.