I’m trying to integrate sockets into my ReasonReact app, but I’m getting tripped up with the GADT and locally abstract types.
I’m trying to implement a redux-like list of messages on the server, and reduce them to get the current state:
module Common = {
type t('a) =
| UpdateCard: t(Board.card)
| ToggleRevealed: t(string)
| UpdateBoard: t(Board.t);
let stringify = (type a, t: t(a)) =>
switch (t) {
| UpdateCard => "UpdateCard"
| ToggleRevealed => "ToggleRevealed"
| UpdateBoard => "UpdateBoard"
};
}
module ActionList = {
open Belt;
type action('a) = {
action: Common.t('a),
payload: 'a,
};
type t('a) =
| List(action('a));
let getNewState = (state, actionList) =>
List.reduce(actionList, state, (acc, next) =>
switch (next.action) {
| UpdateCard => acc
| ToggleRevealed => acc
| _ => acc
}
);
};
I get this error in my getNewState function, and I don’t know what it means:
76 ┆ List.reduce(actionList, state, (acc, next) =>
77 ┆ switch (next.action) {
78 ┆ | UpdateCard => acc
79 ┆ | ToggleRevealed => acc
80 ┆ | _ => acc
The GADT constructor UpdateCard of type ReactTemplate.Common.t
must be qualified in this pattern.
My best guess is that it has something to do with refining the types, but I’m not even sure what that means