Non-trivial parameter are not matched

What is the expected behaviour while matching parameters. Should they be structurally equal, or is some rewriting on their AST expected? For example, the following code gives the error on the return of doubleCube.
cannot implicitly convert 'SIMD[T, __lshift__(1, __add__(__sub__(N, 1), 1))]' value to 'SIMD[T, __lshift__(1, N)]' in return value
cannot implicitly convert 'SIMD[T, __lshift__(1, __add__(__sub__(N, 1), 1))]' value to 'SIMD[T, __lshift__(1, N)]' in return value
because 1<<((N-1)+1) is not considered equal to 1<<N which suggests threre is no rewriting of parameters.
fn doubleCube[T: DType, N: Int]() -> SIMD[T, (1 << (N+1))]:
return SIMD[T, (1 << (N+1))](0) #TODO

fn reflectCubeX[T: DType, N: Int]() -> SIMD[T, (1 << N)]:
if N == 2:
return doubleCube[T, N-1]()
else:
print("ERROR: return identity cube")
return SIMD[T, 1<<N](0)
fn doubleCube[T: DType, N: Int]() -> SIMD[T, (1 << (N+1))]:
return SIMD[T, (1 << (N+1))](0) #TODO

fn reflectCubeX[T: DType, N: Int]() -> SIMD[T, (1 << N)]:
if N == 2:
return doubleCube[T, N-1]()
else:
print("ERROR: return identity cube")
return SIMD[T, 1<<N](0)
mojo 0.4.0 (9e33b013) Question: is it reasonable that this non-trivial (but not ridiculous complex) parameter 1<<N is matched? Or will this type of template programming be beyond the reach of Mojo?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server