Hacker News new | ask | show | jobs
by z5h 806 days ago
This SOUNDS like “types are bad”. The author’s message (towards the end of the article) is “I don’t want to infer types from my code. I’d rather infer the code from the types. Types are the spec…”

Yes. Always annotate types. Keep inference, it tells you when your annotations are inconsistent with tour code.

2 comments

> Keep inference, it tells you when your annotations are inconsistent with tour code.

Isn't that plain type checking, rather than type inference?

Type checking detects inconsistencies, type inference assigns types in ways that avoid inconsistencies.

Right. I guess I meant annotate most of the things. (Top level things, complicated inner functions …) A few temporary values (next = current + 1) might go un-explicitly-typed. Anonymous functions will go untyped. I should have said “ensure your intentions with regards to types are clear”.
Clearly u/z5h meant that type annotations should be optional and used where not inconvenient. That's how I took it anyways.
> This SOUNDS like “types are bad”

No, this sounds like:

* Type Inference Was a Mistake

* Type Inference Makes Code Less Readable

* Type Inference is a Footgun

* Type Inference Wastes Academic Effort

These are incompatible with:

> Keep inference