Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

module

haskell

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.

like image 559
PLL Avatar asked Jun 21 '13 17:06

PLL


2 Answers

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.

like image 93
tazjin Avatar answered Sep 22 '22 09:09

tazjin


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 
like image 23
svenningsson Avatar answered Sep 20 '22 09:09

svenningsson