3 ms·
The author includes a perfect (if unintentional) example of why Haskell programs shouldn't use `error`. (If you're writing a quick-and-dirty program? Fair enoug
by mooism2 13y ago
The author includes a perfect (if unintentional) example of why Haskell programs shouldn't use `error`. (If you're writing a quick-and-dirty program? Fair enough. But not in larger programs.)
He defines a `Lattice` class, and explains that if a type implements the `Lattice` class, it supports all the operations within the `Lattice` class.
He then presents an implementation of the `Lattice` class that doesn't support all the `Lattice` operations (`top` punts to `error`). It breaks the promise, breaks the contract, undermines the guarantees the type system gives you.
So don't use `error` in Haskell. (And for that matter, don't use other partial functions such as `head` and `tail`.)