← Back to context

Comment by itishappy

2 days ago

> 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>

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>`.

  • Ok and Err are "thingies" which are in the type system, which give rise to distinctions that allow for compile-time diagnostics. They are part of the type.

    Ok and Err are not just type constructors because they appear on the left hand side in pattern matching: they "do" matching and destructuring also.