Hacker News new | ask | show | jobs
by nextaccountic 803 days ago
> You won't ever see fast compilation times with it, and here's why:

> > type annotations are rarely necessary, thanks to powerful type inference. This keeps the code clean and feels like a dynamic language.[1]

There are fast type inference implementations. For example, the OCaml compiler is pretty fast

No reason Crystal couldn't improve this part of compile time in future

1 comments

I suspect that doesn't hold true for some larger projects (10K+ LOC) with no annotations but point taken.

My experience with F# (which was way back in version 2.0, but based on OCaml which does type inference very similarly), was that the inference would become slower as the size of the project increased, eventually taking multiple seconds. I eventually adopted a habit of adding type annotations to commonly-used functions because it mitigated the problem. These projects were not huge by any means (5-10K LOC).

There is probably a good compromise to be found here. It should be possible for a tool to suggest areas to add annotations where it would do the most good for performance. But maybe those are non issues with modern implementations.

Adding type annotations in OCaml never reduce the typechecking time: it adds more information for the typechecker to process and it can only increase the size of type. Typechecking time is proportional to the size of types but those tends to stay constants and small inside normal project. I think that F# should have a similar behaviour?