Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Coq-like modules #522
The idea is that semantically, there is some operation on types called e.g.
Module Type TypeM. Parameter m : Type2. End TypeM.
then any actual instantiation of
then we can only apply
Dan Licata has convinced me that a better way to do this is to have a type theory with two contexts, one for "flat types" and one for ordinary types, with the rule that flat can only be applied to types whose ordinary-context is empty. Apparently this is a common technique in modal type theory. So if there is a way to allow multiple kinds of context (cubical type theory also involves a separate context of "line variables") that would be awesome too.
By the way, the fact that modules can only be defined at top level is also essential for the consistency of the universe polymorphism. An operation that's defined at all universe levels is a "very large" gadget, not living in any universe itself, so hypothesizing such a thing is only possible "externally". Note that Agda's modules are different from Coq's --- in many ways, but one of them is that an Agda module-function can be parametrized by types and not just by modules, which breaks the
The introduction of modules has proved in retrospect to be a very invasive change to Coq's kernel, and many of us (Coq developers) think today that an elaboration to dependent records would have been enough for most usages. So you may want to think twice before polluting Lean's nice and small kernel.
The tricky aspects of Coq's modules (and functors) are the handling of name substitutions (when applying a functor) and subtyping. They tend to complexify other parts of the kernel that are apparently orthogonal.
Also, from a more theoretical standpoint, I am not aware of any detailed proof explaining why the addition of modules and functors (and the restrictions Mike mentions, that they can only be defined at toplevel) to the whole formalism of Coq (including inductive types, universe polymorphism and impredicativity) preserves consistency and normalization.