-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]: rebind
doesn't work
#859
Comments
I dont have the answer but i'll participate https://docs.modular.com/mojo/roadmap.html#the-rebind-builtin
so it seems that the rebind function was created for that reason, and not for bitcast conversions here are some examples:fn print_int(x:Int):
print(x)
fn myfunc[T:AnyType](x:T):
if T == Int:
#print_int(x) #cannot do that because x is still of type T:AnyType
print_int(rebind[Int](x))
fn main() :
myfunc[Int](1) fn myfunc2(x:AnyType):
print(rebind[Int](x) 1)
fn main() :
myfunc2(rebind[AnyType](1)) fn print_int(x:Int):
print(x)
fn myfunc3[T:String](x:AnyType):
@parameter #compile time if statement
if T == "int_please":
print_int(rebind[Int](x))
else:
print("error..")
fn main():
var x=0
myfunc3["int_please"](rebind[AnyType](x))
myfunc3["nothing should happen"](rebind[AnyType](1.4)) parameters cannot be runtime values:
I think that rebind is something for compile time metaprogramming, |
Not sure if parameters play a role here. For example, the below code will run, but when you print, it will cause an error.
|
If i understand the rebind function correctly, it is relabeling the type, not casting |
Don't think I am doing anything wrong in my code, I will wait to hear from the Mojo team. |
sure, i just felt the need to participate in your issue, you can also come and join the community on discord if you like and have not already 🖖 |
Sure, thanks for your ideas and insights, appreciate your willingness to help 👍 |
This isn't the intended use of I'll improve the error message and update the doc to be clear about its intended usage. Thanks for filing this report! |
Ok, sounds good. Probably would be better to rename it too, so as to avoid confusion, as |
Bug description
Hosted Juypter instance:
Same with
Int -> StringLiteral
too.Steps to reproduce
System information
The text was updated successfully, but these errors were encountered: