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 Data.Functor.Identity (Identity)
13 -- import Control.Monad.IO.Class (MonadIO(..))
14 import Data.Proxy (Proxy(..))
15 import Data.Type.Equality ((:~:)(Refl))
16 import Prelude hiding (and, not, or)
18 import Language.LOL.Symantic.Repr
19 import Language.LOL.Symantic.AST
20 import Language.LOL.Symantic.Expr
21 import Language.LOL.Symantic.Type
22 -- import Language.LOL.Symantic.Trans
24 -- * Class 'Sym_Int_Vars'
26 -- | A few boolean variables.
27 class Sym_Int_Vars repr where
31 instance Sym_Int_Vars (Repr_String fun) where
32 x = Repr_String $ \_p _v -> "x"
33 y = Repr_String $ \_p _v -> "y"
34 z = Repr_String $ \_p _v -> "z"
37 e1 = int 1 `add` int 0
38 e2 = (int 1 `add` int 0) `add` neg (int 1 `add` int 1)
39 e3 = (int 1 `add` neg (int 0)) `add` (int 1 `add` neg (int 1))
40 e4 = int 0 `add` neg (int 1)
41 e5 = int 1 `add` neg x
43 e7 = (x `add` y) `add` z
44 e8 = x `add` (y `add` int 1)
47 (==>) :: forall h raw root.
48 ( Eq h, Eq raw, Show h, Show raw
49 , root ~ Expr_Lambda_Int IO
50 , Expr_from raw (Expr_Lambda IO root)
51 , Expr_from raw (Expr_Int root)
53 => raw -> (Type_Fun_Int IO h, h, String) -> TestTree
54 (==>) raw expected@(ty_expected::Type_Fun_Int IO h, _::h, _::String) =
56 (>>= (@?= Right expected)) $
57 case expr_lambda_int_from (Proxy::Proxy IO) raw of
58 Left err -> return $ Left err
59 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
60 case ty `type_eq` ty_expected of
61 Nothing -> return $ Left $
62 error_expr (Proxy::Proxy root) $ Error_Expr_Type
63 (error_type_lift $ Error_Type_Unsupported raw) raw
71 -- , (string_from_expr :: Repr_String IO h -> String) r
75 tests = testGroup "Int" $
76 [ AST "int" [AST "1" []] ==>
81 [ AST "int" [AST "1" []]
82 , AST "int" [AST "1" []]
91 , AST "var" [AST "x" []]
93 , AST "int" [AST "1" []]
103 [ AST "var" [AST "x" []]
104 , AST "int" [AST "1" []]
107 , AST "int" [AST "1" []]
111 , "(\\x0 -> x0 + 1) 1" )
114 , AST "int" [AST "1" []]
116 [ AST "var" [AST "x" []]
117 , AST "int" [AST "1" []]
122 , "let x0 = 1 in x0 + 1" )