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.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_Int_Vars'
27 -- | A few boolean variables.
28 class Sym_Int_Vars repr where
32 instance Sym_Int_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"
38 e1 = int 1 `add` int 0
39 e2 = (int 1 `add` int 0) `add` neg (int 1 `add` int 1)
40 e3 = (int 1 `add` neg (int 0)) `add` (int 1 `add` neg (int 1))
41 e4 = int 0 `add` neg (int 1)
42 e5 = int 1 `add` neg x
44 e7 = (x `add` y) `add` z
45 e8 = x `add` (y `add` int 1)
50 case expr_lambda_int_from (Proxy::Proxy IO) ast of
51 Left err -> Left err @?= snd `left` expected
52 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
54 Left (_, err) -> Right ("…"::String) @?= Left err
55 Right (ty_expected::Type_Fun_Int IO h, _::h, _::String) ->
56 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
57 case ty `type_eq` ty_expected of
58 Nothing -> return $ Left $
59 error_expr (Proxy::Proxy (Expr_Lambda_Int IO)) $
60 Error_Expr_Type_mismatch ast
62 (Exists_Type ty_expected)
70 -- , (string_from_expr :: Repr_String IO h -> String) r
74 tests = testGroup "Int" $
75 [ AST "int" [AST "1" []] ==> Right
79 , AST "bool" [AST "True" []] ==> Left (Proxy::Proxy Bool,
81 Error_Expr_Unsupported $ AST "bool" [AST "True" []])
83 [ AST "int" [AST "1" []]
84 , AST "int" [AST "1" []]
90 [ AST "int" [AST "1" []]
91 , AST "int" [AST "1" []]
92 ] in ast ==> Left (Proxy::Proxy Int,
94 Error_Expr_Type_mismatch ast
95 (Exists_Type (type_var SZero `type_fun` type_var (SSucc SZero)
96 ::Type_Fun_Int IO (IO Zero -> IO (Succ Zero))))
97 (Exists_Type type_int))
102 , AST "var" [AST "x" []]
104 , AST "int" [AST "1" []]
114 [ AST "var" [AST "x" []]
115 , AST "int" [AST "1" []]
118 , AST "int" [AST "1" []]
122 , "(\\x0 -> x0 + 1) 1" )
125 , AST "int" [AST "1" []]
127 [ AST "var" [AST "x" []]
128 , AST "int" [AST "1" []]
133 , "let x0 = 1 in x0 + 1" )