1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE NoMonomorphismRestriction #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeOperators #-}
7 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
9 module Expr.Applicative.Test where
12 import Test.Tasty.HUnit
14 import qualified Control.Arrow as Arrow
15 import qualified Control.Monad as Monad
16 import Data.Proxy (Proxy(..))
17 import Data.Text (Text)
18 import Data.Type.Equality ((:~:)(Refl))
19 import Prelude hiding ((&&), not, (||), (==), (<$>), (+), Applicative(..))
21 import Language.Symantic.Type
22 import Language.Symantic.Expr as Expr
23 import Language.Symantic.Repr
30 e1 = lam (\x -> lam $ \y -> x + y)
45 ex_from = root_expr_from (Proxy::Proxy Ex)
50 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
51 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
53 Left (_, err) -> Right ("…"::String) @?= Left err
54 Right (ty_expected::Type_Root_of_Expr Ex h, _::h, _::Text) ->
55 (Monad.>>= (@?= (\(_::Proxy h, err) -> err) `Arrow.left` expected)) $
56 case ty `eq_type` ty_expected of
57 Nothing -> Monad.return $ Left $
58 error_expr (Proxy::Proxy Ex) $
59 Error_Expr_Type_mismatch ast
61 (Exists_Type ty_expected)
63 let h = host_from_expr r
69 -- , (text_from_expr :: Repr_Text h -> Text) r
73 tests = testGroup "Applicative"
77 [ AST "x" [], AST "Int" []
79 [ AST "y" [], AST "Int" []
80 , AST "+" [ AST "var" [AST "x" []]
81 , AST "var" [AST "y" []] ]
84 , AST "just" [ AST "int" [AST "1" []] ]
86 , AST "just" [ AST "int" [AST "2" []] ]
90 , "fmap (\\x0 -> (\\x1 -> x0 + x1)) (just 1) <*> just 2" )