TL;DR
The static type describes the kind of data that could be associated with value. This post is part of the functional language series, and it is based on a remarkable book Programming Elm Build Safe and Maintainable Front-End Applications by Jeremy Fairbank.
The great source of errors in a program is when we associate with value data that do not match in type. Javascript allows this in the image above. We assigned to value number 3
, string 3
and float 3.00
. The assignment is not the issue here, but the problem arises when we start referencing in calculations when we expect value as a number, but user assigned string. It would be a nice feature that Javascript warns us about this in compile time.
Elm does this in compile-time because it uses static types
.
We have in StaticTypes module add function, and we try to add integer and string. Here is compilation result error:
Remember
- difference between dynamic and static type languages
- compilation vs. runtime errors