GHC has a name-shadowing
option which allow to generate a warning or an error
whenever an inner-scope value has the same name as an outer-scope value,
This is really helpful so I turn it on. However there is lots of “false negative” where the shadowing is in fact armless.
For example, I often deal with products (as thing to buy), so I have a Product
data type but can’t have variable name product :: Product
because this shadows product :: [a] -> a
from the prelude.
To avoid that, I have a few options. The easier one is to use a different name for local binding like product_
or hide product
from the Prelude. The former is a bit ugly and the later is not practical. To hide something from the prelude you need import it (and so stop it from being imported implicitely) which is a bit faffy.
According to GHC doc, this is to prevent
inadvertent capture of what would be a recursive call in
f = ... let f = id in ... f ...
.
Well, this doesn’t happen when shadowing something from another module.
What I propose is either
1- a way to ignore shadowing of all imported names
2 - a way to ignore shadowing from implicit Prelude.
3- a way to ignore shadowing of non explicitely imported names
4- a way to ignore shadowing of names outside the current binding (its top level name + local bindings)
5 - (my favorite, but more likely the hardest to do) ignore shadowing if the code compile and the shadowing and the shadowed name don’t share the same type signature.
Does anyone think it is worth making a proposal ?
I would be prepare to try implementing (if I manage to compile GHC).