1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
7 module Expr.Int.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.Text (Text)
17 import Data.Type.Equality ((:~:)(Refl))
18 import Prelude hiding (and, not, or)
20 import Language.Symantic.Repr
21 import Language.Symantic.Expr
22 import Language.Symantic.Type
23 -- import Language.Symantic.Trans
27 -- * Class 'Sym_Int_Vars'
29 -- | A few boolean variables.
30 class Sym_Int_Vars repr where
34 instance Sym_Int_Vars (Repr_Text fun) where
35 x = Repr_Text $ \_p _v -> "x"
36 y = Repr_Text $ \_p _v -> "y"
37 z = Repr_Text $ \_p _v -> "z"
40 e1 = int 1 `add` int 0
41 e2 = (int 1 `add` int 0) `add` neg (int 1 `add` int 1)
42 e3 = (int 1 `add` neg (int 0)) `add` (int 1 `add` neg (int 1))
43 e4 = int 0 `add` neg (int 1)
44 e5 = int 1 `add` neg x
46 e7 = (x `add` y) `add` z
47 e8 = x `add` (y `add` int 1)
52 case expr_lambda_int_from (Proxy::Proxy IO) ast of
53 Left err -> Left err @?= snd `left` expected
54 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
56 Left (_, err) -> Right ("…"::String) @?= Left err
57 Right (ty_expected::Type_Root_of_Expr (Expr_Lambda_Int IO) h, _::h, _::Text) ->
58 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
59 case ty `type_eq` ty_expected of
60 Nothing -> return $ Left $
61 error_expr (Proxy::Proxy (Expr_Lambda_Int IO)) $
62 Error_Expr_Type_mismatch ast
64 (Exists_Type ty_expected)
72 -- , (text_from_expr :: Repr_Text IO h -> String) r
76 tests = testGroup "Int" $
77 [ AST "int" [AST "1" []] ==> Right
81 , AST "bool" [AST "True" []] ==> Left (Proxy::Proxy Bool,
83 Error_Expr_Unsupported $ AST "bool" [AST "True" []])
85 [ AST "int" [AST "1" []]
86 , AST "int" [AST "1" []]
92 [ AST "int" [AST "1" []]
93 , AST "int" [AST "1" []]
94 ] in ast ==> Left (Proxy::Proxy Int,
96 Error_Expr_Type_mismatch ast
97 (Exists_Type (type_var SZero `type_fun` type_var (SSucc SZero)
98 ::Type_Fun_Int IO (IO Zero -> IO (Succ Zero))))
99 (Exists_Type type_int))
104 , AST "var" [AST "x" []]
106 , AST "int" [AST "1" []]
116 [ AST "var" [AST "x" []]
117 , AST "int" [AST "1" []]
120 , AST "int" [AST "1" []]
124 , "(\\x0 -> x0 + 1) 1" )
127 , AST "int" [AST "1" []]
129 [ AST "var" [AST "x" []]
130 , AST "int" [AST "1" []]
135 , "let x0 = 1 in x0 + 1" )