March 2019
Intermediate to advanced
208 pages
5h 11m
English
In the introduction, we mentioned that ReasonML’s static type system keeps you from making the sort of errors that can sink a dynamically typed program. You might be feeling a bit cheated in that we haven’t done a single bit of type specification so far in this chapter. That’s because ReasonML’s type inference engine has been doing a fantastic job of figuring everything out for us.
If, for example, you try to call the payment function with an integer for the annual percentage rate, the compiler won’t permit it:
| | We've found a bug for you! |
| | code/functions/src/TypeSpecifications.re 25:48 |
| | |
| | 23 │ |
| | 24 │ |
| | 25 │ let badCall = payment(~principal=10000.0, ~apr=5, ~years=15); |
| | 26 │ |
| | 27 │ |
| | |
| | This has type: |
| | int |
| |
Read now
Unlock full access