Skip to content

Hiding Imports

The final customization of imports is one that can be seen as the complement of an explicit import list. An import list states what we want to import from a module. In some situations, we may want to import everything from a module except for a few specific types or functions. For this, we have the hiding clause.

One of the most common use cases is to hide symbols from the Prelude. If we do not specify the Prelude as an explicit import, the whole Prelude is imported automatically. However, we can import the Prelude explicitly, and this gives us the ability to specify what we want to import from the Prelude. As an example, we may have a module that works with arrays, and it needs the map function from Data.Array. If we

import Data.Array (map)

we cannot call map unqualified because the map function from the Prelude is also in scope. By adding the import

import Prelude hiding (map)

we ensure that all the standard functions are imported from the Prelude, except map. Thus, the map function from the Prelude is no longer in scope, and calling map now unambiguously refers to the map function imported from Data.Array.

The hiding clause is not used often, but it is good to know that it exists when we do need it.