Note [Inheriting implicit parameters]
Consider this:
f x = (x::Int) + ?y
where f is *not* a top-level binding.
From the RHS of f we'll get the constraint (?y::Int).
There are two types we might infer for f:
f :: Int -> Int
(so we get ?y from the context of f's definition), or
f :: (?y::Int) => Int -> Int
At first you might think the first was better, because then
?y behaves like a free variable of the definition, rather than
having to be passed at each call site. But of course, the WHOLE
IDEA is that ?y should be passed at each call site (that's what
dynamic binding means) so we'd better infer the second.
BOTTOM LINE: when *inferring types* you must quantify over implicit
parameters, *even if* they don't mention the bound type variables.
Reason: because implicit parameters, uniquely, have local instance
declarations. See pickQuantifiablePreds. References 0
This Note does not link to any other.
Referenced by 5
- GHC.Tc.Solver call site ×2
- closeWrtFunDeps ignores implicit parameters GHC.Tc.Instance.FunDeps
- pickQuantifiablePreds GHC.Tc.Solver
- ApproximateWC GHC.Tc.Types.Constraint