I've come across some modules that contain particularly strange imports.
First of all, I have seen a module A that imports an other module as himself. For example:
-- module A.hs
module A where
import B as A -- ???
f = id
What does this do? Why is the above permitted at all?
However what most troubles me is that the code is actually of this kind:
module A where
import B as A -- Okay, assume this works...
import C as A -- ??? A is already defined!
f = id
Why can more then one module be imported with the same name? What does this achieve?
I thought that these kind of imports weren't permitted and also A Gentle Introduction to Haskell states that:
it is illegal to import two different entities having the same name into the same scope.
However these imports work fine. Yet an other strange thing that bugs me is exporting the module itself:
module A (module A) where
To summarize, given the following MWE:
-- A.hs
module A (module A) where
import B as A
import C as A
f = id
-- B.hs
module B where
g = id
-- C.hs
module C where
h = id
- Are the imports following the standards or is this some bug of GHC? It doesn't look like a bug, but I can't find any reference that explains all these corner cases.
- What's the exact result achieved? I mean: which names are imported and/or exported from
A?