July 2023
Intermediate to advanced
670 pages
17h 13m
English
As you get more accustomed to using types to help you write correct programs, you’ll start to find that sometimes you want to test if the types for your functions are right before you spend the time implementing them. To help with that, Prelude includes the undefined function, which has the type undefined :: a. In other words, undefined is a value that inhabits all types. Of course it’s impossible to actually write a pure function that can have any value of any type, given no inputs, and indeed, if you try to use an undefined value you’ll get a runtime error:
| | λ undefined |
| | *** Exception: Prelude.undefined |
| | CallStack (from HasCallStack): |
| | error, called at libraries/base/GHC/Err.hs:80:14 ... |