Shadowing and metadata #556
Labels
blocked/need-info ❌
Blocked, need more information
easy
Should be straightforward to fix
primer
Specific to the primer package
type-checker
Type-checker issue
UX
UX issue
Milestone
[This is currently a question to build consensus. There is nothing technically wrong, but we could probably do a better job at assigning metadata. Later this issue may evolve into (or be replaced by) a feature request.]
Currently we assign a type to every node of a program, saying "this node has type ...". It is not clear quite what the notion of shadowing means here, and if we want to avoid shadowing.
The high-level trade off is that we need to choose between reflecting types as displayed/given in the program and alpha-converting to avoid "shadowing".
Some examples: what type should we claim the hole in the following terms needs to be filled with?
letrec y : ∀a.Bool = (let a : ... = ... in ?)
f : ∀a.Bool -> Int
(either as a top-level function, or a let-binding, or just thatf
is some term whose type happens to be as stated),let a = 0 in f ?
(Λa. ?) : ∀b.∀a. Bool
In each of these cases, we have a hole under a binder
a
, and the naïve thing to report for the type of the hole is∀a.Bool
. However, this may be confusing as (especially in the case where we have a complex type mentioning a (and other type vars) in the place of Bool) this forall binder shadows some other binder fora
.The other option is to ensure we alpha-convert the reported type to avoid this. For instance, we could say the hole has type
∀c.Bool
. However, I worry that this may be confusing because the type "should obviously be∀a.Bool
, as written in the text of the program".The question more-or-less boils down to: "which is more confusing: shadowing or alpha-conversion?" (Note that because this metadata is entirely generated by primer, we can easily alpha-convert if we want to, whereas the same question about the program text is more difficult -- we wouldn't want to automatically rename the user's program)
(NB: whilst some of these examples have the
∀a
shadowing some term-variable binderlet a
, the question of whether type and term variables are in the same namespace and shadow each other is orthogonal to this question. See #359)[Edit to add examples from #548
]
The text was updated successfully, but these errors were encountered: