infelicity in module imports

Malcolm Wallace
Wed, 4 Jul 2001 17:13:13 +0100

I was considering submitting this as a bug report in the Haskell'98
definition, but I don't know whether that is the appropriate
designation or not.  In any case, I think it is probably caused by
a hang-over from a previous version of Haskell that never caught up
with the newer features added in '98.

The problem is the combination of qualified imports, explicit hiding,
and renamed imports with overlapping.

Currently, you are permitted to write

    import A hiding (f)
    import B as A (f)

and this means that everything exported from module A is visible,
with the exception that function `f' is overridden by a different
definition from module B.  Here, a reference to `A.f' is resolved
unambiguously to `B.f'.

However, should you wish to do the same trick with all names forced
to be qualified, it is not legal.

    import qualified A hiding (f)
    import qualified B as A (f)

Although this looks like a very similar case, the standard says that
a `hiding' clause has no effect on a qualified import.  Hence, even
though the programmer has clearly tried to make it non-ambiguous,
a reference to `A.f' cannot be resolved between `A.f' and `B.f',
and such a program is rejected.

I submit that the way `hiding' clauses are ignored is a vestige from
the days when it was not possible to have overlapped module renamings.
Now that overlapped renamings are possible, the `hiding' clauses
should be permitted to take effect.