> In Rust, if you have an thing that returns Result<String, String> that's still type safe, even though success and error types are the same.
These types are not the same:
Ok<String>
Err<String>
Re:Sshole
by markasoftware on Friday November 06, 2026 @12:57AM
(#50388711)
Those are not types at all. Ok and Err are type constructors for the Result<A, B> type that take arguments of type A and B respectively.
> type constructors
Nit: the type constructor is `Result`: given two types `A` and `B` (not instances of those types, but actual types) it gives you a new type `Result<A, B>`.
`Ok` and `Err` are called "variants" and can be used to construct a new _instance_ of `Result<A, B>`.
Re:Sshole
by markasoftware on Friday November 06, 2026 @04:41PM
(#50398887)
Ah, thanks! I'd remembered the term "data constructor" from Haskell and called it a type constructor instead.
[delayed]
[delayed]
Basically, you need the whole 'success and error types are different' in a language like Python if you make the return type something like "int | string", where 'string' stands for your error message.
Of course that breaks down, when the success type is also an error message, eg when you are looking up something in a catalogue of error messages.
Rust has no trouble with this, for exactly the reasons you line out.
That's a bit weird? In Rust, if you have an thing that returns Result<String, String> that's still type safe, even though success and error types are the same.
I think I know what you want to express..
You might say it's in-band vs out-of-band error signalling?