hiding imports
Simon Peyton-Jones
simonpj@microsoft.com
Wed, 5 Dec 2001 02:42:18 -0800
I think it's an ill-thought-out exception. The point is this:
if a data constructor cannot appear on its own in a hiding
list, then you can't hide the constructor without hiding the
type. Currently you can say
import Maybe hiding( Just )
It would be simpler and more uniform to only allow data
constructors inside parens, just as for exports, but then
I'd have to say
import Maybe hiding( Maybe(Just) )
and now the type constructor Maybe is hidden too.
I say "ill thought out" because the exception doesn't actually
solve the problem, as you point out. You may accidentally hide
things you didn't mean to. So perhaps the cure is as bad
as the disease.
Changing this would be technically easy (delete a sentence)
but it might break some programs, so that suggests the status
quo.
Simon
| -----Original Message-----
| From: Iavor S. Diatchki [mailto:diatchki@cse.ogi.edu]=20
| Sent: 04 December 2001 19:14
| To: haskell@haskell.org
| Subject: hiding imports
|=20
|=20
| hello,
|=20
| i was wondering if there was a reasong why "hiding imports"=20
| have different semantics from "importing imports" and=20
| "exports". what i mean is, if one=20
| writes:
|=20
| module A(T) where
| data T =3D T
| only the type constructor T is exported. simillarly if i write:
|=20
| module A where
| data T =3D T
|=20
| module B where
| import A(T)
|=20
| only the type constructor is imported, but if i write
| (module A as above)
|=20
| module B where
| import A hiding (T)
|=20
| both the type constructor and the value constructor are hidden.
|=20
| this seems not only irregular, but may also be inconvinient=20
| in practise as sometimes it happens that a type constructor=20
| and a data constructor have the same name, but the data=20
| constructor does not "belong" to the type constructor. for example:
|=20
| module A where
| type T =3D TGen Int
| data TGen a =3D T a | S
|=20
| module B where
| import A hiding (T) -- intending to just hide the type T
| genF =3D T -- error T not in scope!
|=20
| so if i wanted to ignore the type T, but still have the data=20
| constructor i=20
| have to explicitly import it, i.e. write:
| module B where
| import A hiding (T)
| import A (TGen(T))
| which is kind of ugly. is this strange behaviour for=20
| historical reasons,=20
| or was there a practical reason why this decision was made?
|=20
| bye
| iavor
|=20
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
|=20