{-# LANGUAGE DeriveDataTypeable #-}
module Internal.Error
( failure
, violation
, impossible
, unimplemented
) where
import Control.Exception
import Data.Typeable
data Violation = Violation String String deriving ( Typeable )
data Failure = Failure String String deriving ( Typeable )
instance Show Failure where
show (Failure f m) = f ++ ":" ++ m
instance Show Violation where
show (Violation f m) = "Bug in " ++ f ++ ", please report: " ++ m
instance Exception Violation
instance Exception Failure
failure :: String
-> String
-> a
failure f msg = throw $ Failure f msg
violation :: String
-> String
-> a
violation f msg = throw $ Violation f msg
impossible :: String
-> a
impossible f = violation f "The impossible happened."
unimplemented :: String
-> a
unimplemented f = failure f "Unimplemented."