Skip to content

Generated selector methods don't take into account named parameters of the field #310

@ppolesiuk

Description

@ppolesiuk

For records with fields that have named (implicit, regular named) parameters the generated selector methods fails to type-check. For instance

data T = { x : {~n:Int} -> Unit }

fails with the following error.

fatal error: Cannot resolve an implicit parameter ~n
 -> test.fram
 1 |>data T = { x : {~n:Int} -> Unit }

Similarly, when we replace ~n with n. For optional parameters it works, but not as one would expect.

The problem is that the generated method x looks like the following (modulo some non-important type annotations).

method x (T { x }) = x

To solve this problem, the generated method should explicitly generalize named parameters from the filed, and use the to reisntantiate the field. For instance:

method x {~n=_freshIdent42 : Int} (T { x }) = x {~n=_freshIdent42}

The following observations might be useful.

  1. Identifiers used to store named parameters should not collide with other variables. For instance data T = { x : {x : Int} -> Unit } cannot generate method x {x : Int} (T { x }) = x { x }.
  2. Type annotations are important, and cannot be inferred in general. For instance data T = { x : {n : {X} -> X} -> Unit } cannot generate method x {n} (T { x }) = x { n }, because the type-checker cannot guess polymorphic types.
  3. For type parameters, the type-checker should be able to infer missing information, but it would be nice to preserve names of named typed parameters.

Metadata

Metadata

Assignees

Labels

0. parsingThings related to lexer and parser

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions