1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE ScopedTypeVariables #-}
5 {-# LANGUAGE TypeOperators #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
8 module Expr.Functor.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, (||), (==), fmap, (+))
19 import Language.Symantic.Type
20 import Language.Symantic.Expr as Expr
21 import Language.Symantic.Repr
28 e1 = fmap (val $ \x -> x + int 1) (list $ int Prelude.<$> [1..3])
31 type Ex lam = Expr_Root
39 ex_from = root_expr_from (Proxy::Proxy (Ex lam)) (Proxy::Proxy lam)
44 Left err -> Left err @?= snd `left` expected
45 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
47 Left (_, err) -> Right ("…"::String) @?= Left err
48 Right (ty_expected::Type_Root_of_Expr (Ex IO) h, _::h, _::Text) ->
49 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
50 case ty `eq_type` ty_expected of
51 Nothing -> return $ Left $
52 error_expr (Proxy::Proxy (Ex IO)) $
53 Error_Expr_Type_mismatch ast
55 (Exists_Type ty_expected)
63 -- , (text_from_expr :: Repr_String IO h -> Text) r
67 tests = testGroup "Functor"
72 , AST "+" [ AST "var" [AST "x" []]
73 , AST "int" [AST "1" []] ]
77 , AST "int" [AST "1" []]
78 , AST "int" [AST "2" []]
79 , AST "int" [AST "3" []]
84 , "fmap (\\x0 -> x0 + 1) [1, 2, 3]" )