Higher-order module system of ML is actually possible in Haskell

A nice post from Oleg on the Haskell mailing list shows how to implement high order modules, and more specifically translucent applicative functors in idiomatic Haskell.

Thus different instantiations of the functor with respect to type-compatible arguments are type-compatible; and yet the functor hides the representation details behind the unbreakable abstraction barrier.

The work is inspired by (our own) Ken Shan's work that can be found here.

Oleg concludes,

The example illustrates that Haskell already has a higher-order module language integrated with the core language and with the module checking being a part of the regular typechecking.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Sharing by specification and taming the parameter explosion

A closely related message shows that type parameters of a functor may indeed proliferate exponentially. However, that problem can be fixed -- not only in ML, but also in Haskell. Even in Haskell we can, surprisingly, refer to parameters of a functor by their names rather than their positions. That message is a doubly literal code: both in OCaml and in Haskell. The Haskell part also shows off a recursive functor, which can be applied to itself. The key idea is that a module (structure, in ML speak) in Haskell is uniquely represented by a value and its type. That fact makes modules in Haskell not only first-class but also inspectable and introspectable.