Lightweight Checked Exceptions in Haskell
Posted on July 31, 2015Consider this function from the http-conduit library:
-- | Download the specified URL (..)
--
-- This function will 'throwIO' an 'HttpException' for (..)
simpleHttp :: MonadIO m => String -> m ByteString
Notice that part of the semantics of this function—that it may throw an HttpException
—is encoded in a comment, which the compiler cannot check. Wouldn’t it be much nicer if we could simply express in the type that simpleHttp
may throw a HttpException
? In this blog post I will propose a very lightweight scheme to do precisely that.