Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Accept value declarations as structure items #6688
Original bug ID: 6688
I propose to let the parser accept value declarations (val x : ...) as valid syntactic structure items. They can already be encoded in the Parsetree (as Pstr_primitive, which takes a value_description argument), so the impact on the code (Ast_helper, Ast_mapper, print_ast, etc) is minimal.
Such declarations would be rejected by the type-checker, but later, one could give interesting meaning to them (e.g. to specify locally the expected type scheme for a value definition; or even support local forward declarations). The reason to add them now is to give more freedom to what can go into an extension/attribute payload, cf #6681.
(It would also make sense to rename Pstr_primitive to Pstr_value, but then this impacts more existing code.)
A patch is attached. In addition to it, one should get rid of the following comment in parsetree.mli:
"Note: when used under Pstr_primitive, prim cannot be empty"