1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
7 module Expr.Bool.Test where
10 import Test.Tasty.HUnit
12 -- import Data.Functor.Identity (Identity)
13 -- import Control.Monad.IO.Class (MonadIO(..))
14 import Data.Proxy (Proxy(..))
15 import Data.Type.Equality ((:~:)(Refl))
16 import Prelude hiding (and, or)
22 -- import TFHOE.Expr.Trans
24 -- * Class 'Expr_Bool_Vars'
26 -- | A few boolean variables.
27 class Expr_Bool_Vars repr where
31 instance Expr_Bool_Vars (Repr_String fun) where
32 x = Repr_String $ \_p _v -> "x"
33 y = Repr_String $ \_p _v -> "y"
34 z = Repr_String $ \_p _v -> "z"
36 instance -- Trans_Boo_Const
39 ) => Expr_Bool_Vars (Trans_Bool_Const repr) where
46 e1 = bool True `and` bool False
47 e2 = (bool True `and` bool False) `or` (bool True `and` bool True)
48 e3 = (bool True `or` bool False) `and` (bool True `or` bool True)
49 e4 = bool True `and` neg (bool False)
50 e5 = bool True `and` neg x
52 e7 = (x `xor` y) `xor` z
53 e8 = x `xor` (y `xor` bool True)
55 (==>) raw expected@(ty_expected::Type_Fun_Bool_Int IO Type_End h, _::h, _::String) =
57 (>>= (@?= Right expected)) $
58 case expr_fun_bool_int_from Proxy Proxy raw of
59 Left err -> return $ Left err
60 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
61 case ty `type_eq` ty_expected of
62 Nothing -> return $ Left "Type mismatch"
70 -- , (string_repr :: Repr_String IO h -> String) r
74 tests = testGroup "Bool" $
75 [ Raw "bool" [Raw "True" []] ==>
76 ( Type_Fun_Next Type_Bool
80 [ Raw "bool" [Raw "True" []]
81 , Raw "bool" [Raw "True" []]
83 ( Type_Fun_Next Type_Bool
85 , "(True | True) & !(True & True)" )
90 , Raw "var" [Raw "x" []]
92 , Raw "bool" [Raw "True" []]
94 ( Type_Fun_Next Type_Bool
96 , "(\\x0 -> x0) True" )
102 [ Raw "var" [Raw "x" []]
103 , Raw "bool" [Raw "True" []]
106 , Raw "bool" [Raw "True" []]
108 ( Type_Fun_Next Type_Bool
110 , "(\\x0 -> (x0 | True) & !(x0 & True)) True" )
116 raw_ty_bool = Raw "Bool" []
120 Either Error_Type (Type_Fun_Bool_End repr Bool)
121 ty_bool = type_from raw_ty_bool $ \(ty::Type_Fun_Bool_End repr h) ->
123 Type_Fun_Next Type_Bool -> Right ty
127 raw_ty_bool2bool :: Raw
128 raw_ty_bool2bool = Raw "->" [Raw "Bool" [], Raw "Bool" []]
132 Either Error_Type (Type_Fun_Bool_End repr (repr Bool -> repr Bool))
133 ty0_bool2bool = type_from raw_ty_bool2bool $ \(ty::Type_Fun_Bool_End repr h) ->
136 (Type_Fun_Next Type_Bool)
137 (Type_Fun_Next Type_Bool) -> Right ty
147 [ Raw "var" [Raw "x" []]
148 , Raw "bool" [Raw "True" []]
153 :: forall repr. MonadIO repr =>
154 Either Error_Type (repr (Repr_Host repr Bool -> Repr_Host repr Bool))
156 expr_fun_bool_int_from
157 (Proxy::Proxy Type_End)
158 raw_xor_true $ \ty (repr::Repr_Host repr h) ->
161 (Type_Fun_Next Type_Bool)
162 (Type_Fun_Next Type_Bool) ->
163 Right $ meta_repr repr