semi-private exports

Simon Marlow
Tue, 23 Apr 2002 16:29:57 +0100

> In my NLP.Prelude file, I define:
> > newtype Token =3D Token [Word8]
> and I export only the type, not the constructor because I=20
> don't users of
> my package to be able to inspect/modify the list directly. =20
> However, in my
> NLP.IO module, in which I define IO for some of my data=20
> types, I need to
> be able to access it directly.
> In Java/C#, I would make Token public and the constructor=20
> protected (i.e.,
> public for the current package but private for other people).  I would
> really like to be able to do something similar.  Any ideas?

Define the type in a private module, say DLP.Prelude.Private, which is
used by NLP.IO, and re-export it abstractly from NLP.Prelude.  You don't
get the benefit of language support for enforcing that
NLP.Prelude.Private isn't nefariously imported by the client, but at
least now with hierarchical modules the private module name isn't
polluting the client's module namespace.