That's actually a problem in Erlang.
In Haskell, 'Maybe (Maybe Int)' is a different type from 'Maybe Int'.
That means that when you use eg a hash table that returns some kind null value like 'Nothing' on lookup when a key is not found, you can still stick exactly that kind of null value as a normal value into the table and everything will turn out fine.
The comparison here is with go.
Unwrap would look like:
file := os.Open("foo").Unwrap()
I'll take that over the current go state of the art: file, err := os.Open("foo")
if err != nil {
panic(err)
}
Just like "panic(err)" is used infrequently, "unwrap" would be used infrequently. They're comparable, and for the cases where unwrap is okay (test code, once-off scripts, etc), I'd definitely prefer it to the panic boilerplate.I don't understand this example at all. A Rust programmer would essentially never use unwrap on the return from File::open. It would be like checking open(2) with assert() in C.
Re:Go Replaces Interface{} with 'Any'
by preseinger on Wednesday December 15, 2021 @02:43AM
(#29563120)
That Go would never pass code review unless it is part of a tiny CLI tool or script.
I use rust and my code does not have .unwrap() (and definitely not .unwrap().unwrap()) in it either. That's what the ? operator is for.
The '?' is not a conceptual advance over .unwrap(), it's "just" a major syntactic convenience.
Re:Go Replaces Interface{} with 'Any'
by ComputerGuru on Wednesday December 15, 2021 @02:10AM
(#29562947)
Of course it is. Unwrap panics on error, while ? bubbles up the error instead. But ? wasn’t introduced to replace unwrap, unwrap was always frowned upon. It instead replaces match and return.
It was always frowned upon, but still ended up everywhere (including lots of documentation and example code) because it was less verbose than the match handling. The ? helped remove that last obstacle.
[1] https://github.com/SeaQL/sea-orm/blob/64c54f8ad603df0c1d9da8...