Note [The top-level Any principle]
Key principles:
* we never want to show the programmer a type with `Any` in it.
* avoid "spooky action at a distance" and silent defaulting
Most /top level/ bindings have a type signature, so none of this arises. But
where a top-level binding lacks a signature, we don't want to infer a type like
f :: alpha[0] -> Int
and then subsequently default alpha[0]:=Any. Exposing `Any` to the user is bad
bad bad. Better to report an error, which is what may well happen if we
quantify over alpha instead.
Moreover,
* If (elsewhere in this module) we add a call to `f`, say (f True), then
`f` will get the type `Bool -> Int`
* If we add /another/ call, say (f 'x'), we will then get a type error.
* If we have no calls, the final exported type of `f` may get set by
defaulting, and might not be principal (#26004).
For /nested/ bindings, a monomorphic type like `f :: alpha[0] -> Int` is fine,
because we can see all the call sites of `f`, and they will probably fix
`alpha`. In contrast, we can't see all of (or perhaps any of) the calls of
top-level (exported) functions, reducing the worries about "spooky action at a
distance". This also moves in the direction of `MonoLocalBinds`, which we like. References 0
This Note does not link to any other.
Referenced by 2
- decideAndPromoteTyVars GHC.Tc.Solver
- Do not quantify over constraints that determine a variable GHC.Tc.Solver