Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Enforce the same generic type between two functions

$
0
0

I’m writing bindings for a function that takes a string.

@send
external scene: (t, string, 'a => unit) => unit = "scene";

@send
external go: (t, string, ~data: 'a=?) => unit = "go";

Usage is as follows:

k->scene("one", () => {});
k->go("one");

These strings represent a limited set of values. One could model them with a variant:

type scenes = | One | Two;

Can I keep the type generic in my bindings while enforcing a relationship between the two functions?

@send
external scene: (t, 'scene, 'a => unit) => unit = "scene";

@send
external go: (t, 'scene, ~data: 'a=?) => unit = "go";

In this case, 'scene can be a variant but should be the same for both functions. What can I do to achieve this? What would be idiomatic?


Viewing all articles
Browse latest Browse all 2592

Trending Articles