1 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
5 -- | Transformer propagating boolean constants.
6 module Language.Symantic.Trans.Bool.Const where
8 import qualified Data.Bool as Bool
9 import Prelude hiding (and, not, or)
11 import Language.Symantic.Trans.Common
12 import Language.Symantic.Expr.Bool
14 -- * Type 'Trans_Bool_Const'
17 data Trans_Bool_Const repr h where
18 Trans_Bool_Const_Unknown :: repr h -> Trans_Bool_Const repr h
19 Trans_Bool_Const_Known :: Bool -> Trans_Bool_Const repr Bool
23 Trans Trans_Bool_Const repr where
24 trans_lift = Trans_Bool_Const_Unknown
25 trans_apply (Trans_Bool_Const_Unknown x) = x
26 trans_apply (Trans_Bool_Const_Known x) = bool x
30 Sym_Bool (Trans_Bool_Const repr) where
31 bool = Trans_Bool_Const_Known
33 not (Trans_Bool_Const_Unknown e) = Trans_Bool_Const_Unknown $ not e
34 not (Trans_Bool_Const_Known x) = Trans_Bool_Const_Known $ Bool.not x
36 and (Trans_Bool_Const_Known True) y = y
37 and (Trans_Bool_Const_Known False) _y = Trans_Bool_Const_Known False
38 and x (Trans_Bool_Const_Known True) = x
39 and _x (Trans_Bool_Const_Known False) = Trans_Bool_Const_Known False
40 and (Trans_Bool_Const_Unknown x)
41 (Trans_Bool_Const_Unknown y)
42 = Trans_Bool_Const_Unknown $ and x y
44 or (Trans_Bool_Const_Known False) y = y
45 or (Trans_Bool_Const_Known True) _y = Trans_Bool_Const_Known True
46 or x (Trans_Bool_Const_Known False) = x
47 or _x (Trans_Bool_Const_Known True) = Trans_Bool_Const_Known True
48 or (Trans_Bool_Const_Unknown x)
49 (Trans_Bool_Const_Unknown y)
50 = Trans_Bool_Const_Unknown $ or x y
55 => (Trans_Bool_Const repr) h -> repr h
56 trans_bool_const = trans_apply