[Haskell-cafe] How to use Control.Failure?

ntupel ntupel at googlemail.com
Sat Dec 19 09:46:35 EST 2009

I have looked at the recently released Control.Failure library but I
admit, I couldn't understand it completely. So given the example
below, how would Control.Failure help me here?


-- Theirs (other library code stubs)
data TheirError = TheirErrorCase deriving Show
data TheirData  = TheirData deriving Show

theirFunc :: [String] -> Either TheirError TheirData
theirFunc = undefined

-- Mine (my own code stubs)
data MyError = MyErrorCase deriving Show
data MyData  = MyData deriving Show

myFuncA :: TheirData -> Either MyError MyData
myFuncA = undefined

-- Ugly. How to apply Control.Failure here?
myFuncB :: IO (Either MyError MyData)
myFuncB = do
    let x = theirFunc []
    case x of
        Right x' -> return $ myFuncA x'
        Left  _  -> return . Left $ MyErrorCase

More information about the Haskell-Cafe mailing list