$30 off During Our Annual Pro Sale. View Details »

Either Error Success

Either Error Success

Tim McGilchrist

May 24, 2018
Tweet

More Decks by Tim McGilchrist

Other Decks in Programming

Transcript

  1. View Slide

  2. Either Error Success
    FP-SYD 2018

    View Slide

  3. 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

    View Slide

  4. –Mark H
    “I have people sitting around solutionizing”

    View Slide

  5. Examples
    • Code

    View Slide

  6. –Nick H
    “I will admit human error played a large part”

    View Slide

  7. 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

    View Slide

  8. Exception Pattern
    • Code

    View Slide

  9. Exception Pattern
    • type signature doesn’t indicate errors

    • exceptions compose without effort

    • no stack traces by default

    • dealing with exceptions properly is hard

    View Slide

  10. EitherT Pattern
    • Code

    View Slide

  11. 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

    View Slide

  12. Transformers Either
    • Code

    View Slide

  13. Either Examples
    • mismi - wrapper around Amazonka

    • mafia - cabal build tool

    • boris - continuous integration / builds

    View Slide

  14. Exception Examples
    • http-client - http library

    • stack - Haskell build tool ++

    • hs-tls - Native Haskell TLS / SSL implementation

    View Slide

  15. Conclusion
    • make error behaviour explicit

    • use appropriate tool for the
    job

    • EitherT yields more
    maintainable code

    • similar or less effort to
    exceptions

    View Slide

  16. 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

    View Slide