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'])
50 ex_from = root_expr_from (Proxy::Proxy Ex)
55 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
56 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
58 Left (_, err) -> Right ("…"::String) @?= Left err
59 Right (ty_expected::Type_Root_of_Expr Ex h, _::h, _::Text) ->
60 (Monad.>>= (@?= (\(_::Proxy h, err) -> err) `Arrow.left` expected)) $
61 case ty `eq_type` ty_expected of
62 Nothing -> Monad.return $ Left $
63 error_expr (Proxy::Proxy Ex) $
64 Error_Expr_Type_mismatch ast
66 (Exists_Type ty_expected)
68 let h = host_from_expr r
74 -- , (text_from_expr :: Repr_Text h -> Text) r
78 tests = testGroup "Map"
88 [ AST "var" [AST "x" []]
89 , AST "var" [AST "y" []]
95 , AST "int" [AST "1" []]
96 , AST "int" [AST "2" []]
97 , AST "int" [AST "3" []]
101 , AST "text" [AST "a" []]
102 , AST "text" [AST "b" []]
103 , AST "text" [AST "c" []]
107 ( type_map type_int type_text
108 , Map.fromList [(1, "a"), (2, "b"), (3, "c")]
109 , "map_from_list (list_zipWith (\\x0 -> (\\x1 -> (x0, x1))) [1, 2, 3] [\"a\", \"b\", \"c\"])" )
110 , AST "map_foldrWithKey"
119 , AST "(,)" [AST "Int" [], AST "Text" []]
122 [ AST "var" [AST "k" []]
123 , AST "fst" [ AST "var" [AST "a" []] ]
126 [ AST "var" [AST "v" []]
127 , AST "snd" [ AST "var" [AST "a" []] ]
134 [ AST "int" [AST "0" []]
135 , AST "text" [AST "" []]
137 , AST "map_from_list"
146 [ AST "var" [AST "x" []]
147 , AST "var" [AST "y" []]
153 , AST "int" [AST "1" []]
154 , AST "int" [AST "2" []]
155 , AST "int" [AST "3" []]
159 , AST "text" [AST "a" []]
160 , AST "text" [AST "b" []]
161 , AST "text" [AST "c" []]
166 ( type_tuple2 type_int type_text
168 , "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\"]))" )