Fall back to types when looking up data constructors
Motivation
When the user mentions a type constructor or a type variable in a term-level context, we can tell them that this isn't the right thing to do rather than complain about scope.
For example, if they write:
ghci> id Int
The current error says:
<interactive>:1:4: error: Data constructor not in scope: Int
But of course GHC can do better and say this:
<interactive>:21:10: error:
• Type constructor 'Int' used where a value identifier was expected
That's more useful because there is, in fact, such a thing as Int
, but it can't be used in a term-level context at the moment.
When we implement visible forall
in types of terms, we'll need to lift this restriction anyway. And the way to lift it is straightforward: just like we fall back to the data namespace when looking for type constructors, we can fall back to the type namespace when looking for data constructors.
Thus we can kill two birds with one stone:
- improve error messages
- prepare the renamer for visible
forall
And the change should be comparatively small.
The goal of this ticket is to prepare the renamer for the glorious future with visible forall
in types of terms. But before we get to that feature (proposed in GHC Proposal #281), the only user-facing effect should be an improvement to error messages.
Completion
- The renamer accepts type constructors and type variables in term-level contexts
- The type checker rejects them with a more useful error message