[email protected]
[Top] [All Lists]

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

Subject: [Haskell-cafe] How to use Control.Failure?
From: ntupel
Date: Sat, 19 Dec 2009 06:46:35 -0800 PST
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?

Thanks,
nt


-- 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
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>