I have a variant type like this:
type score =
InInteger of int
| InFloat of float ;;
Now, given two scores (InInteger(5) and InFloat(5.5)), I want to add, subtract them etc..
How can this be done?
PS – I’m a newbie to OCaml.
Edit::
More specifically:
How does this work?
let n = InInt(2);;
let m = InFloat(3.2);;
let var = InFloat(float n +. m);;
First, discriminated unions require their identifiers starting with upper cases:
Second, you can define an
addfunction on this datatype by pattern matching all possible cases and returning appropriate values: