July 2023
Intermediate to advanced
670 pages
17h 13m
English
Type annotations, which are also sometimes called type signatures, are how Haskell lets you associate a type with an expression. Type annotations come after the name of a top-level function, a let or where binding, or after an expression. A type annotation starts with two colons (::) followed by the type name.
Adding a type annotation to a binding in a source file can be done in two separate lines. For example, open a new source file and copy in the following example to create a new top-level binding named pi and give it the Float type:
| | pi :: Float |
| | pi = 3.14 |
If you have several bindings with the same type you can add them on multiple lines, or on a single line separated by commas:
| | one, two :: Int ... |
Read now
Unlock full access