Hacker News new | ask | show | jobs
by muglug 806 days ago
Sometimes you'll read something and think "I'm not taking the bait".
3 comments

>> Sometimes you'll read something and think "I'm not taking the bait".

Like when I read about "auto" in C++. It still bugs me when I see it...

It's not even factual.

> In Rust and Haskell you have to at least annotate the parameter types and return type of functions. Type inference is only for variable bindings inside the function body.

This is false for Haskell. Can't speak for Rust.

In rust, you are required to annotate at least the interface. In Haskell, if I remember it well, it is allowed but not required.

Even in Rust, I tend to specify types at variable bindings if the type gets overly complex, just to push errors closer to their cause.

A nice feature of Rust is you can specify partial types, wih underscores for the still-to-infer part. E.g. let x:Vec<_>=someexpression; is a vector of something, but you don't know what exactly.

> you can specify partial types, wih underscores for the still-to-infer part

Yup. I love that. And it even lets you say things like for example:

    let res: Result<Vec<_>, _> = someexpression;
Rust does require explicitly writing out the signature of top-level functions.

I believe it was a conscious decision to limit de cascading of type errors from global type inference, the base algorithm was capable of it.

Yes, particularly due to the design decision that Rust code should strive to be explicit in intention and mechanism.
it's technically false for Haskell, but is considered mostly good practice. It would be true for Idris.
At least it wasn't titled, "Type Inference Considered Harmful". That one always infuriates me.