Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Author of “Unix in Rust” Abandons Rust in Favour of Nim. Parent comment
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...
There are no comments on this comment yet.
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...