Putting the type checker to work
Types are very important in Haskell. It is, after all, a statically typed language. This means that programs are (type-)checked before they are run, by a process called the type checker. If the type checker finds that the program violates the typing discipline imposed by the language, then it raises a (type) error and the program will not be executed.
The type checker helps in several ways during the programming process.
Checking function calls
Firstly, when calling a function, it checks that we pass parameters of the appropriate type to that function. For instance, recall that discount
has the Int ->
Float
type:
*Main> discount True <interactive>:44:10: error: • Couldn't match expected type 'Int' with actual type 'Bool' • In the first argument of 'discount', namely 'True' In the expression...