Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
PermissiveImportsProposal
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Implementation== I don't have enough knowledge of GHC's internals to implement this, so it's a feature request. However, there are two quite different ways to implement this that occur to me, so I may as well list them. One is automatically hiding imports that have been explicitly imported. So the example given above would become: <haskell> import Data.Text.Lazy.IO (putStrLn) import Prelude hiding (putStrLn, isInfixOf) import qualified Data.List as L hiding (putStrLn, isInfixOf) import qualified Data.Text.Lazy as L (isInfixOf) import qualified Prelude (putStrLn) import qualified Data.List (isInfixOf) </haskell> We first do a pass through the import list to see what has been explicitly imported, then do another pass to add/append hiding clauses to anything bringing an unspecified number of identifiers into scope. Note it is not an error to hide an identifier that isn't being exported, so we aren't required to know which modules export what identifiers to do this. However, this would prevent us from calling Prelude.putStrLn explicitly, so we also need to add an explicit qualified import of any identifiers that have been hidden to not disallow those uses (unless the user had already manually hidden them). There's also the question of how to resolve <haskell> import Data.Either (Either(..)) import MyModule (Left) </haskell> That would suggest we should import all of Either's data constructors but Left, but there's no way to do something like "import Data.Either (Either(..)) hiding (Left)". I don't think there's any way to resolve that without knowing what Data.Either exports. I think the better implementation is automatically promote anything that has been imported explicitly to a qualified use, provided only one identifier with the name has been explicitly imported. So with the example again: <haskell> import Data.Text.Lazy.IO (putStrLn) import Prelude import qualified Data.List as L import qualified Data.Text.Lazy as L (isInfixOf) </haskell> any unshadowed use of putStrLn is automatically changed to Data.Text.Lazy.IO.putStrLn, and any unshadowed use of L.isInfixOf is changed to Data.Text.Lazy.isInfixOf. If multiple identifiers with the name putStrLn had been explicitly imported no promotion would occur. This should also cover the Data.Either example, would still let you use the non-explicitly imported identifiers by qualifying their use, and would probably be simpler to implement in GHCi (no need to retroactively hide identifiers after an explicit import). The only tricky case is: <haskell> import Data.Text.Lazy.IO (putStrLn) import Prelude as Data.Text.Lazy.IO </haskell> In that case putStrLn should refer to the text version, but changing it to Data.Text.Lazy.IO.putStrLn if anything makes it more ambiguous. If we wanted to resolve this I'm sure GHC can disambiguate even if the user can't at the source level. Granted, I don't think anyone would lose sleep if this still gave an ambiguous identifier warning. Really just depends where in GHCs pipeline the change is implemented I guess.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width