top | item 47147415

(no title)

9rx | 4 days ago

> super type safe

Maybe if you're willing to write insanity like this:

    struct Zero;
    struct Succ<N>(N);

    trait Add<Rhs> {
        type Output;
    }

    impl<M> Add<M> for Zero {
        type Output = M;
    }

    impl<N, M> Add<M> for Succ<N> 
    where 
        N: Add<M> 
    {
        type Output = Succ<<N as Add<M>>::Output>;
    }
But even then it doesn't really work all that well for any practical use and you'll quickly hit a bunch of other roadblocks if you were to actually try to use it. You're pushing Rust to go well beyond what it is designed for. If we're being honest, in the real world you're going to write something like this instead:

    fn add(a: u32, b: u32) -> u32 {
        a + b
    }
But then you give up the type safety. So it's not really a type safe language in any meaningful sense. Certainly not compared to languages that are designed to be actually type safe. If your only point of comparison is Javascript, then sure, Rust looks pretty super type safe in comparison to that, but in the grand scheme of things it's not type safe.

If it is just as easy to emit a language that is type safe, why Rust?

discuss

order

echelon|4 days ago

We skipped over sum types here and the syntactic sugar that makes them a cut above other languages.

9rx|4 days ago

Other languages meaning Javascript? Rust doesn't even have proper sum types. Try expressing this Coq sum type in Rust: { x : A & B x } I'll wait.

If it is just as easy to emit a language that is type safe, why Rust?