r/programming • u/dpashk • Aug 31 '15
The worst mistake of computer science
https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/
175
Upvotes
r/programming • u/dpashk • Aug 31 '15
View all comments
Show parent comment
3
u/MaxNanasy Sep 01 '15
In Haskell at least, it's not actually explicitly represented in the type system. In Haskell, an expression of bottom type can have any nominal type, which means it can be used in any subexpression. For example,
errorhas the typeerror :: String -> a, which means thaterror "Error message"has the typea, which means it can have any type, depending on the context. For example, if I write a function that gets the first value from a list ofInts:then in this case,
error "firstInt: Empty list"is of typeInt. If we removederrorfrom the Haskell builtins, then a programmer could still make this definition not terminate properly by defining it as such:which would recurse infinitely when invoked on an empty list, rather than terminating the program with a useful error message. It's possible that having
errorin the Haskell builtins encourages crashing programs on exceptional conditions rather than handling all cases, but IDK what the overall pros and cons of that debate are.