Last time I looked at Nim, I was put off by the lack of algebraic data types and pattern matching. I still can't find anything about them in the manual. Am I missing something, or is this something it just doesn't have?
With ADTs:
data Shape a =
Rectangle
{ x :: Float
, y :: Float
, width :: Float
, height :: Float
}
| Circle
{ x :: Float
, y :: Float
, radius :: Float
}
With Object Variants, note that we don't have to repeat x and y: type
ShapeKind = enum Rectangle, Circle
Shape = object
x, y: float
case kind: ShapeKind
of Rectangle: width, height: float
of Circle: radius: float
The pattern matching in Nim is quite limited. Something like this works: let (x, y) = getCoordinates()
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...