Last active
August 29, 2015 14:01
-
-
Save passy/41d4abf1dcb97e302ddb to your computer and use it in GitHub Desktop.
oh dear
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
{-# LANGUAGE DataKinds #-} | |
data ErrorCatA = WTFError String | OMGError String | |
data ErrorCatB = BadError Int | TerribleError Float | |
data GenericError = CatA ErrorCatA | CatB ErrorCatB | |
class GError a where | |
wrap :: a -> GenericError | |
instance GError ErrorCatA where | |
wrap = CatA | |
instance GError ErrorCatB where | |
wrap = CatB | |
handleError :: GenericError -> IO () | |
handleError err = | |
putStrLn $ case err of | |
CatA (WTFError s) -> "WTF?! " ++ s | |
CatA (OMGError s) -> "OMG?! " ++ s | |
CatB (BadError i) -> "Bad! " ++ show i | |
CatB (TerribleError f) -> "Terrible! " ++ show f | |
main :: IO () | |
main = do | |
let err0 = CatA $ WTFError "Sky's falling." | |
let err1 = CatB $ TerribleError 1.337 | |
handleError err0 | |
handleError err1 | |
handleError $ wrap $ WTFError "Yo" | |
handleError $ wrap $ OMGError "this can't be right ..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment