Skip to content

Instantly share code, notes, and snippets.

@Yardanico
Last active August 23, 2017 19:10
Show Gist options
  • Save Yardanico/bf0cdf371464173e2af9c9bd7bbb5d7a to your computer and use it in GitHub Desktop.
Save Yardanico/bf0cdf371464173e2af9c9bd7bbb5d7a to your computer and use it in GitHub Desktop.
type Point[T] = object
x, y: T
proc newPoint[T](x, y: T): Point[T] = Point[T](x: x, y: y)
proc `+`[T](a, b: Point[T]): Point[T] =
result = Point[T](x: a.x + b.x, y: a.y + b.y)
proc `==`[T](a, b: Point[T]): bool =
a.x == b.x and a.y == b.y
assert newPoint(1, 0) + newPoint(2, 3) == newPoint(3, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment