Question

In packages-haskell2010/System/IO.hs we have the following line :

import "base" System.IO hiding (openFile, hWaitForInput)

This form of import (where it is followed by a String and then by a module name) is not documented at Import. Am I correct in assuming that the String (in this case "base") simply refers to a directory?

Was it helpful?

Solution

The string refers to a package, since this is a package-qualified import. That extension is enabled by

{-# LANGUAGE PackageImports #-}

One can use this to include the given module from the named package. In your case, it would import System.IO from the package "base":

With the -XPackageImports flag, GHC allows import declarations to be qualified by the package name that the module is intended to be imported from. For example:

import "network" Network.Socket

would import the module Network.Socket from the package network (any version). This may be used to disambiguate an import when the same module is available from multiple packages, or is present in both the current package being built and an external package.

In case you're wondering what packages are on your system, use ghc-pkg list. Note that you might need a ghc-pkg recache if you aborted the installation of a package in cabal, and recache might need administrator's rights (depending on your platform).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top