rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Cannot parse Diff List constructor

Open sikanhe opened this issue 5 years ago • 8 comments

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 avatar Jul 26 '20 20:07 sikanhe

@sikanhe is this still relevant?

chenglou avatar Aug 14 '20 07:08 chenglou

@chenglou yes I believe so

sikanhe avatar Aug 14 '20 20:08 sikanhe

What's our philosophy on this feature ?

sikanhe avatar Feb 03 '21 18:02 sikanhe

@sikanhe This hasn't received a lot of attention. It is a rather niche corner of the language.

IwanKaramazow avatar Feb 04 '21 19:02 IwanKaramazow

I guess we need to find a way to parse Ocaml's | [] and | ::.

IwanKaramazow avatar Feb 04 '21 19:02 IwanKaramazow

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.

stale[bot] avatar May 28 '23 23:05 stale[bot]

Hi, can this please be moved to the compiler repo, as it is an important ability for more type-safe libraries.

yawaramin avatar May 29 '23 01:05 yawaramin

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.

github-actions[bot] avatar Oct 15 '24 02:10 github-actions[bot]