1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeOperators #-}
7 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
8 module Expr.Map.Test where
11 import Test.Tasty.HUnit
13 import qualified Control.Arrow as Arrow
14 import qualified Control.Monad as Monad
15 -- import qualified Data.List as List
16 import qualified Data.Map.Strict as Map
17 import Data.Proxy (Proxy(..))
18 import Data.Text (Text)
19 import qualified Data.Text as Text
20 import Data.Type.Equality ((:~:)(Refl))
21 import Prelude hiding (maybe, not)
23 import Language.Symantic.Repr
24 import Language.Symantic.Expr
25 import Language.Symantic.Type
32 e1 = map_from_list $ list_zipWith (lam (lam . tuple2))
33 (list $ int Prelude.<$> [1..5])
34 (list $ (text . Text.singleton) Prelude.<$> ['a'..'e'])
51 ex_from = root_expr_from (Proxy::Proxy Ex)
56 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
57 Right (Exists_Type0_and_Repr ty (Forall_Repr r)) ->
59 Left (_, err) -> Right ("…"::String) @?= Left err
60 Right (ty_expected::Type_Root_of_Expr Ex h, _::h, _::Text) ->
61 (Monad.>>= (@?= (\(_::Proxy h, err) -> err) `Arrow.left` expected)) $
62 case ty `type0_eq` ty_expected of
63 Nothing -> Monad.return $ Left $
64 error_expr (Proxy::Proxy Ex) $
65 Error_Expr_Type_mismatch ast
67 (Exists_Type0 ty_expected)
69 let h = host_from_expr r
75 -- , (text_from_expr :: Repr_Text h -> Text) r
79 tests = testGroup "Map"
89 [ AST "var" [AST "x" []]
90 , AST "var" [AST "y" []]
96 , AST "int" [AST "1" []]
97 , AST "int" [AST "2" []]
98 , AST "int" [AST "3" []]
102 , AST "text" [AST "a" []]
103 , AST "text" [AST "b" []]
104 , AST "text" [AST "c" []]
108 ( type_map type_int type_text
109 , Map.fromList [(1, "a"), (2, "b"), (3, "c")]
110 , "map_from_list (list_zipWith (\\x0 -> (\\x1 -> (x0, x1))) [1, 2, 3] [\"a\", \"b\", \"c\"])" )
111 , AST "map_foldrWithKey"
120 , AST "(,)" [AST "Int" [], AST "Text" []]
123 [ AST "var" [AST "k" []]
124 , AST "fst" [ AST "var" [AST "a" []] ]
127 [ AST "var" [AST "v" []]
128 , AST "snd" [ AST "var" [AST "a" []] ]
135 [ AST "int" [AST "0" []]
136 , AST "text" [AST "" []]
138 , AST "map_from_list"
147 [ AST "var" [AST "x" []]
148 , AST "var" [AST "y" []]
154 , AST "int" [AST "1" []]
155 , AST "int" [AST "2" []]
156 , AST "int" [AST "3" []]
160 , AST "text" [AST "a" []]
161 , AST "text" [AST "b" []]
162 , AST "text" [AST "c" []]
167 ( type_tuple2 type_int type_text
169 , "map_foldrWithKey (\\x0 -> (\\x1 -> (\\x2 -> (x0 + fst x2, mappend x1 (snd x2))))) (0, \"\") (map_from_list (list_zipWith (\\x0 -> (\\x1 -> (x0, x1))) [1, 2, 3] [\"a\", \"b\", \"c\"]))" )