Sorry, but I don't buy it.
When they are separate. I don't see it that way. In fact I would have liked your break 'fn
(and also break 'try
and, maybe, break 'if
) better than current return
.
But return
have extremely strong reason to exist: almost all curly-bracket languages (and many non-curly-bracket ones) have this operator.
That's the most compelling reason to have both return
foo
and also break
'label
foo
(I would have like return
'label
foo
better, but that ship have sailed).
yeet
doesn't have such advantage: it doesn't exist in any modern language and, in fact, I don't even remember any language where construct like proposed yeet
exists.
You have already shown how to solve that issue: if break 'try
would be usable in many try blocks (by just picking the innermost one) then you would only need labels for nested ones.
To me that makes perfect sense and yes, indeed, I would expect that code to work. Why shouldn't it work? It does work with nested try blocks and normal break.
It's perfectly clean if you don't introduce any “simplifications” and just make 'break
return actual value.
Yes, it may not be as pretty, but, presumably, you are not using try
just to then explicitly return errors from it. You don't need any syntax sugar for that. yeet
/break
/whatever is not supposed to be used often, if I understand the whole thing correctly, which means that the less magical it is the less confusing the whole thing becomes.
Adding one .into()
is not considered a big problem in Rust in many other cases, why this one is special?
P.S. I, kinda, understand why Rust can not just embrace monads, but their repeated reinvention is just tiring.