{-# LANGUAGE TypeApplications #-}
--- | Error handling utilities.
module Language.Symantic.Grammar.Error where
-import Data.Proxy (Proxy(..))
+import Data.Proxy (Proxy)
--- * Class 'Gram_Error'
--- | Symantics for handling errors at the semantic level (not the syntaxic one).
-class Gram_Error err g where
- catch :: g (Either err a) -> g a
+-- * Class 'ErrorInj'
+class ErrorInj a b where
+ errorInj :: a -> b
+instance ErrorInj err e => ErrorInj err (Either e a) where
+ errorInj = Left . errorInj
--- * Class 'Inj_Error'
-class Inj_Error a b where
- inj_Error :: a -> b
-instance Inj_Error err e => Inj_Error err (Either e a) where
- inj_Error = Left . inj_Error
-
-lift_Error ::
+liftError ::
forall e0 err e1 a.
- Inj_Error e0 e1 =>
- Inj_Error e1 err =>
+ ErrorInj e0 e1 =>
+ ErrorInj e1 err =>
Proxy e1 -> Either e0 a -> Either err a
-lift_Error _e1 (Right a) = Right a
-lift_Error _e1 (Left e) = Left $ inj_Error @e1 @err $ inj_Error @e0 @e1 e
+liftError _e1 (Right a) = Right a
+liftError _e1 (Left e) = Left $ errorInj @e1 @err $ errorInj @e0 @e1 e