The type of this function:
let do_finc = function
| `Float f -> `Float (f +. 1.0)
Is [< `Float of float ] -> [> `Float of float ]
. In other words, it takes as input any variant type that has at most a `Float
alternative; i.e., either has a `Float
alternative, or no alternatives at all. It seems to me you want the function to work for variants that have at least a `Float
alternative , i.e., a variant that has `Float
and any number of other variants:
let do_finc = function
| `Float f -> `Float (f +. 1.0)
| _ -> failwith "wanted a float"
If I change do_iinc
and do_finc
in this way, the table has a type closer to what you want.
I'm not at all sure that your plan will work, as you might be expecting OCaml to accept type-incorrect programs and complain at runtime. Instead OCaml complains at compile time and you probably have to write your own code to complain at runtime :-) But this might help get past the first problem.