TTG: Does HsUnboundVar belong in the Haskell Language AST?
The parser currently parses holes ("_") to the HsUnboundVar constructor. This constructor is then also used by the renamer for true unbound variable names. Later, HsUnboundVars can become type wildcards, named wildcards, and typed holes if the relevant extensions are enabled.
While doing TTG work during ZuriHac with @alt-romes some questions came up:
- Does it make sense to view expression holes and type wildcards as unbound variables?
- Does the concept of an unbound variable belong in the Haskell Language AST?
I've experimented with two alternatives. Both currently eliminate HsUnboundVar but keep HsUnboundVarRn and HsUnboundVarTc as XExpr extensions for the renaming and type checking phases so that they keep working the same as they were.
- Introduce HsHole as a constructor ( !12973) and parse underscores to HsHole instead of HsUnboundVar in type or expression contexts.
- Parse type/expression underscores to HsVar (see this branch).
Maybe solution 1 could be extended to include named wildcards and holes by directly parsing "_someName" to HsHole. This would eliminate the startsWithUnderscore
checks which currently exist in the Rn/Tc phases. (But also complicate other things? I might give it a try to see what happens.)
Looking forward to reading your thoughts!
Part of the plan! #21592