fram-lang / fram-lang/dbl

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

Open
#310 0 comments 0 reactions 1 assignee Claimed by @Foxinio View on GitHub
0. parsing
Dominant language
OCaml
Stars
45
Forks
28
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.