GHC 5.02, import Prelude hiding ...
Simon Peyton-Jones
simonpj@microsoft.com
Fri, 12 Oct 2001 08:59:42 -0700
Thomas Hallgren says:
| The following program was accepted by previous versions of=20
| GHC, but is not in GHC 5.02
|=20
| module HidingBug where
| import Prelude hiding (lookup)
|=20
| lookup env x =3D Prelude.lookup x env
|=20
| Instead, you get the error message
|=20
| HidingBug.hs:4: Variable not in scope: `Prelude.lookup'
|=20
| This behaviour does not seem to agree with the=20
| Haskell 98 Report, which in section 5.6.1 says
|=20
| The Prelude module is imported automatically into all modules as
if
| by the statement `import Prelude', if and only if it is not
imported
| with an explicit import declaration. This provision for explicit
| import allows values defined in the Prelude to be hidden from the
| unqualified name space. The Prelude module is always available as
a
| qualified import: an implicit `import qualified Prelude ' is part
of
| every module and names prefixed by `Prelude.' can always be used
to
| refer to entities in the Prelude.
An(other) excellent point. This didn't happen on purpose, but it
did happen for a reason.
In the current Report draft, the idea is that a hiding clause hides
both qualified and unqualified names
=09
import Foo hiding( f )
hides Foo.f as well as unqualified f.
I think we all agreed that is a good change. But we (ahem, I) forgot
to propagate that change to the sections about the Prelude. It's
really odd to say
import Prelude hiding( map )
does *not* hide Prelule.map, after all. In GHC we didn't implement
this inconsistency, hence the original message.
I therefore PROPOSE to replace the current text with:=20
The Prelude module is imported automatically into all modules as if
by the statement `import Prelude', if and only if it is not imported
with an explicit import declaration. This provision for explicit
import allows values defined in the Prelude to be selectively
imported,
just like any other module.
The fact that this makes the Report behave like GHC is purely
coincidental :-)
Seriously, comments anyone?
Simon