Created
March 11, 2018 20:39
-
-
Save liarokapisv/71b833cb5606c778812598a74b2ee50e to your computer and use it in GitHub Desktop.
Error handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data A | |
data A' | |
data B | |
data B' | |
data C | |
data C' | |
data ExtraX | |
data ExtraY | |
data D = D A B C | |
data D' = D' A' B' C' ExtraX ExtraY | |
data AError | |
data BError | |
data CError | |
data ExtraXError | |
data ExtraYError | |
data DSubError = DSubError (Maybe AError) (Maybe BError) (Maybe CError) | |
instance Monoid DSubError | |
data DError = DError (Maybe DSubError) (Maybe ExtraXError) (Maybe ExtraYError) | |
instance Monoid DError | |
tA :: Monad m -> m (Either AError A') | |
tB :: Monad m -> m (Either BError B') | |
tC :: Monad m -> m (Either CError C') | |
getExtraX :: A' -> C' -> Either ExtraXError ExtraX | |
getExtraY :: A' -> B' -> Either ExtraYError ExtraY | |
tD :: Monad m -> m (Either DError D') | |
tD a b c = do | |
a <- tA a | |
b <- tB b | |
c <- tC c | |
x <- case (a, c) of | |
(Just a', Just c') -> Just $ getExtraX a' c' | |
_ -> Nothing | |
y <- case (a', b') of | |
(Just a', Just b') -> Just $ getExtraY a' b' | |
_ -> Nothing | |
case (a, b, c, x, y) of | |
(Just a', Just b', Just c', Just (Right x'), Just (Right y')) -> pure $ Right (D' a' b' c' x' y') | |
_ -> pure $ Left ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment