"why can't crystal resolve the type of the assignment of 1 + 1?" Code Answer


If I'm not mistaken, Crystal used to be more aggressive in deducing the types. While it is elegant in certain examples, it creates more issues in bigger projects. Compilation times became a problem (incremental compilation is hard or impossible), and errors in the code (e.g. because of a typo) could be harder to track down when everything propagates.

In the end, keeping the interference rules simpler and falling back to explicit types for expressions was considered more practical. Here is a discussion about the change from 2015. I'm not involved in the language design, but reading through the thread, I think the arguments in the thread apply to your question (why 1 + 1 needs to be explicitly typed). Note that 1 + 1 is a simple case, but expressions can become arbitrary more complex once you allow them. In general, the compiler would have to work through the whole program code to do the analysis.

By Jesus is Lord on January 9 2022

Answers related to “why can't crystal resolve the type of the assignment of 1 + 1?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.