I\'m curious about the \'undefined\' value in Haskell. Its interesting because you can put it just about anywhere, and Haskell will be happy. The following are all a-ok
There's nothing really special about undefined
. It is just an exceptional value -- you could represent it with an infinite loop, or a crash, or a segfault. One way to write it is as a crash:
undefined :: a
undefined | False = undefined
Or a loop:
undefined = undefined
It is an exceptional value that can be an element of any type.
Since Haskell is lazy you can still use such values in computations. E.g.
> length [undefined, undefined]
2
But otherwise, it is just a natural consequence of polymorphism and non-strictness.