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 Control.Arrow (left)
13 -- import Data.Functor.Identity (Identity)
14 -- import Control.Monad.IO.Class (MonadIO(..))
15 import Data.Proxy (Proxy(..))
16 import Data.Type.Equality ((:~:)(Refl))
17 import Prelude hiding (and, not, or)
19 import Language.LOL.Symantic.Repr
20 import Language.LOL.Symantic.AST
21 import Language.LOL.Symantic.Expr
22 import Language.LOL.Symantic.Type
23 import Language.LOL.Symantic.Trans
24 import Language.LOL.Symantic.Lib.Data.Peano
26 -- * Class 'Sym_Bool_Vars'
28 -- | A few boolean variables.
29 class Sym_Bool_Vars repr where
33 instance Sym_Bool_Vars (Repr_String fun) where
34 x = Repr_String $ \_p _v -> "x"
35 y = Repr_String $ \_p _v -> "y"
36 z = Repr_String $ \_p _v -> "z"
37 instance -- Trans_Boo_Const
40 ) => Sym_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)
59 ( Eq h, Eq ast, Show h, Show ast
60 , root ~ Expr_Lambda_Bool IO
61 , Expr_from ast (Expr_Lambda IO root)
62 , Expr_from ast (Expr_Bool root)
64 -- -> (Type_Fun_Bool IO h, h, String)
65 -> Either (Proxy h, Error_of_Expr ast root)
66 (Type_Fun_Bool IO h, h, String)
71 case expr_lambda_bool_from (Proxy::Proxy IO) ast of
72 Left err -> Left err @?= snd `left` expected
73 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
75 Left (_, err) -> Right ("…"::String) @?= Left err
76 Right (ty_expected::Type_Fun_Bool IO h, _::h, _::String) ->
77 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
78 case ty `type_eq` ty_expected of
79 Nothing -> return $ Left $
80 error_expr (Proxy::Proxy (Expr_Lambda_Bool IO)) $
81 Error_Expr_Type_mismatch ast
83 (Exists_Type ty_expected)
91 -- , (string_from_expr :: Repr_String IO h -> String) r
95 tests = testGroup "Bool" $
96 [ AST "bool" [AST "True" []] ==> Right
100 , AST "int" [AST "1" []] ==> Left (Proxy::Proxy Int,
101 Error_Expr_Alt_Curr $
102 Error_Expr_Unsupported $ AST "int" [AST "1" []])
104 [ AST "bool" [AST "True" []]
105 , AST "bool" [AST "True" []]
109 , "(True | True) & !(True & True)" )
114 , AST "var" [AST "x" []]
116 , AST "bool" [AST "True" []]
120 , "(\\x0 -> x0) True" )
121 , let ast = AST "app"
122 [ AST "bool" [AST "True" []]
123 , AST "bool" [AST "True" []]
124 ] in ast ==> Left (Proxy::Proxy Bool,
125 Error_Expr_Alt_Curr $
126 Error_Expr_Type_mismatch ast
127 (Exists_Type (type_var SZero `type_fun` type_var (SSucc SZero)
128 ::Type_Fun_Bool IO (IO Zero -> IO (Succ Zero))))
129 (Exists_Type type_bool))
135 [ AST "var" [AST "x" []]
136 , AST "bool" [AST "True" []]
139 , AST "bool" [AST "True" []]
143 , "(\\x0 -> (x0 | True) & !(x0 & True)) True" )
146 , AST "bool" [AST "True" []]
148 [ AST "var" [AST "x" []]
149 , AST "bool" [AST "True" []]
154 , "let x0 = True in (x0 | True) & !(x0 & True)" )