News for hackers. Stuff that matters.
Re:Sshole by eru on Thursday November 05, 2026 @09:37PM (#50387465)
> [...] because the success type and error type are the same.

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?

Re:Sshole by itishappy on Thursday November 05, 2026 @10:13PM (#50387717)
> 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.
Re:Sshole by SkiFire13 on Friday November 06, 2026 @02:00AM (#50389078)
> 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.
Re:Sshole by kazinator on Friday November 06, 2026 @06:52PM (#50400123)
[delayed]
Re:Sshole by kazinator on Friday November 06, 2026 @06:48PM (#50400090)
[delayed]
Re:Sshole by eru on Friday November 06, 2026 @09:35PM (#50401089)
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.