]> Git — Sourcephile - haskell/symantic.git/blob - symantic-grammar/Language/Symantic/Grammar/Error.hs
Support directories as targets in GNUmakefile.
[haskell/symantic.git] / symantic-grammar / Language / Symantic / Grammar / Error.hs
1 {-# LANGUAGE TypeApplications #-}
2 -- | Error handling utilities.
3 module Language.Symantic.Grammar.Error where
4
5 import Data.Proxy (Proxy(..))
6
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
11
12 -- * Class 'Inj_Error'
13 class Inj_Error a b where
14 inj_Error :: a -> b
15 instance Inj_Error err e => Inj_Error err (Either e a) where
16 inj_Error = Left . inj_Error
17
18 lift_Error ::
19 forall e0 err e1 a.
20 Inj_Error e0 e1 =>
21 Inj_Error e1 err =>
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