|
|
|
|
|
by dllthomas
3571 days ago
|
|
The bits about exceptions and IO isn't quite right. So far as I'm aware, there is no technical difference between exceptions thrown in IO versus exceptions thrown in pure code. There are two contextual differences. First, exceptions can only be caught in IO, but everything running has IO above it somewhere, or it wouldn't be running in the first place. Regarding exceptions thrown in IO versus elsewhere, it's worth noting that exceptions thrown anywhere are only actually thrown if the thunk representing them is forced. IO values tend to be used quite close to where they are created, whereas an exception in lazy, pure code might hide in the creation of the leaf of a tree or at the end of a list. |
|
The biggest challenge is definitely how easily exceptions can slip by handling code unless you make strict use of throwIO with synchronous exceptions (or something equivalent like throwM from exceptions). My favorite example is the following:
let foo = try . return $ error "foo".
Which evaluates to "Right * Exception: foo".