1 {-# LANGUAGE TypeApplications #-}
2 -- | Error handling utilities.
3 module Language.Symantic.Grammar.Error where
5 import Data.Proxy (Proxy(..))
7 -- * Class 'Gram_Error'
8 -- | Symantics for handling errors at the semantic level (not the syntaxic one).
9 class Gram_Error err g where
10 catch :: g (Either err a) -> g a
12 -- * Class 'Inj_Error'
13 class Inj_Error a b where
15 instance Inj_Error err e => Inj_Error err (Either e a) where
16 inj_Error = Left . inj_Error
22 Proxy e1 -> Either e0 a -> Either err a
23 lift_Error _e1 (Right a) = Right a
24 lift_Error _e1 (Left e) = Left $ inj_Error @e1 @err $ inj_Error @e0 @e1 e