Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
Either Error Success
Tim McGilchrist
May 24, 2018
Programming
0
48
Either Error Success
Tim McGilchrist
May 24, 2018
Tweet
Share
More Decks by Tim McGilchrist
See All by Tim McGilchrist
lambda_foo
0
61
lambda_foo
1
36
lambda_foo
0
65
lambda_foo
3
540
Other Decks in Programming
See All in Programming
kazuhei0108
3
950
adarapata
1
460
atamaplus
2
450
imk2o
0
200
manfredsteyer
PRO
0
290
hkusu
0
280
emberconf
0
140
rukiadia
3
860
daipresents
1
170
shiba6v
0
200
kulkarniankita09
0
270
ykpythemind
0
140
Featured
See All Featured
marktimemedia
7
450
paulrobertlloyd
71
3.7k
swwweet
206
6.9k
malarkey
119
16k
lara
590
61k
notwaldorf
19
2.1k
iamctodd
22
2.2k
malarkey
392
61k
jeffersonlam
330
15k
addyosmani
495
110k
chriscoyier
498
130k
danielanewman
201
20k
Transcript
None
Either Error Success FP-SYD 2018
Introduction • who, what, why, where, how questions • who
-> Tim McGilchrist @lambda_foo • what -> exciting area of error handling • where -> in Haskell mostly • how -> with functions and data types
–Mark H “I have people sitting around solutionizing”
Examples • Code
–Nick H “I will admit human error played a large
part”
The Async Problem • Asynchronous exceptions are a feature of
Haskell • No fancy effect systems or modular IO effects • Deal with it! • Code in IO can fail at any point with an exception
Exception Pattern • Code
Exception Pattern • type signature doesn’t indicate errors • exceptions
compose without effort • no stack traces by default • dealing with exceptions properly is hard
EitherT Pattern • Code
EitherT Pattern • pattern matching has your back • composition
is explicit (you need to think) • application stack traces • constrained exception handling • extra work • interfacing with exception heavy code
Transformers Either • Code
Either Examples • mismi - wrapper around Amazonka • mafia
- cabal build tool • boris - continuous integration / builds
Exception Examples • http-client - http library • stack -
Haskell build tool ++ • hs-tls - Native Haskell TLS / SSL implementation
Conclusion • make error behaviour explicit • use appropriate tool
for the job • EitherT yields more maintainable code • similar or less effort to exceptions
Resources • https://simonmar.github.io/posts/2017-01-24- asynchronous-exceptions.html • https://haskell-lang.org/library/safe-exceptions • https://www.fpcomplete.com/blog/2016/11/exceptions- best-practices-haskell •
https://simonmar.github.io/bib/papers/async.pdf