2
type t = A;;
.<A>.;;

will give error Unqualified constructor A cannot be used within brackets. Put into a separate file.

What is the underlying reason of this error?

Some reference can be found here

objmagic
  • 1,028
  • 1
  • 9
  • 18

1 Answers1

3

Here is the official explanation - http://okmij.org/ftp/ML/MetaOCaml.html#ctors

My very vague guess would be that this restriction comes from the need to ensure that actually same variant definition is used at compile-time and run-time when referenced in staged code (because same code can and will be compiled at different points of time in run-time), by putting type declarations in separate modules they get hashed and checked by compiler with usual checks for interface matching. Also I think the possibility of shadowing plays some role here.

ygrek
  • 6,656
  • 22
  • 29