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.Functor.Test where
10 import Data.Proxy (Proxy(..))
11 import Data.Text (Text)
12 import Prelude hiding ((&&), not, (||))
14 import Language.Symantic.Parsing
15 import Language.Symantic.Typing
16 import Language.Symantic.Compiling
17 import Compiling.Term.Test
18 import Compiling.Bool.Test ()
28 (==>) = test_compile (Proxy::Proxy Ifaces)
31 ( Inj_Token (Syntax Text) ts Functor
32 , Tokenize (Syntax Text) (Syntax Text) ts ) =>
33 TokenizeT (Syntax Text) (Syntax Text) ts (Proxy Functor) where
34 tokenizeT _t (Syntax "fmap" (ast_f : ast_m : as)) = Just $ do
37 Right $ (as,) $ EToken $ inj_token (Syntax "fmap" [ast_f, ast_m]) $
38 Token_Term_Functor_fmap f m
39 tokenizeT _t (Syntax "(<$)" (ast_a : ast_fb : as)) = Just $ do
42 Right $ (as,) $ EToken $ inj_token (Syntax "fmap" [ast_a, ast_fb]) $
43 Token_Term_Functor_ltdollar a fb
44 tokenizeT _t _sy = Nothing
47 tests = testGroup "Functor"
49 [ syLam "x" (sy @Bool)
50 (Syntax "not" [syVar "x"])
51 , Syntax "Just" [syLit True]
52 ] ==> Right (ty @Maybe :$ ty @Bool, Just False, "fmap (\\x0 -> (\\x1 -> not x1) x0) (Just True)")
55 , Syntax "Just" [syLit True]
56 ] ==> Right (ty @Maybe :$ ty @Bool, Just False, "False <$ Just True")