Basically I have this code:
proc mkString*[T](v : T, prefix, sep, postfix : string) : string =
result = prefix
var first = true
for x in v:
if not first:
result.add(sep)
result.add($x)
first = false
result.add(postfix)
type Vec[h : static[int], T] = distinct array[h, T]
proc arr[h : static[int], T]( v : Vec[h,T] ) : array[h, T] = cast[array[h, T]](v)
proc `$`[h : static[int], T](v : Vec[h,T]) : string =
v.arr.mkString("vec" & $(h) & "(", ", ", ")")
type Vec2f = Vec[2, float32]
proc vec2f(x,y : float32 ) : Vec2f = [x,y].Vec2f
type Mat[w, h : static[int], T] = distinct array[w, Vec[h, T]]
proc arr[w, h : static[int], T]( m : Mat[w,h,T] ) : array[w, Vec[h, T]] =
# type mismatch: got (array[0..1, Vec[h, system.float32]]) but expected 'array[0..1, Vec[2, system.float32]]'
cast[array[w, Vec[h, T]]](m)
# seriously?
proc `$`[w,h : static[int], T](v : Mat[w, h,T]) : string =
let prefix = "Mat" & (if w == h: $w else: $w & "x" & $h) & "("
v.arr.mkString(prefix, ", ", ")")
type Mat2f = Mat[2, 2, float32]
proc mat2f(x,y : Vec2f) : Mat2f = [x,y].Mat2f
echo mat2f(vec2f(1,2), vec2f(3,4))
this is the compile error:
~/proj/nim/break/ nim c vector_type_03.nim
Hint: system [Processing]
Hint: vector_type_03 [Processing]
vector_type_03.nim(34, 11) template/generic instantiation from here
vector_type_03.nim(28, 4) template/generic instantiation from here
vector_type_03.nim(23, 3) Error: expression cannot be casted to array[0..1, Vec[h, system.float32]]
in emacs the red line under the cast operator in proc arr[w, h : static[int], T]( m : Mat[w,h,T] ) says the following:
type mismatch: got (array[0..1, Vec[h, system.float32]]) but expected 'array[0..1, Vec[2, system.float32]]'
I should mention, that in this context h has the value 2, so the only difference I can see is that got is in () and expcted in in ''
You should do this instead:
array[w, Vec[h, T]](m)