Skip to content

Proposal for throwLeft and throwLeftIO in Control.Exception

There already exist some functions to translate between Maybe and Exception, and between Either and Exception in the module Control.Exception.

Given an API like:

data MyException --...
instance Exception MyException --...
myUsefulFunction :: a -> b -> c -> Either MyException d
myUsefulAction :: a -> b -> c -> IO (Either MyException d)

It sometimes the case that calling code that cannot sensibly handle Left results directly.

This proposal is to add standard library functions that let calling code easily to turn Left results into thrown runtime exceptions, which might be caught and handled further up the call stack.

throwLeft :: Exception e => Either e a -> a
throwLeftIO :: Exception e => Either e a -> IO a

Note that examples of functions named throwLeft may be found in the wild: https://www.stackage.org/lts-7.10/hoogle?q=throwLeft.

Trac metadata
Trac field Value
Version 8.0.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC simonmar
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information