Replies: 1 comment
-
Mojo uses this syntax because, since 3.12, Python does. Mojo aims to be a strict superset of Python, so it has to add these features. As for why Python decided to use this syntax, I'm not very knowledgeable about type theory and how it interacts with programming language syntax, so I don't know. You'll have to ask people who do know. It seems that this verbose syntax is inescapable since even modern languages like Rust use it, though it provides some syntax sugar. For example: pub fn notify(item: &impl Summary) {
println!("Breaking news! {}", item.summarize());
} ...desugars to: pub fn notify<T: Summary>(item: &T) {
println!("Breaking news! {}", item.summarize());
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The biggest difference between Java and Python is how verbose Java is compared to Python -- as such I find
fn make_it_quack[T: Quackable](implements_quack: T):
to be extremely unwieldy and unnecessarily verbose. Why can't the compiler acceptfn make_it_quack(implements_quack: Quackable):
instead? It can see that Quackable is defined as a trait, so there's no confusion over whether it's a trait or a struct.And
fn factory[T: MassProducible]() -> T:
can befn factory() -> MassProducible:
.Similarly for the case of calling static functions on traits, i.e.
fn fun_with_traits[T: HasStaticMethod](): T.do_stuff()
-- why not justfn fun_with_traits(): HasStaticMethod.do_stuff()
?Beta Was this translation helpful? Give feedback.
All reactions