简体   繁体   中英

Haskell: hide specific function(s) in module exports?

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM