Skip to content

Cannot parse Diff List constructor #6276

@sikanhe

Description

@sikanhe
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleOld issues that went stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions