syntax icon indicating copy to clipboard operation
syntax copied to clipboard

Cannot parse Diff List constructor

Open sikanhe opened this issue 5 years ago • 5 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