links icon indicating copy to clipboard operation
links copied to clipboard

"flat" and "nested" kinds for query results

Open jamescheney opened this issue 2 years ago • 0 comments

This is a proposal to address #761 (which calls for typechecking nested query results to ensure that they are sensible nested types) and (the typechecking part of) #1127 (which calls for providing record flattening for all kinds of queries).

The proposal is to add two kind restrictions:

  • Flat which consists of base types or records of flat types. Thus if record flattening is implemented according to #1127 the Flat restriction characterizes the allowed return types for the flat and mixed/delat policies.
  • Nested which consists of base types, records of nested types, or collections (lists) of nested types. This would characterize the allowed return types of nested queries.

We would also have subkinding relationships Base <: Flat <: Nested <: Mono. I believe checking the above restrictions would be straightforward: whenever we unify a flexible type variable with one of the above restrictions applied to it with something else, we check whether the newly unified structure makes use of any disallowed type constructors and constrain any type variables encountered along the way by min-ing with the subkind (similar to what already happens with Mono and Base).

I'd still rather have this happen as an instance of a general-purpose programmable mechanism like type classes, but that doesn't seem likely to happen in the near future.

jamescheney avatar May 12 '22 09:05 jamescheney