M
Modular•3w ago
JulianJS

Why not separate Parameters and Generics?

The mojo docs have the following example:
fn repeat[MsgType: Stringable, //, count: Int](msg: MsgType):
@parameter
for i in range(count):
print(msg)
fn repeat[MsgType: Stringable, //, count: Int](msg: MsgType):
@parameter
for i in range(count):
print(msg)
I personally find it a little confusing and "hacky" to mix Parameters and Generics. The docs even say
This is a little confusing, because the parameter value you're passing in this case is a type
What about adding an additional "block" to separate them like (only one idea):
fn repeat[MsgType: Stringable](msg: MsgType)<count: Int>: ...
fn repeat[MsgType: Stringable](msg: MsgType)<count: Int>: ...
With that you have clear separation - [...]: for Generics / Types; - (...): for function arguments (generics/types can be used here) - <>: for parameters; used inside the function Any thoughts on this? 🤔 🤓
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server