
Hello, I did some Googling, and read a bit through the Haskell 2010 report, Chapter 5 "Modules," and searched through the Haskell-prime Trac tickets and can't really find anything on this. I don't know if it has ever been suggested before, or the reasoning for how export lists work the way they do. So as we all know, when there is no exports list in a module declaration, everything in the top level is exported by default. If you provide an exports list, everything is hidden except what you declare in the exports list. I think a good way to hide things without an exports list might be to simply prefix the type signature with a tilde character. For example: module M where ~type A = () ~newtype B = B () ~data C = MkB1 () | MkB2 () ~abc :: () abc = () increment :: Int -> Int increment = (+1) So in this example, the module M would only export the "increment" function, everything else would be hidden. Right now, this would produce a compile-time error like: Invalid type signature: ~abc :: () I propose making this kind of expression legal and effecting whether or not the symbol is exported. The only disadvantage I can think of is that tilde is generally reserved for making things more lazy, and using tilde in a way that has nothing to do with lazyness, it could make the language a bit more confusing. Otherwise I think it is very practical.

On 2014-01-09 at 08:46:28 +0100, Ramin Honary wrote: [...]
So as we all know, when there is no exports list in a module declaration, everything in the top level is exported by default.
If you provide an exports list, everything is hidden except what you declare in the exports list.
Btw, that's almost symmetric with an import statement lacking an 'impspec' and one providing a non-"hiding" 'impspec'; Otoh I've been wondering for some time why the export declaration doesn't support the "hiding" modifier, e.g. module M hiding (A, B(..), C(..), abc) where ... to make the export declaration a bit more symmetric with 'impsec' on the import side.
I think a good way to hide things without an exports list might be to simply prefix the type signature with a tilde character. For example:
module M where
~type A = () ~newtype B = B () ~data C = MkB1 () | MkB2 ()
~abc :: () abc = ()
increment :: Int -> Int increment = (+1)
So in this example, the module M would only export the "increment" function, everything else would be hidden.
So in order to hide a function/value this way, you have to write a type-signature for 'abc', in order to be able to declare 'abc' non-exported? [...] Cheers, hvr

It was discussed several times. for example: http://haskell.1045720.n5.nabble.com/Proposal-Pragma-EXPORT-tt5736547.html -- View this message in context: http://haskell.1045720.n5.nabble.com/Hiding-top-level-declaration-with-tilde... Sent from the Haskell - Haskell-prime mailing list archive at Nabble.com.
participants (3)
-
Herbert Valerio Riedel
-
Ramin Honary
-
Wvv