Parse.add_numeral_form : (char * string option) -> unit
A call to add_numeral_form(c,s) augments the global term grammar in two ways. Firstly, in common with the function add_bare_numeral_form (q.v.), it allows the user to write a single letter suffix after a numeral (the argument c). The presence of this character specifies s as the ``injection function'' which is to be applied to the natural number denoted by the preceding digits.
Secondly, the constant denoted by the s argument is overloaded to be one of the possible resolutions of the overloaded operator &. When a numeral doesn't have a character suffix, this means that it has been made an argument to the function fromNum, and so might take on different types, depending on the context.
val _ = add_numeral_form (#"n", NONE);This is done in arithmeticTheory so that after it is loaded, one can write numerals and have them parse (and print) as natural numbers. However, later in the development, in integerTheory, numeral forms for integers are also introduced:
val _ = add_numeral_form(#"i", SOME "int_of_num");Here int_of_num is the name of the function which injects natural numbers into integers. After this call is made, numeral strings can be treated as integers or natural numbers, depending on the context.
- load "integerTheory"; > val it = () : unit - Term`3`; <<HOL message: more than one resolution of overloading was possible.>> > val it = `3` : term - type_of it; > val it = `:int` : hol_typeThe parser has chosen to give the string ``3'' integer type (it will prefer the most recently specified possibility, in common with overloading in general). However, numerals can appear with natural number type in appropriate contexts:
- Term`(SUC 3, 4 + ~x)`; > val it = `(SUC 3,4 + ~x)` : term - type_of it; > val it = `:num # int` : hol_typeMoreover, one can always use the character suffixes to absolutely specify the type of the numeral form:
- Term`f 3 /\ p`; <<HOL message: more than one resolution of overloading was possible.>> > val it = `f 3 /\ p` : term - Term`f 3n /\ p`; > val it = `f 3 /\ p` : term