Suggestion: Improved handling of overlapping imports
simonpj at microsoft.com
Wed Jan 7 12:51:53 EST 2009
| I've noticed an annoying (anti)pattern when using modules that collide
| with other modules (esp with the prelude). I find this is most common
| with modules conflicting with Data.List or System.IO. I'm fairly new
| to Haskell (did a little last January with XMonad and Just now getting
| back into it) so maybe there is a better way to handle this.
| import Data.Foldable (minimum, minimumBy, maximum, maximumBy)
| import Data.List hiding (minimum, minimumBy, maximum, maximumBy)
| import Prelude hiding (minimum, maximum)
| import System.IO.UTF8 (putStrLn, hPutStrLn)
| import System.IO hiding (putStrLn, hPutStrLn)
| import Prelude hiding (putStrLn)
Yes, I've seen this too.
| 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.
| 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
| 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.
| 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:
import System.IO.UTF8 shadowing Prelude
import System.IO shadowing Prelude
So for me (2) is a clear winner.
More information about the Haskell-prime