Open Martinsos opened 3 years ago
Thanks for sharing, I find especially interesting the one about exceptions since I still I need to understand that part better!
What are your thoughts about recommendation from https://www.fpcomplete.com/haskell/tutorial/exceptions/ to use UnliftIO.Exception instead of Control.Exception?
I believe fpco understand exceptions better than me. I've tried covering the basics that are available in base and focus on IO
.
It is also likely that understanding the regular Control.Exception
will make using UnliftIO.Exception
easier anyway, because they have very similar APIs and concepts.
What is also somewhat confusing is when to use Either vs throwing an IO exception. Interesting discussion here: https://www.reddit.com/r/haskell/comments/z5ezoa/why_network_requests_throw_exceptions_instead_of/ .
The summary is somewaht in direction of: use Either when you want consumer of function to be very aware of what you are returning and explicitly handle it, vs use IO exception when you want to be more implicit and just let him handle those exceptions only if they really want to. But I don't think this is final explanation, I think there is more to it, this was just what I quickly got from it.
As a general approach when following the 'functional core, imperative shell' pattern, I usually use Either/Except in the functional core, and exceptions in the imperative shell.
lhbg-book.link has a few chapters on Either, ExceptT, and exceptions.