I\'ve been doing some OCaml programming lately to learn the language and to get more acquainted with functional programming. Recently, I\'ve started to think that I\'d like
An interesting solution is to use polymorphic variant:
type bexp =
[ `And of bexp * bexp
| `Or of bexp * bexp
| `Xor of bexp * bexp
| `Not of bexp ];;
type nbexp = [ bexp | `Nop of nbexp ];;
Note that polymorphic variants are trickier than normal ones, but allow extension of type.
An interesting example of expression evaluation, with extension, using polymorphic variant can be found in a test directories of the ocaml source, see the svn