Suggestion: Improved handling of overlapping imports
redbeard0531 at gmail.com
Fri Jan 9 12:17:46 EST 2009
> | 1) Transitive Hiding
> | If you hide something when importing a module it automatically hides
> | identical imports.
> I don't like this because a 'hiding' clause on one import affects other imports. Yuk.
Perhaps limit it to hiding implicit Prelude re-exports then. In each
of those examples the Prelude is only listed to hide things. If the
only import is:
import System.IO hiding (putStrLn, hPutStrLn)
There is no indication that System.IO.putStrLn is still in scope.
Also the following three examples are valid haskell98 but are likely a
import System.IO hiding (print, putStrLn)
import Prelude hiding (putStrLn)
import System.IO hiding (print)
--assume no import Prelude line
import System.IO hiding (print)
import Prelude (print)
None of these trigger a warning from GHC 6.8.3 with -Wall even though
they will not do what the programmer likely intended. Note that the
second will implicitly become the the third (if print is the only
thing used from Prelude), and that the third has no reasonable
meaning. (I think. Does it?)
> | 2) Explicit Import Lists Take Precedence
> | Any ambiguity should be resolved in favor of the module that has the
> | name explicitly in its import list. ...This can be considered an extension of
> | the current ImportShadowing
> | (http://hackage.haskell.org/trac/haskell-prime/wiki/ImportShadowing)
> | proposal if the current module is thought of as imported with
> | everything explicit.
> I like this. It's in the same spirit as the ImportShadowing proposal, so if that proposal is accepted, then this one makes sense too. (If not, then think again.) Why don't you modify the ticket to add your proposal to it.
I'll do that later today. I thought the ticket system was abandoned though?
> | 3) Import A Shadowing B
> | This actually adds a new import style which I think is the best solution:
> | import System.IO.UTF8 shadowing System.IO
> | import Data.Foldable shadowing Data.List
> I'm not keen on this. Not only is it new syntax, but it leads to the same repeats as you objected to earlier:
Do you object to the idea in general or just this specific syntax?
> import System.IO.UTF8 shadowing Prelude
> import System.IO shadowing Prelude
> import Prelude
Well System.IO wouldn't have to shadow Prelude because their name
collisions are re-exports and therefore, not ambiguous. Only if
shadowing wasn't transitive would need to do something like:
import System.IO.UTF8 shadowing (Prelude, System.IO)
I was trying to come up with a better way to use a module designed to
"overlay" on top others. This was the best syntax I could think of
that makes overlay modules easy to use. At first I was considering a
priority system where you could list the order to search for names,
but shadowing seemed easier. The two common uses for these modules
that I've seen are improvement and generalization. I see both as
important in allowing the language to flexibly update. Consider
something like the following to try a updated partial Prelude which
still uses the old Prelude for things that haven't changed:
import NewPrelude shadowing Prelude
Is there a way to do this without introducing a new syntax (other than
explicitly listing every name or importing Prelude qualified, neither
of which are practical when testing an overlay module)?
PS- I couldn't find a (non-strawman) proposal on the wiki about
improving Unicode IO in Haskell'. Has that been discussed to death on
the mailing list or should I start a new thread for it?
More information about the Haskell-prime