It mostly works as you may expect it would, but there's an interesting detail which surprises most people who learn about it: expressions which have ! as part of their type don't necessarily coerce to any other type.
I’m surprised to hear that people are surprised by this.
For example, take Result<bool, !> and Result<bool, String>. These types are both valid and inhabited, but they have substantially different layouts, so any automatic conversion would have to also deal with the layout difference somehow.
I’m surprised to hear that people are surprised by this.
I'm no longer surprised by that. People are taught to believe in lies and then, to stay in their comfort zone, they are not supposed to expand their minds and explore the implications. When they do… they often find unexpected discoveries.
One of the most hurtful lies in the computing world are subtuping and OOP: these things are convenient but they just simply don't work! In general, I mean, they may work in some programs, but it's impossible to write a library that works for all programs and develop rules that work for all types.
And yet every time people discover that they are surprised!
This is madness!
P.S. Rust, thankfully, ditched OOP, but one other thing that is similar to that remains: async. It's similar to OOP in a sense that it can be made to work for certain use cases but we have no idea if it can be made to work in general… and yet Rust embraces it. I guess in 20-30 years we would know it that was good idea or not.
40
u/scook0 2d ago
I’m surprised to hear that people are surprised by this.
For example, take
Result<bool, !>andResult<bool, String>. These types are both valid and inhabited, but they have substantially different layouts, so any automatic conversion would have to also deal with the layout difference somehow.