Created
January 25, 2015 06:53
-
-
Save gmpreussner/34b6bf829f8a2e46b2bb to your computer and use it in GitHub Desktop.
Generic tuple types
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
# compiles | |
type Foo = tuple[x, y: float] | |
proc foo(a, b: Foo): bool = (a.x == b.x) and (a.y == b.y) | |
var f = (1.0, 2.0) | |
check(foo(f, f)) | |
# does not compile | |
type Bar[T] = tuple[x, y: T] | |
proc bar(a, b: Bar): bool = (a.x == b.x) and (a.y == b.y) # Error: undeclared identifier: 'x' | |
var b = (1.0, 2.0) | |
check(bar(b, b)) # Info: instantiation from here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Workaround: