first class modules
Passing around modules as functions is a very powerful capability and allows emulating a lot of other language features in combination with a few other things:
- with abstract types in modules you can emulate GADTs: http://lambda-the-ultimate.org/node/4101
- together with implicit arguments it can also be used to implement something similar to type classes by using the module as the type class dictionary
This is a fairly large pain point in Haskell, here are some proposals for improving Haskell’s module system that provide interesting insights into what design decisions can cause large problems further down the road:
- Less ambitious proposal that does a good job of showcasing some of the flaws in GHC’s module system that caused a more amitious proposal to not be possible
- More ambitious proposal: probably too much to implement in GHC, but good design ideas for a new language
Implementation notes
Typically first class modules are implemented as a fancy dependent record. It would be good to unify the implementation of records with the implementation of modules ideally.