3 ms·
> That is exactly what Rust does Cool, that's good to know (I've not used Rust (yet)) > There's nothing implicit about Option, it's literally the concrete ret
by chriswarbo 4y ago
> That is exactly what Rust does
Cool, that's good to know (I've not used Rust (yet))
> There's nothing implicit about Option, it's literally the concrete return type of the function
For context, I was referring to this paragraph in the article regarding `.then`:
> I’m not a huge fan of the implicit introduction of the Option type. In a language like Rust, implicitly introducing Option is barely acceptable: Option is already a priveleged type, and ‘accidentally’ assigning such an optional if-expression to a variable will likely cause a type mismatch error, caught by the compiler.
---
> Rust does not have lazy arguments, arguments are always eagerly evaluated.
I thought as much, since it would be a glaring omission if Rust did have this feature but didn't use it for the argument of '.then' ;)
It also makes sense given Rust's goals of low-level, high-performance, substructural-typing, etc.: if extra wrapping/unwrapping is needed, better to make it explicit (and enforced by the types), rather than have the compiler slowing things down without warning.
Also, to be clear: the Scala version is actually pass-by-name, rather than lazy; e.g. the following function will evaluate its argument twice!
def double(x: => Int): Int = x + x