1 {-# LANGUAGE NoMonomorphismRestriction #-}
2 {-# LANGUAGE UndecidableInstances #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
5 {-# OPTIONS_GHC -O0 #-} -- speedup compiling…
6 module Compiling.Map.Test where
10 import Data.Map.Strict (Map)
11 import qualified Data.Map.Strict as Map
12 import Data.Proxy (Proxy(..))
13 import Data.Text (Text)
14 import qualified Data.Text as Text
15 import Prelude hiding (zipWith)
17 import Language.Symantic.Parsing
18 import Language.Symantic.Typing
19 import Language.Symantic.Compiling
20 import Compiling.Term.Test
21 import Compiling.Bool.Test ()
22 import Compiling.Foldable.Test ()
26 e1 = map_fromList $ zipWith (lam (lam . tuple2))
27 (list $ int Prelude.<$> [1..5])
28 (list $ (text . Text.singleton) Prelude.<$> ['a'..'e'])
41 (==>) = test_term_from (Proxy::Proxy Ifaces)
44 ( Inj_Token (Syntax Text) ts Map
45 , Tokenize (Syntax Text) (Syntax Text) ts ) =>
46 TokenizeT (Syntax Text) (Syntax Text) ts (Proxy Map) where
47 tokenizeT _t (Syntax "Map.fromList" (ast_f : as)) = Just $ do
49 Right $ (as,) $ EToken $ inj_token (Syntax "Map.fromList" [ast_f]) $
50 Token_Term_Map_fromList f
51 tokenizeT _t (Syntax "Map.foldrWithKey" (ast_f : as)) = Just $ do
53 Right $ (as,) $ EToken $ inj_token (Syntax "Map.foldrWithKey" [ast_f]) $
54 Token_Term_Map_foldrWithKey f
55 tokenizeT _t _sy = Nothing
58 tests = testGroup "Map"
59 [ Syntax "Map.fromList"
61 [ syLam "x" (sy @Int) $
62 syLam "y" (sy @Text) $
81 ( (ty @Map :$ ty @Int) :$ ty @Text
82 , Map.fromList [(1, "a"), (2, "b"), (3, "c")]
83 , "Map.fromList (((\\x0 -> (\\x1 -> zipWith (\\x2 -> (\\x3 -> (x2, x3))) x0 x1)) [1, 2, 3]) [\"a\", \"b\", \"c\"])" )
84 , Syntax "Map.foldrWithKey"
85 [ syLam "k" (sy @Int) $
86 syLam "v" (sy @Text) $
87 syLam "a" (sy @(,) [sy @Int, sy @Text]) $
91 , Syntax "fst" [ syVar "a" ]
95 , Syntax "snd" [ syVar "a" ]
102 , Syntax "Map.fromList"
104 [ syLam "x" (sy @Int) $
105 syLam "y" (sy @Text) $
125 ( (ty @(,) :$ ty @Int) :$ ty @Text
127 , "((\\x0 -> (\\x1 -> Map.foldrWithKey (\\x2 -> (\\x3 -> (\\x4 -> ((\\x5 -> x2 + x5) (fst x4), (\\x5 -> mappend x3 x5) (snd x4))))) x0 x1)) (0, \"\")) (Map.fromList (((\\x0 -> (\\x1 -> zipWith (\\x2 -> (\\x3 -> (x2, x3))) x0 x1)) [1, 2, 3]) [\"a\", \"b\", \"c\"]))" )