1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE ScopedTypeVariables #-}
5 {-# LANGUAGE TypeOperators #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
8 module Expr.Applicative.Test where
11 import Test.Tasty.HUnit
13 import Control.Arrow (left)
14 import Data.Proxy (Proxy(..))
15 import Data.Text (Text)
16 import Data.Type.Equality ((:~:)(Refl))
17 import Prelude hiding ((&&), not, (||), (==), (<$>), (+), Applicative(..))
19 import Language.Symantic.Type
20 import Language.Symantic.Expr as Expr
21 import Language.Symantic.Repr
28 e1 = val (\x -> val $ \y -> x + y)
33 type Ex lam = Expr_Root
40 .|. Expr_Applicative lam
42 ex_from = root_expr_from (Proxy::Proxy (Ex lam)) (Proxy::Proxy lam)
47 Left err -> Left err @?= snd `left` expected
48 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
50 Left (_, err) -> Right ("…"::String) @?= Left err
51 Right (ty_expected::Type_Root_of_Expr (Ex IO) h, _::h, _::Text) ->
52 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
53 case ty `eq_type` ty_expected of
54 Nothing -> return $ Left $
55 error_expr (Proxy::Proxy (Ex IO)) $
56 Error_Expr_Type_mismatch ast
58 (Exists_Type ty_expected)
66 -- , (text_from_expr :: Repr_String IO h -> Text) r
70 tests = testGroup "Applicative"
74 [ AST "x" [], AST "Int" []
76 [ AST "y" [], AST "Int" []
77 , AST "+" [ AST "var" [AST "x" []]
78 , AST "var" [AST "y" []] ]
81 , AST "just" [ AST "int" [AST "1" []] ]
83 , AST "just" [ AST "int" [AST "2" []] ]
87 , "fmap (\\x0 -> (\\x1 -> x0 + x1)) (just 1) <*> just 2" )