Last active
August 23, 2017 19:10
-
-
Save Yardanico/bf0cdf371464173e2af9c9bd7bbb5d7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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