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.
48 ( Eq h, Eq raw, Show h, Show raw
49 , Expr_from raw (Expr_Lambda IO (Expr_Lambda_Int IO))
50 , Expr_from raw (Expr_Int (Expr_Lambda_Int IO)))
51 => raw -> (Type_Fun_Int IO h, h, String) -> TestTree
52 (==>) raw expected@(ty_expected::Type_Fun_Int IO h, _::h, _::String) =
54 (>>= (@?= Right expected)) $
55 case expr_lambda_int_from (Proxy::Proxy IO) raw of
56 Left err -> return $ Left err
57 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
58 case ty `type_eq` ty_expected of
59 Nothing -> return $ Left $ Nothing -- Just $ "Type mismatch"
67 -- , (string_from_expr :: Repr_String IO h -> String) r
71 tests = testGroup "Int" $
72 [ AST "int" [AST "1" []] ==>
77 [ AST "int" [AST "1" []]
78 , AST "int" [AST "1" []]
87 , AST "var" [AST "x" []]
89 , AST "int" [AST "1" []]
99 [ AST "var" [AST "x" []]
100 , AST "int" [AST "1" []]
103 , AST "int" [AST "1" []]
107 , "(\\x0 -> x0 + 1) 1" )