1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeOperators #-}
7 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
8 module Expr.Bool.Test where
11 import Test.Tasty.HUnit
13 import Control.Arrow (left)
14 -- import Data.Functor.Identity (Identity)
15 -- import Control.Monad.IO.Class (MonadIO(..))
16 import Data.Proxy (Proxy(..))
17 import Data.Text (Text)
18 import Data.Type.Equality ((:~:)(Refl))
19 import Prelude hiding ((&&), not, (||))
21 import Language.Symantic.Repr
22 import Language.Symantic.Expr
23 import Language.Symantic.Type
24 import Language.Symantic.Trans
28 -- * Class 'Sym_Bool_Vars'
30 -- | A few boolean variables.
31 class Sym_Bool_Vars repr where
35 instance Sym_Bool_Vars (Repr_Text fun) where
36 x = Repr_Text $ \_p _v -> "x"
37 y = Repr_Text $ \_p _v -> "y"
38 z = Repr_Text $ \_p _v -> "z"
39 instance -- Trans_Boo_Const
42 ) => Sym_Bool_Vars (Trans_Bool_Const repr) where
48 e1 = bool True && bool False
49 e2 = (bool True && bool False) || (bool True && bool True)
50 e3 = (bool True || bool False) && (bool True || bool True)
51 e4 = bool True && not (bool False)
52 e5 = bool True && not x
54 e7 = (x `xor` y) `xor` z
55 e8 = x `xor` (y `xor` bool True)
58 type Ex lam = Expr_Root (Expr_Lambda lam .|. Expr_Bool)
59 ex_from = root_expr_from (Proxy::Proxy (Ex lam)) (Proxy::Proxy lam)
64 Left err -> Left err @?= snd `left` expected
65 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
67 Left (_, err) -> Right ("…"::String) @?= Left err
68 Right (ty_expected::Type_Root_of_Expr (Ex IO) h, _::h, _::Text) ->
69 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
70 case ty `eq_type` ty_expected of
71 Nothing -> return $ Left $
72 error_expr (Proxy::Proxy (Ex IO)) $
73 Error_Expr_Type_mismatch ast
75 (Exists_Type ty_expected)
83 -- , (text_from_expr :: Repr_Text IO h -> String) r
87 tests = testGroup "Bool" $
88 [ AST "bool" [AST "True" []] ==> Right
92 , AST "int" [AST "1" []] ==> Left (Proxy::Proxy Int,
94 Error_Expr_Unsupported $ AST "int" [AST "1" []])
96 [ AST "bool" [AST "True" []]
97 , AST "bool" [AST "True" []]
106 , AST "var" [AST "x" []]
108 , AST "bool" [AST "True" []]
112 , "(\\x0 -> x0) True" )
113 , let ast = AST "app"
114 [ AST "bool" [AST "True" []]
115 , AST "bool" [AST "True" []]
116 ] in ast ==> Left (Proxy::Proxy Bool,
117 Error_Expr_Alt_Curr $
118 Error_Expr_Type_mismatch ast
119 (Exists_Type (type_var SZero `type_fun` type_var (SSucc SZero)
120 ::Type_Root (Type_Var :|: Type_Fun IO :|: Type_Bool)
121 (Lambda IO Zero (Succ Zero))))
122 (Exists_Type type_bool))
128 [ AST "var" [AST "x" []]
129 , AST "bool" [AST "True" []]
132 , AST "bool" [AST "True" []]
136 , "(\\x0 -> xor x0 True) True" )
139 , AST "bool" [AST "True" []]
141 [ AST "var" [AST "x" []]
142 , AST "bool" [AST "True" []]
147 , "let x0 = True in xor x0 True" )