Diagrams for structuring via modules and functors?

In object-oriented programming, the class diagram is a very popular way to show the structure of the system. (Perhaps at this point I should emphasize that this question is not about objects etc.)

In OCaml, we have module types, modules and functors. We can refine module types using e.g. “with type” annotations or similar. Refinement is in some ways similar to subtyping.

Is there any way to capture the relationships (including refinement) between module types, modules and functors in a diagram, analogous to a class diagram?

My hope is that this might make some things more easy to understand. For example, the chapter on modules here:


is great. But I find it quite hard to read and remember what is going on (too many things with similar names etc). Perhaps a diagram could help me?

Does that helps? :stuck_out_tongue:


More seriously, traditional UML-y class diagrams should work for modules, but pretty much nobody uses such a constrained format. You can find diagrams in some contexts (this for example) but it’s usually simpler to just write down the relations and follow the typechecker.

For the Module syntax, you can check DrawGrammar (Railroad diagrams of EBNF grammar)

(click on Examples / OCaml)


@spop : EBNF diagrams are fine, but I’m more interested in the things Drup is talking about.

@Drup: The Norm Ramsey diagram is something like what I would like. Indeed, it somewhat resembles my own attempts. But it all looks a bit ad hoc.

I created a single file called “recapitulation.ml”, where I reference all the main modules, functors, module types, etc. Not a diagram, but usefully collects the main types in a single place.

I’d like to write something like:

module type X = Foo.X = sig … end

(Analogous to type t = X.t = … ?)

This would allow the file to be reasonably self-contained (at the moment, I have to look at the file foo.ml at least). Is there anything like this?