Hi guys, I've been rewriting my project to nim, it is written in rescript(a modified version of the OCaml compiler), I have a little type model like below:
type equal =
| EqualStr(string)
| EqualInt(int)
type cmp =
| LessThan(int)
| GreatThan(int)
| Equal
It is used to express a rule which has several possible comparable cases, I wrote the following nim code to map the idea:
type
IntOrString = enum
int, str
Ios = ref object
case kind: IntOrString
of int: intOf: int
of str: stringOf: string
type
CmpKind = enum
greatThan, lessThan, equalTo
Cmp = ref object
case kind: CmpKind
of greatThan: greatVal: int
of lessThan: lessVal: int
of equalTo: iosValue: Ios
which looks a lot more than the rescript one, especially the IntOrString case, can I simplify the modelling code in Nim?