With ADTs:
data Shape a = Rectangle { x :: Float , y :: Float , width :: Float , height :: Float } | Circle { x :: Float , y :: Float , radius :: Float }
type ShapeKind = enum Rectangle, Circle Shape = object x, y: float case kind: ShapeKind of Rectangle: width, height: float of Circle: radius: float
let (x, y) = getCoordinates()
You could implement your own pattern matching using metaprogramming: http://www.drdobbs.com/open-source/nimrod-a-new-systems-prog...
With ADTs:
With Object Variants, note that we don't have to repeat x and y: The pattern matching in Nim is quite limited. Something like this works: But Nim doesn't have (x,y) = (y,x) for example, instead swap can be used.You could implement your own pattern matching using metaprogramming: http://www.drdobbs.com/open-source/nimrod-a-new-systems-prog...