You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are a lot of things we could talk about on this topic.
Just as a jumping-off point, here's some code that is more or less a direct translation from Go By Example:
importData.Foldable (for_)
dataError=Error{arg::Int
, problem::String}derivingShow
f arg =case arg of42->Left (Error arg "Can't work with it")
x ->Right (x +3)
t1 =do
x <- f 7
y <- f 8
z <- f 9return (x, y, z)
t2 =do
x <- f 41
y <- f 42
z <- f 43return (x, y, z)
main =do
for_ [7, 42] $\i ->case (f i) ofLeft e ->putStrLn ("f failed: "++show e)
Right r ->putStrLn ("f worked: "++show r)
putStrLn (show t1)
putStrLn (show t2)
$ runhaskell errors.hs
f worked: 10
f failed: Error {arg = 42, problem = "Can't work with it"}
Right (10,11,12)
Left (Error {arg = 42, problem = "Can't work with it"})
I don't think a demonstrating involving ExceptT Error IO would be out of line either.
The text was updated successfully, but these errors were encountered:
There are a lot of things we could talk about on this topic.
Just as a jumping-off point, here's some code that is more or less a direct translation from Go By Example:
I don't think a demonstrating involving
ExceptT Error IO
would be out of line either.The text was updated successfully, but these errors were encountered: