3 ms·
Exceptions in Haskell simply are not the same as in other languages. In particular, they probably should only ever occur in IO code. Why? Because right now you
by tel 12y ago
Exceptions in Haskell simply are not the same as in other languages. In particular, they probably should only ever occur in IO code.
Why? Because right now you spend a lot of time trying to reason about non-local jumps in code due to exceptions. Purr Haskell code frees you from that concern by making everything local and explicit.
You have to learn a new style, but once you do going back to pervasive exceptions is a pain! It's really hard to trust code that might bubble up an exception at any point.
Finally, I've found that the times I genuinely want bubbling exceptions are exclusively IO scenarios anyway. Touching the real world is when you're likely to need to handle partial coverage of behavior amyay.
So it all matches up and is wonderful, but is also quite different from what you might normally expect. In particular, you need to learn how to think about and reason within pure code—once you learn that you'll find that predicting the right type signatures is easy. They just explain exactly what your function really does.
---
Here's a great /r/Haskell thread on the topic of modern error handling style: http://www.reddit.com/r/haskell/comments/2csaml/are_there_any_new_developments_in_the_last_seven/ http://www.reddit.com/r/haskell/comments/2csaml/are_there_an...