Skip to content

Instantly share code, notes, and snippets.

@gmpreussner
Created January 25, 2015 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmpreussner/34b6bf829f8a2e46b2bb to your computer and use it in GitHub Desktop.
Save gmpreussner/34b6bf829f8a2e46b2bb to your computer and use it in GitHub Desktop.
Generic tuple types
# 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
@gmpreussner
Copy link
Author

Workaround:

var b: Bar[float] = (1.0, 2.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment