syntax_fns : {dest: term -> exn -> term -> 'a, make: term -> 'b -> term, n: int} -> string -> string -> term * ('b -> term) * (term -> 'a) * (term -> bool)
> val num1 = HolKernel.syntax_fns {n = 1, make = HolKernel.mk_monop, dest = HolKernel.dest_monop} "num"; val num1 = fn: string -> term * (term -> term) * (term -> term) * (term -> bool)
> val (suc_tm, mk_suc, dest_suc, is_suc) = num1 "SUC"; val dest_suc = fn: term -> term val is_suc = fn: term -> bool val mk_suc = fn: term -> term val suc_tm = ``SUC``: term
> val tm = mk_suc ``4n``; val tm = ``SUC 4``: term
> is_suc tm; val it = true: bool > val v = dest_suc tm; val v = ``4``: term
> is_suc ``SUC``; val it = false: bool > val v = dest_suc ``SUC``; Exception- HOL_ERR {message = "", origin_function = "dest_SUC", origin_structure = "numSyntax"} raised
The value n in the call to syntax_fns acts purely as a sanity check. For example, the following fails because SUC is not a binary operation:
> HolKernel.syntax_fns {n = 2, make = HolKernel.mk_binop, dest = HolKernel.dest_binop} "num" "SUC"; Exception- HOL_ERR {message = "bad number of arguments", origin_function = "systax_fns", origin_structure = "numSyntax"} raised
> val tm = bitstringSyntax.mk_v2w (``l:bitstring``, ``:32``); val tm = ``v2w l``: term > type_of tm; val it = ``:word32``: hol_type > bitstringSyntax.dest_v2w tm; val it = (``l``, ``:32``): term * hol_type
val (v2w_tm, mk_v2w, dest_v2w, is_v2w) = HolKernel.syntax_fns {n = 1, dest = fn tm1 => fn e => fn w => (HolKernel.dest_monop tm1 e w, wordsSyntax.dim_of w), make = fn tm => fn (v, ty) => Term.mk_comb (Term.inst [Type.alpha |-> ty] tm, v)} "bitstring" "v2w"