Cannot parse Diff List constructor
14 │
15 │ type rec selectionList<, > =
16 │ | []: selectionList<'a, 'a>
17 │ | ::(column<'a>, selectionList<'b, 'c>): selectionList<'b, 'a => 'c>
18 │
I'm not sure what to parse here when looking at ":".
This is used in https://github.com/sikanhe/reason-graphql for inferring GraphQL resolver argument types. It uses the trick where for each item you add to the diff list, the resolver gets an additional argument.
field("field",
~args=[arg("count", ~typ=int), arg("foo", ~typ=string)],
~resolver=(ctx, count: int, foo: string) => {
// we get safely typed `count` and `foo` inside resolver fn body
}
)
I am also currently working on a library that does a similar trick for SQL selects - when change the columns selected, the row mapper of the query results changes with it.
select([User.name, User.age], ~mapRow=(name: string, age: int) => { // type safe rows returned here }
GADT can be complicated topic - but in rare (but very practical) use cases they provide a much better api than alternatives
@sikanhe is this still relevant?
@chenglou yes I believe so
What's our philosophy on this feature ?
@sikanhe This hasn't received a lot of attention. It is a rather niche corner of the language.
I guess we need to find a way to parse Ocaml's | [] and | ::.
The rescript-lang/syntax repo is obsolete and will be archived soon. If this issue is still relevant, please reopen in the compiler repo (https://github.com/rescript-lang/rescript-compiler) or comment here to ask for it to be moved. Thank you for your contributions.
Hi, can this please be moved to the compiler repo, as it is an important ability for more type-safe libraries.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.