Re:Good-bye core types; Hello Go as we know and love it
by steveklabnik on Thursday March 27, 2025 @10:21AM
(#43493966)
Where did you get this Rust code from? Iām curious.
[ Parent
| on HN ]
Re:Good-bye core types; Hello Go as we know and love it
by 9rx on Thursday March 27, 2025 @10:34AM
(#43494091)
I found the same code in several different places. Wikipedia was the place I ultimately copy/pasted it from.
Re:Good-bye core types; Hello Go as we know and love it
by steveklabnik on Thursday March 27, 2025 @11:12AM
(#43494497)
Huh, I don't see this code on Wikipedia.
I ask because it's very much not "canonical," Just and Nothing are Haskell terms, not Rust terms. You'd expect at least Some and None.
Regardless, I do agree that in this specific circumstance, you're emulating an if. There's even a form in this case that emulates it even more closely:
if Some(x) = divide(3.0, 2.0) {
println!("Answer: ", x);
} else {
println!("division failed; we'll get 'em next time.");
}
But these simple cases don't show off where Option/Result truly shine.
Re:Good-bye core types; Hello Go as we know and love it
by steveklabnik on Thursday March 27, 2025 @11:17AM
(#43494543)
Ah, thanks, I was looking at the Rust page. I'll consider sending them an edit.
Sent one in: https://en.wikipedia.org/w/index.php?title=Monad_(functional... we'll see if it gets reverted. Honestly, I find this whole section kind of awkward. I fully agree with you that it doesn't really show off why this stuff works, and works well. Real-world code doesn't get written like this.
Re:Good-bye core types; Hello Go as we know and love it
by umanwizard on Friday March 28, 2025 @12:28PM
(#43507289)
you're missing a `let`
Re:Good-bye core types; Hello Go as we know and love it
by steveklabnik on Friday March 28, 2025 @03:25PM
(#43509080)
dangit, thanks. can't edit now though...