Last active
February 27, 2016 18:32
-
-
Save gmpreussner/5ed8d0e4b921564f7e1d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 IntArray[T; N: static[int]] = array[N, T] | |
proc ones[T](N: static[int]): IntArray[T, N] = | |
for i in 0 .. < N: | |
result[i] = 1 | |
echo @[ones[int](5)] |
type inference works...
type IntArray[T; N: static[int]] = array[N, T]
proc `$`(a: IntArray): string = $(@(a))
proc defaults[T](N: static[int], default: T): IntArray[T, N] =
for i in 0 .. < N:
result[i] = 1
echo defaults(5, 1.0)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tstatic_ones_generic.nim(7, 12) Error: cannot instantiate: ones[int]; got 1 type(s) but expected 2