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, not, or)
18 import Language.LOL.Symantic.Repr
19 import Language.LOL.Symantic.AST
20 import Language.LOL.Symantic.Expr
21 import Language.LOL.Symantic.Type
22 -- import Language.LOL.Symantic.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` not (bool False)
50 e5 = bool True `and` not x
52 e7 = (x `xor` y) `xor` z
53 e8 = x `xor` (y `xor` bool True)
55 (==>) :: forall h raw.
56 ( Eq h, Eq raw, Show h, Show raw
57 , Sym_from raw (Expr_Lambda IO (Expr_Lambda_Bool IO))
58 , Sym_from raw (Expr_Bool (Expr_Lambda_Bool IO)))
59 => raw -> (Type_Fun_Bool IO h, h, String) -> TestTree
60 (==>) raw expected@(ty_expected::Type_Fun_Bool IO h, _::h, _::String) =
62 (>>= (@?= Right expected)) $
63 case expr_lambda_bool_from (Proxy::Proxy IO) raw of
64 Left err -> return $ Left err
65 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
66 case ty `type_eq` ty_expected of
67 Nothing -> return $ Left $ Nothing -- Just $ "Type mismatch"
75 -- , (string_repr :: Repr_String IO h -> String) r
79 tests = testGroup "Bool" $
80 [ AST "bool" [AST "True" []] ==>
85 [ AST "bool" [AST "True" []]
86 , AST "bool" [AST "True" []]
90 , "(True | True) & !(True & True)" )
95 , AST "var" [AST "x" []]
97 , AST "bool" [AST "True" []]
101 , "(\\x0 -> x0) True" )
107 [ AST "var" [AST "x" []]
108 , AST "bool" [AST "True" []]
111 , AST "bool" [AST "True" []]
115 , "(\\x0 -> (x0 | True) & !(x0 & True)) True" )