change in syntax for types declaration

Can we have new syntax for function type hinting Current;
fn function_name(var : String) -> String:
# function body
fn function_name(var : String) -> String:
# function body
New declaration:
fn function_name(var : string) -> string:
# function body
fn function_name(var : string) -> string:
# function body
I am asking for removal for capitalization of type name
3 Replies
Ryulord
Ryulord12mo ago
The capitalization is actually important for Mojo's goal of being a strict Python superset. This is because the lowercase type hints are already what's being used in Python and they don't actually change the behavior of the code, whereas Mojo's capital letter type hints do affect behavior. Consider the following code:
def double_it(x: float) -> float:
return 2 * x

x = double_it(42)
def double_it(x: float) -> float:
return 2 * x

x = double_it(42)
This works in both Python and Mojo because the type hints don't enforce anything but capitalizing float or making Mojo treat lowercase like it currently treats uppercase will make Mojo complain about you using the wrong type. This is important because a lot of big important Python libraries lie to you with their type hints like this.
VikasPoddar001
VikasPoddar001OP12mo ago
Oh, thanks for replying and explaining the concept
Arthur Evans
Arthur Evans12mo ago
Also, the types themselves are different. I.e., Int versus int isn't a matter of the compiler looking at capitalization... int is a Python class. Int is a Mojo struct.
Want results from more Discord servers?
Add your server