would compiler be able to say "ohai I've just compiled this functor with this type I probably don't need to do it again?"
You are thinking of the way templates are typically compiled by C++ compilers. The compilation scheme of ocamlc
and ocamlopt
instead produces generic code that does not need to be duplicated.
The OCaml functor Map.Make
is compiled only once for all modules it may be applied to. The same code is executed when you call iter
from Map.Make(String)
and iter
from Map.Make(Float)
. Or indeed when you run iter
from two different applications of Map.Make
to String
.