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
25 -- * Class 'Sym_Bool_Vars'
27 -- | A few boolean variables.
28 class Sym_Bool_Vars repr where
32 instance Sym_Bool_Vars (Repr_String fun) where
33 x = Repr_String $ \_p _v -> "x"
34 y = Repr_String $ \_p _v -> "y"
35 z = Repr_String $ \_p _v -> "z"
36 instance -- Trans_Boo_Const
39 ) => Sym_Bool_Vars (Trans_Bool_Const repr) where
45 e1 = bool True `and` bool False
46 e2 = (bool True `and` bool False) `or` (bool True `and` bool True)
47 e3 = (bool True `or` bool False) `and` (bool True `or` bool True)
48 e4 = bool True `and` not (bool False)
49 e5 = bool True `and` not x
51 e7 = (x `xor` y) `xor` z
52 e8 = x `xor` (y `xor` bool True)
58 ( Eq h, Eq ast, Show h, Show ast
59 , root ~ Expr_Lambda_Bool IO
60 , Expr_from ast (Expr_Lambda IO root)
61 , Expr_from ast (Expr_Bool root)
63 -- -> (Type_Fun_Bool IO h, h, String)
64 -> Either (Proxy h, Error_of_Expr ast root)
65 (Type_Fun_Bool IO h, h, String)
70 case expr_lambda_bool_from (Proxy::Proxy IO) ast of
71 Left err -> Left err @?= snd `left` expected
72 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
74 Left (_, err) -> Right ("…"::String) @?= Left err
75 Right (ty_expected::Type_Fun_Bool IO h, _::h, _::String) ->
76 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
77 case ty `type_eq` ty_expected of
78 Nothing -> return $ Left $
79 error_expr (Proxy::Proxy (Expr_Lambda_Bool IO)) $
80 Error_Expr_Type_mismatch ast
82 (Exists_Type ty_expected)
90 -- , (string_from_expr :: Repr_String IO h -> String) r
94 tests = testGroup "Bool" $
95 [ AST "bool" [AST "True" []] ==> Right
99 , AST "int" [AST "1" []] ==> Left (Proxy::Proxy Int,
100 Error_Expr_Alt_Curr $
101 Error_Expr_Unsupported $ AST "int" [AST "1" []])
103 [ AST "bool" [AST "True" []]
104 , AST "bool" [AST "True" []]
108 , "(True | True) & !(True & True)" )
113 , AST "var" [AST "x" []]
115 , AST "bool" [AST "True" []]
119 , "(\\x0 -> x0) True" )
120 , let ast = AST "app"
121 [ AST "bool" [AST "True" []]
122 , AST "bool" [AST "True" []]
123 ] in ast ==> Left (Proxy::Proxy Bool,
124 Error_Expr_Alt_Curr $
125 Error_Expr_Type_mismatch ast
126 (Exists_Type (type_var SZero `type_fun` type_var (SSucc SZero)
127 ::Type_Fun_Bool IO (IO Zero -> IO (Succ Zero))))
128 (Exists_Type type_bool))
134 [ AST "var" [AST "x" []]
135 , AST "bool" [AST "True" []]
138 , AST "bool" [AST "True" []]
142 , "(\\x0 -> (x0 | True) & !(x0 & True)) True" )
145 , AST "bool" [AST "True" []]
147 [ AST "var" [AST "x" []]
148 , AST "bool" [AST "True" []]
153 , "let x0 = True in (x0 | True) & !(x0 & True)" )