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