Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion with name resolution #202

Open
Ingo60 opened this issue Nov 3, 2015 · 0 comments
Open

Confusion with name resolution #202

Ingo60 opened this issue Nov 3, 2015 · 0 comments

Comments

@Ingo60
Copy link
Member

Ingo60 commented Nov 3, 2015

Given this:

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 maxPrelude.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant