Hacker News new | past | comments | ask | show | jobs | submit login

A type error means a type error, and nothing more. Type errors do not mean "incorrectness." Here is an example of something you can't do in rust, but can do in other statically typed languages.

```rust

struct Type1 { id: u32 }

struct Type2 { id: u32 }

fn main() {

    let obj1 = Type1 {

        id: 1

    };

    let obj2: Type2 = obj1; // compile error, Type1 is not Type2
}

```

This code works perfectly fine. These two structs have the same signature. The only thing that doesn't work is the names. There are dozens of things like this where your code works but the compiler is too strict. This is terrible for rapid iteration. It's good for other things like modeling your domain with types.




[text deleted because it was based on a incorrecf recollection of the details of Rust features.]


This was just one example of type error != logic error.

> one is for things that are structurally identitical but semantically distinct where confusing them creates a semantic error, the other is for alternate (usually, more concise) names for an existing type

This is not always true. Sometimes there are cases where you have different type aliases and want to use them interchangeably. Now you have to refactor them to inherit from some general type that didn't exist before. I also could count on one hand the amount of times this has caught a genuine bug even with diligent domain modeling (Which I would argue is overhyped).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: