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
# Suppose we have the following type for a rectangular array: | |
type | |
RectArray*[R, C: static[int], T] = distinct array[R * C, T] | |
var a23: RectArray[2, 3, int] | |
var a32: RectArray[3, 2, int] | |
echo "a23: ", a23.R, "x", a23.C | |
echo "a32: ", a32.R, "x", a32.C |
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) |
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
# this works ########################## | |
type | |
Foo[N: static[int], T] = object | |
elements: array[0..(N - 1), T] | |
var f2 = Foo[2, float](elements: [1.0, 2.0]) | |
var f3 = Foo[3, float](elements: [1.0, 2.0, 3.0]) | |
NewerOlder