2022-05-25 10:10:19 -04:00
|
|
|
module Tests.Reduce
|
|
|
|
|
|
|
|
import Quox.Syntax as Lib
|
2023-01-22 18:53:34 -05:00
|
|
|
import Quox.Equal
|
2022-05-25 10:10:19 -04:00
|
|
|
import TermImpls
|
2023-02-22 01:40:19 -05:00
|
|
|
import TypingImpls
|
2022-05-25 10:10:19 -04:00
|
|
|
import TAP
|
|
|
|
|
|
|
|
|
2023-04-15 09:13:01 -04:00
|
|
|
parameters {0 isRedex : RedexTest tm} {auto _ : Whnf tm isRedex} {d, n : Nat}
|
|
|
|
{auto _ : (Eq (tm d n), Show (tm d n))}
|
2023-04-01 13:16:43 -04:00
|
|
|
{default empty defs : Definitions}
|
2023-04-15 09:13:01 -04:00
|
|
|
private
|
|
|
|
testWhnf : String -> WhnfContext d n -> tm d n -> tm d n -> Test
|
|
|
|
testWhnf label ctx from to = test "\{label} (whnf)" $ do
|
|
|
|
result <- bimap toInfo fst $ whnf defs ctx from
|
2023-02-22 01:40:19 -05:00
|
|
|
unless (result == to) $ Left [("exp", show to), ("got", show result)]
|
2022-05-25 10:10:19 -04:00
|
|
|
|
2023-04-15 09:13:01 -04:00
|
|
|
private
|
|
|
|
testNoStep : String -> WhnfContext d n -> tm d n -> Test
|
|
|
|
testNoStep label ctx e = testWhnf label ctx e e
|
2022-05-25 10:10:19 -04:00
|
|
|
|
2023-04-15 09:13:01 -04:00
|
|
|
private
|
|
|
|
ctx : Context (\n => (BaseName, Term 0 n)) n -> WhnfContext 0 n
|
|
|
|
ctx xs = let (ns, ts) = unzip xs in MkWhnfContext [<] ns ts
|
2022-05-25 10:10:19 -04:00
|
|
|
|
2023-04-15 09:13:01 -04:00
|
|
|
|
|
|
|
export
|
|
|
|
tests : Test
|
2022-05-25 10:10:19 -04:00
|
|
|
tests = "whnf" :- [
|
|
|
|
"head constructors" :- [
|
2023-04-15 09:13:01 -04:00
|
|
|
testNoStep "★₀" empty $ TYPE 0,
|
|
|
|
testNoStep "[A] ⊸ [B]" empty $
|
2022-05-25 10:10:19 -04:00
|
|
|
Arr One (FT "A") (FT "B"),
|
2023-04-15 09:13:01 -04:00
|
|
|
testNoStep "(x: [A]) ⊸ [B [x]]" empty $
|
2023-03-16 13:18:49 -04:00
|
|
|
Pi One (FT "A") (S [< "x"] $ Y $ E $ F "B" :@ BVT 0),
|
2023-04-15 09:13:01 -04:00
|
|
|
testNoStep "λx. [x]" empty $
|
2023-03-16 13:18:49 -04:00
|
|
|
Lam $ S [< "x"] $ Y $ BVT 0,
|
2023-04-15 09:13:01 -04:00
|
|
|
testNoStep "[f [a]]" empty $
|
2022-05-25 10:10:19 -04:00
|
|
|
E $ F "f" :@ FT "a"
|
|
|
|
],
|
|
|
|
|
|
|
|
"neutrals" :- [
|
2023-04-15 09:13:01 -04:00
|
|
|
testNoStep "x" (ctx [< ("A", Nat)]) $ BV 0,
|
|
|
|
testNoStep "a" empty $ F "a",
|
|
|
|
testNoStep "f [a]" empty $ F "f" :@ FT "a",
|
|
|
|
testNoStep "★₀ ∷ ★₁" empty $ TYPE 0 :# TYPE 1
|
2022-05-25 10:10:19 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
"redexes" :- [
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "[a] ∷ [A]" empty
|
2022-05-25 10:10:19 -04:00
|
|
|
(FT "a" :# FT "A")
|
|
|
|
(F "a"),
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "[★₁ ∷ ★₃]" empty
|
2022-05-25 10:10:19 -04:00
|
|
|
(E (TYPE 1 :# TYPE 3))
|
|
|
|
(TYPE 1),
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "(λx. [x] ∷ [A] ⊸ [A]) [a]" empty
|
2023-03-16 13:18:49 -04:00
|
|
|
((([< "x"] :\\ BVT 0) :# Arr One (FT "A") (FT "A")) :@ FT "a")
|
2022-05-25 10:10:19 -04:00
|
|
|
(F "a")
|
|
|
|
],
|
|
|
|
|
2023-01-22 18:53:34 -05:00
|
|
|
"definitions" :- [
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "a (transparent)" empty
|
2023-04-01 13:16:43 -04:00
|
|
|
{defs = fromList [("a", mkDef gzero (TYPE 1) (TYPE 0))]}
|
2023-01-22 18:53:34 -05:00
|
|
|
(F "a") (TYPE 0 :# TYPE 1)
|
|
|
|
],
|
|
|
|
|
2022-05-25 10:10:19 -04:00
|
|
|
"elim closure" :- [
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "x{}" (ctx [< ("A", Nat)])
|
2022-05-25 10:10:19 -04:00
|
|
|
(CloE (BV 0) id)
|
|
|
|
(BV 0),
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "x{a/x}" empty
|
2022-05-25 10:10:19 -04:00
|
|
|
(CloE (BV 0) (F "a" ::: id))
|
|
|
|
(F "a"),
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "x{x/x,a/y}" (ctx [< ("A", Nat)])
|
2022-05-25 10:10:19 -04:00
|
|
|
(CloE (BV 0) (BV 0 ::: F "a" ::: id))
|
|
|
|
(BV 0),
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "x{(y{a/y})/x}" empty
|
2022-05-25 10:10:19 -04:00
|
|
|
(CloE (BV 0) ((CloE (BV 0) (F "a" ::: id)) ::: id))
|
|
|
|
(F "a"),
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "(x y){f/x,a/y}" empty
|
2022-05-25 10:10:19 -04:00
|
|
|
(CloE (BV 0 :@ BVT 1) (F "f" ::: F "a" ::: id))
|
|
|
|
(F "f" :@ FT "a"),
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "([y] ∷ [x]){A/x}" (ctx [< ("A", Nat)])
|
2022-05-25 10:10:19 -04:00
|
|
|
(CloE (BVT 1 :# BVT 0) (F "A" ::: id))
|
|
|
|
(BV 0),
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "([y] ∷ [x]){A/x,a/y}" empty
|
2022-05-25 10:10:19 -04:00
|
|
|
(CloE (BVT 1 :# BVT 0) (F "A" ::: F "a" ::: id))
|
|
|
|
(F "a")
|
|
|
|
],
|
|
|
|
|
|
|
|
"term closure" :- [
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "(λy. x){a/x}" empty
|
2023-03-16 13:18:49 -04:00
|
|
|
(CloT (Lam $ S [< "y"] $ N $ BVT 0) (F "a" ::: id))
|
|
|
|
(Lam $ S [< "y"] $ N $ FT "a"),
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "(λy. y){a/x}" empty
|
2023-03-16 13:18:49 -04:00
|
|
|
(CloT ([< "y"] :\\ BVT 0) (F "a" ::: id))
|
|
|
|
([< "y"] :\\ BVT 0)
|
2022-05-25 10:10:19 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
"looking inside […]" :- [
|
2023-04-15 09:13:01 -04:00
|
|
|
testWhnf "[(λx. x ∷ A ⊸ A) [a]]" empty
|
2023-03-16 13:18:49 -04:00
|
|
|
(E $ (([< "x"] :\\ BVT 0) :# Arr One (FT "A") (FT "A")) :@ FT "a")
|
2022-05-25 10:10:19 -04:00
|
|
|
(FT "a")
|
|
|
|
],
|
|
|
|
|
|
|
|
"nested redex" :- [
|
|
|
|
note "whnf only looks at top level redexes",
|
2023-04-15 09:13:01 -04:00
|
|
|
testNoStep "λy. [(λx. [x] ∷ [A] ⊸ [A]) [y]]" empty $
|
2023-03-16 13:18:49 -04:00
|
|
|
[< "y"] :\\ E ((([< "x"] :\\ BVT 0) :# Arr One (FT "A") (FT "A")) :@ BVT 0),
|
2023-04-15 09:13:01 -04:00
|
|
|
testNoStep "f [(λx. [x] ∷ [A] ⊸ [A]) [a]]" empty $
|
2022-05-25 10:10:19 -04:00
|
|
|
F "a" :@
|
2023-03-16 13:18:49 -04:00
|
|
|
E ((([< "x"] :\\ BVT 0) :# Arr One (FT "A") (FT "A")) :@ FT "a"),
|
2023-04-15 09:13:01 -04:00
|
|
|
testNoStep "λx. [y [x]]{x/x,a/y}" (ctx [< ("A", Nat)]) $
|
2023-03-16 13:18:49 -04:00
|
|
|
[< "x"] :\\ CloT (E $ BV 1 :@ BVT 0) (BV 0 ::: F "a" ::: id),
|
2023-04-15 09:13:01 -04:00
|
|
|
testNoStep "f ([y [x]]{x/x,a/y})" (ctx [< ("A", Nat)]) $
|
2022-05-27 12:00:06 -04:00
|
|
|
F "f" :@ CloT (E $ BV 1 :@ BVT 0) (BV 0 ::: F "a" ::: id)
|
2022-05-25 10:10:19 -04:00
|
|
|
]
|
|
|
|
]
|