Question on the grammar of functor

As we can see in the doc OCaml - The OCaml language, the functor’s definition “functor ( module-name : module-type ) → module-expr” seems to accept only one module name as argument, though we can provide multiple “(module-name : module-type)” as arguments to implement higher-order functor. So just wonder why not use the form “functor {( module-name : module-type )}+ → module-expr” to hint the Kleene plus form of the arguments? Thanks!

Note that the shorthand is explained in

https://ocaml.org/manual/modtypes.html#sss:mty-module

for module types; and in

https://ocaml.org/manual/modules.html#sss:mexpr-module-defs

for module expressions.

As this is purely syntax sugar, I guess that it was preferred to explain these separately instead of polluting the abstract syntax specifications…

Cheers,
Nicolas

Thanks for your answer!

So I guess you mean this:
" module module-name ( name1 : module-type1 ) … ( namen : module-typen ) = module-expr which is equivalent to module module-name = functor ( name1 : module-type1 ) → … → module-expr ".

However I think there are still some problems.

According to the functor’s definition: " module X (A:S) (B:T) = struct …end " can be rewritten as " module X = functor (A:S) → functor (B:T) → struct…end " which corresponds to the explanation you mentioned.

Furthermore I wonder how the form " module X = functor (A:S) (B:T) → struct…end " can be deduced via the BNF rules in the doc, on which I can’t find any clues.

You are right, this seems to be an oversight. Feel free to open an issue at https://github.com/ocaml/ocaml/issues or (even better) propose a PR to fix it! The source of the reference manual is at ocaml/manual/src/refman at trunk · ocaml/ocaml · GitHub

Cheers,
Nicolas

Thanks for your reply!

I just created a PR to update functor form in modtypes.etex and modules.etex.

The PR is now merged OCaml manual: change the argument of functor BNF into Kleene plus form in the doc by zyq8709 · Pull Request #10530 · ocaml/ocaml · GitHub

Thanks @zyq8709!

Cheers,
Nicolas

Thanks a lot for your kind help and advice! :slight_smile: