type Vect[N: static[int], A] = array[N, A]
proc plusOne(n: int): int = n + 1
proc concat[M, N: static[int], A](a: Vect[M, A], b: Vect[N, A]): Vect[M + N, A] =
for m in 0 .. < M:
result[m] = a[m]
for n in 0 .. < N:
result[M + n] = b[n]
proc push[N: static[int], A](a: Vect[N, A], x: A): Vect[plusOne(N), A] =
for n in 0 .. < N:
result[n] = a[n]
result[N] = x
proc `$`[N: static[int], A](a: Vect[N, A]): string = $(@(a))
when isMainModule:
let
a = [1, 2, 3, 4]
b = [2, 3, 6, 8, 9]
echo concat(a, b)
echo push(a, 5)
For some reason, though, if I use array[N, A] directly, instead of wrapping it in the equivalent Vect[N, A] type, the compiler fails with
example3.nim(5, 44) Error: internal error: cannot generate code for: M
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>
Is there a reason why array receives special treatment with respect to other generic types? It is not a big deal to create a type alias, but maybe it is not necessary after all