You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
module my.fine.Decimal where
data Decimal = .... where
max :: Decimal -> Decimal -> Decimal
main = print (Decimal.max 5 3)
Here, the expectation is that this gives type errors, for example because 5 is not Decimal and Decimal is not an instance of Show. (This is, incidentally, exactly what happens when max is replaced with some different identifier like add.)
Istead, the code compiles without complaints and the output is 5.
The reson is that the (implicit) Prelude import created a link max → Prelude.max in the module namespace Decimal, hence the main function is equivalent to:
main = print (max 5 3)
While this is correct, it is quite confusing if the following applies on name resolution of M.x:
the module name M is the same as some type name that is in scope
the type M also has a binding for x
the module M has no original binding for x because x was imported.
There should at least be a warning, saying something like:
M.x is resolved as I.x
Use I.x or X.M.x for unambiguous name resolution.
where X is the module namespace where he type M was defined.
The text was updated successfully, but these errors were encountered:
Given this:
Here, the expectation is that this gives type errors, for example because 5 is not
Decimal
andDecimal
is not an instance ofShow
. (This is, incidentally, exactly what happens whenmax
is replaced with some different identifier likeadd
.)Istead, the code compiles without complaints and the output is
5
.The reson is that the (implicit)
Prelude
import created a linkmax
→Prelude.max
in the module namespaceDecimal
, hence themain
function is equivalent to:While this is correct, it is quite confusing if the following applies on name resolution of M.x:
There should at least be a warning, saying something like:
where X is the module namespace where he type M was defined.
The text was updated successfully, but these errors were encountered: