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.Traversable.Test where
12 import Test.Tasty.HUnit
14 import qualified Control.Arrow as Arrow
15 import qualified Control.Monad as Monad
16 import qualified Data.Functor as Functor
17 import Data.Proxy (Proxy(..))
18 import Data.Text (Text)
19 import Data.Type.Equality ((:~:)(Refl))
20 import Prelude hiding ((&&), not, (||), (==), (<$>), (+), Applicative(..), Monad(..), Traversable(..))
22 import Language.Symantic.Type
23 import Language.Symantic.Expr as Expr
24 import Language.Symantic.Repr
31 e1 = traverse (lam Right)
32 (list $ int Functor.<$> [1..3])
46 ex_from = root_expr_from (Proxy::Proxy Ex)
51 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
52 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
54 Left (_, err) -> Right ("…"::String) @?= Left err
55 Right (ty_expected::Type_Root_of_Expr Ex h, _::h, _::Text) ->
56 (Monad.>>= (@?= (\(_::Proxy h, err) -> err) `Arrow.left` expected)) $
57 case ty `eq_type` ty_expected of
58 Nothing -> Monad.return $ Left $
59 error_expr (Proxy::Proxy Ex) $
60 Error_Expr_Type_mismatch ast
62 (Exists_Type ty_expected)
64 let h = host_from_expr r
70 -- , (text_from_expr :: Repr_Text h -> Text) r
74 tests = testGroup "Traversable"
77 [ AST "x" [], AST "Int" []
78 , AST "just" [ AST "var" [ AST "x" [] ] ]
82 , AST "int" [AST "1" []]
83 , AST "int" [AST "2" []]
84 , AST "int" [AST "3" []]
87 ( type_maybe (type_list type_int)
89 , "traverse (\\x0 -> just x0) [1, 2, 3]" )
92 [ AST "x" [], AST "Int" []
93 , AST "right" [ AST "Int" [], AST "var" [ AST "x" [] ] ]
97 , AST "int" [AST "1" []]
98 , AST "int" [AST "2" []]
99 , AST "int" [AST "3" []]
102 ( type_either type_int (type_list type_int)
104 , "traverse (\\x0 -> right x0) [1, 2, 3]" )