1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE NoMonomorphismRestriction #-}
3 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
4 module Compiling.Bool.Test where
8 import Data.Proxy (Proxy(..))
9 import Prelude hiding ((&&), not, (||))
11 import Language.Symantic.Typing
12 import Language.Symantic.Compiling
13 import Language.Symantic.Interpreting
14 import Compiling.Term.Test
16 -- * Class 'Sym_Bool_Vars'
18 -- | A few boolean variables.
19 class Sym_Bool_Vars repr where
23 instance Sym_Bool_Vars TextI where
24 x = TextI $ \_p _v -> "x"
25 y = TextI $ \_p _v -> "y"
26 z = TextI $ \_p _v -> "z"
28 instance -- Trans_Boo_Const
31 ) => Sym_Bool_Vars (Trans_Bool_Const repr) where
38 te1 = bool True && bool False
39 te2 = (bool True && bool False) || (bool True && bool True)
40 te3 = (bool True || bool False) && (bool True || bool True)
41 te4 = bool True && not (bool False)
42 te5 = bool True && not x
44 te7 = (x `xor` y) `xor` z
45 te8 = x `xor` (y `xor` bool True)
52 (==>) = test_term_from (Proxy::Proxy Ifaces)
55 tests = testGroup "Bool" $
56 [ syTrue ==> Right (tyBool, True, "True")
57 , Syntax "xor" [syTrue, syTrue] ==> Right
58 (tyBool, False, "((\\x0 -> (\\x1 -> x0 `xor` x1)) True) True")
60 (syLam (Syntax "x" []) syBool
63 (tyBool, True, "(\\x0 -> x0) True")
65 (syLam (Syntax "x" []) syBool
71 (tyBool, False, "(\\x0 -> ((\\x1 -> (\\x2 -> x1 `xor` x2)) x0) True) True" )
72 , syLet (Syntax "x" []) syTrue
77 (tyBool, False, "let x0 = True in ((\\x1 -> (\\x2 -> x1 `xor` x2)) x0) True")
78 , testGroup "Error_Term" $
79 [ syApp syTrue syTrue ==> Left (tyBool,
80 Error_Term_Type_is_not_an_application $ At (Just syTrue) $
84 (Syntax "x" []) syBool
90 syBool ==> Left (tyBool,
91 Error_Term_unknown $ At (Just syBool) $
94 [ syLam (Syntax "x" []) syBool
96 ] in sy ==> Left (tyBool,
97 Error_Term_Syntax $ Error_Syntax_more_arguments_needed $
100 [ syLam (Syntax "x" []) syBool
104 ] in sy ==> Left (tyBool,
105 Error_Term_Type_is_not_an_application $
106 At (Just sy) $ EType tyBool)
108 syLam (Syntax "x" []) (syBool .> syBool)
109 (Syntax " " [Syntax "x" [], syTrue]) in
110 syApp sy syTrue ==> Left (tyBool,
111 Error_Term_Type_mismatch
112 (At (Just sy) $ EType $ (tyBool ~> tyBool))
113 (At (Just $ syTrue) $ EType tyBool)