Take the 2-minute tour ×

I have a Haskell module, and I’d like it to export all objects declared in its file except for one specific function local_func.

Is there a cleaner way to achieve this than by writing an export list explicitly listing all the other declarations (and carefully keeping this list up-to-date for all eternity)?

In other words, I’d like an analogue of import MyModule hiding (local_func), but specified in the exporting module rather that at import time.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

As far as I'm aware there is not currently a way to do this.

What I usually end up doing is having a central module that re-exports important things as a convenient way to import everything that is necessary while not hiding anything in the modules defining these things (which in some cases - that you probably won't foresee! - makes it easier for your users to modify things in your module.

To do this use the following syntax:

-- |Convenient import module
module Foo.Import (module All) where

-- Import what you want to export
import Foo.Stuff as All hiding (local_func)
-- You can import several modules into the same namespace for this trick!
-- For example if using your module also requires 'decode' from "Data.Aeson" you can do
import Data.Aeson as All (decode)

You have now conveniently exported these things.

share|improve this answer
Great advice: "which in some cases - that you probably won't foresee! - makes it easier for your users to modify things in your module": Yes! This is a common problem in my experience, and when a cabal-packaged module has been "locked down" with an overly restrictive export list, I know of no better solution than editing and reinstalling the package, which is annoying. –  ntc2 Dec 26 '13 at 7:08
add comment

Unfortunately not.

One could imagine a small syntactic addition which would allow the kind of thing you're asking for. Right now it's possible to write:

module M (module M) where

foo = quux

quux = 1+2

You can explicitly export the whole module. But suppose we were to add syntax such that it was possible to hide from that module. Then we would be able to write like this:

module M (module M hiding (quux)) where

foo = quux

quux = 1+2
share|improve this answer
add comment

Your Answer


