How to declare a function type in a trait?
This is a simple class in Python
Now I thought I could this in Mojo in someway but stucked
Is there any possible way of doing this in Mojo?
Error:
9 Replies
You have to set the type to match the function signature. And Fn functions must explicitly return there type.
But this makes for an inflexible
_hello
function as now it must return None.Congrats @mad alex 1997, you just advanced to level 11!
Thanks for the answer, so is it not possible to be more flexible with this apperoach in any ways?
Not without doing something weird, strong typing is a double edged sword.
I see, but still it is a good start, thanks and now I am starting to see the cons of strong typings .. ughh
Technically if you are willing to do something verbose and your functions don't need parameters (I'll put in a bug report for it tomorrow) only arguments.
Hi, so there was one more problem I am facing
So, in any how I was not able to initialize my func_module which is taken from func.py file. I got to insert it under try block other wise giving me error, and once that done, I am getting this kind of error:
the compiler needs to know with 100% certainty that
self.func_module
is initialized by the end of __init__
but it can't because it only gets initialized in your try block but not the except block. You'll need to give it some value in your except block or just get rid of the try-catch and make __init__
raiseyes, I am thinking of not adding try block but then you saying just using a raise would work with an if?