[Haskell-cafe] Re: Best practices for modular programming in Haskell

oleg at pobox.com oleg at pobox.com
Thu Mar 17 00:21:18 EST 2005

Benjamin Pierce wrote:
> For someone coming to Haskell from an OCaml background, one of the hardest
> things to get used to is the somewhat more bare bones module system that
> Haskell provides.
> ...
> This works fine as long as what you're exporting is just values, but it's
> awkward for types, since there is no way to *declare* a type (e.g., giving
> just its kind) without *defining* it.

Actually Haskell fully matches the module system of OCaml -- and then
adds some. Haskell provides both generative and applicative (recursive)
functors. The following two messages elucidate the correspondence


The end of the first message gives the translation dictionary: from
OCaml/ML module terminology to Haskell terminology. I have recently
found out that the translation works the other way around, too.

Both messages are doubly-literate code: messages can be loaded into
OCaml or into a Haskell system.

Regarding the specific question of hiding a type: oftentimes declaring
a class and exporting it suffices. (forall a.C a => a) is an
`abstract' type in Haskell. If the type to abstract has a kind *->*,
we can write (forall a.C a => a b), etc. If we really want to prevent
the user from ever knowing the details of the implementation,
existential quantification (along with the typeclass) does the
trick. That trick incidentally permits `self-tuned' data structures,
the simple example of which is


More information about the Haskell-Cafe mailing list