Skip to content

Commit 3f21999

Browse files
authored
Introduce common quoted terms (e.g. refl, yes, no)
1 parent f1aa13f commit 3f21999

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

Tactic/ByEq.agda

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open import Class.Functor
77
open import Class.Monad
88
open import Reflection using (TC; withNormalisation; inferType; unify)
99
open import Reflection.Utils using (argTys)
10+
open import Reflection.QuotedDefinitions
1011

1112
-- Introduce as many arguments as possible and then:
1213
-- 1. for those of type `_ ≡ _`, unify with `refl`
@@ -16,8 +17,8 @@ by-eq : Hole → TC ⊤
1617
by-eq hole = do
1718
ty withNormalisation true $ inferType hole
1819
let ps : Args Pattern
19-
ps = argTys ty <&> fmap λ {(def (quote _≡_) _) quote refl ; _ dot unknown}
20-
unify hole $ pat-lam [ clause [] ps (quote refl ◆) ] []
20+
ps = argTys ty <&> fmap λ { (_ ``≡ _) ``refl ; _ dot unknown }
21+
unify hole $ pat-lam [ clause [] ps `refl ] []
2122

2223
macro $by-eq = by-eq
2324

Tactic/ClauseBuilder.agda

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ open import Data.List.Sort using (SortingAlgorithm)
1515
open import Data.List.Sort.MergeSort using (mergeSort)
1616
open SortingAlgorithm ≤-decTotalOrder (mergeSort ≤-decTotalOrder) public
1717

18+
open import Reflection.QuotedDefinitions
1819
open import Reflection.Utils
1920
open import Reflection.Utils.TCI
2021

@@ -213,7 +214,7 @@ module _ {M : ∀ {a} → Set a → Set a} ⦃ _ : Monad M ⦄ ⦃ me : MonadErr
213214
return $ ref x'
214215

215216
caseMatch : Term M ClauseExpr M Term
216-
caseMatch t expr = debugLog ("Match" ∷ᵈ t ∷ᵈ []) >> (refineWithSingle (quote case_of_ ∙⟦ t ∣_⟧) $
217+
caseMatch t expr = debugLog ("Match" ∷ᵈ t ∷ᵈ []) >> (refineWithSingle (`case_of_ t) $
217218
(λ expr' pat-lam (clauseExprToClauses expr') []) <$> expr)
218219

219220
currentTyConstrPatterns : M (List SinglePattern)

Tactic/Derive/DecEq.agda

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ open import Reflection.Tactic
2323
open import Reflection.AST.Term using (_≟-Pattern_)
2424
open import Reflection.Utils
2525
open import Reflection.Utils.TCI
26+
open import Reflection.QuotedDefinitions
2627

2728
open import Class.DecEq.Core
2829
open import Class.Functor
@@ -39,10 +40,6 @@ open ClauseExprM
3940
private
4041
instance _ = ContextMonad-MonadTC
4142

42-
`yes `no : Term Term
43-
`yes x = quote _because_ ◆⟦ quote true ◆ ∣ quote ofʸ ◆⟦ x ⟧ ⟧
44-
`no x = quote _because_ ◆⟦ quote false ◆ ∣ quote ofⁿ ◆⟦ x ⟧ ⟧
45-
4643
-- We take the Dec P argument first to improve type checking performance.
4744
-- It's easy to infer the type of P from this argument and we need to know
4845
-- P to be able to check the pattern lambda generated for the P → Q direction
@@ -77,15 +74,15 @@ private
7774

7875
-- c x1 .. xn ≡ c y1 .. yn ⇔ x1 ≡ y1 .. xn ≡ yn
7976
genEquiv : Term
80-
genEquiv n = quote mk⇔ ∙⟦ `λ⟦ reflPattern n ⇒ quote refl ⟧ ∣ `λ⟦ quote refl ⇒ reflTerm n ⟧ ⟧
77+
genEquiv n = quote mk⇔ ∙⟦ `λ⟦ reflPattern n ⇒ `refl ⟧ ∣ `λ⟦ ``refl ⇒ reflTerm n ⟧ ⟧
8178
where
8279
reflPattern : Pattern
8380
reflPattern 0 = quote tt ◇
84-
reflPattern (suc n) = quote _,_ ◇⟦ reflPattern n ∣ quote refl
81+
reflPattern (suc n) = quote _,_ ◇⟦ reflPattern n ∣ ``refl ⟧
8582

8683
reflTerm : Term
8784
reflTerm 0 = quote tt ◆
88-
reflTerm (suc n) = quote _,_ ◆⟦ reflTerm n ∣ quote refl
85+
reflTerm (suc n) = quote _,_ ◆⟦ reflTerm n ∣ `refl ⟧
8986

9087
toMapDiag : SinglePattern SinglePattern NE.List⁺ SinglePattern × TC (ClauseExpr ⊎ Maybe Term)
9188
toMapDiag p@(_ , arg _ p₁) p'@(_ , arg _ p₂) =

Tactic/ReduceDec.agda

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open import Meta.Prelude
99
open import Meta.Init
1010

1111
open import Reflection.Tactic
12+
open import Reflection.QuotedDefinitions
1213
open import Reflection.Utils
1314
open import Reflection.Utils.TCI
1415
open import Relation.Nullary
@@ -79,8 +80,8 @@ fromWitnessFalse' (yes p) h = ⊥-elim $ h p
7980
fromWitnessFalse' (no ¬p) h = refl
8081

8182
fromWitness'Type : Bool Term Term
82-
fromWitness'Type true dec = def (quote _≡_) (hArg? ∷ hArg? ∷ def (quote isYes) (hArg? ∷ hArg? ∷ dec ⟨∷⟩ []) ⟨∷⟩ quote true ◆ ⟨∷⟩ [])
83-
fromWitness'Type false dec = def (quote _≡_) (hArg? ∷ hArg? ∷ def (quote isYes) (hArg? ∷ hArg? ∷ dec ⟨∷⟩ []) ⟨∷⟩ quote false ◆ ⟨∷⟩ [])
83+
fromWitness'Type true dec = quote isYes ∙⟦ dec ⟧ `≡ quote true ◆
84+
fromWitness'Type false dec = quote isYes ∙⟦ dec ⟧ `≡ quote false ◆
8485

8586
findDecRWHypWith : ITactic Term TC Term
8687
findDecRWHypWith tac dec =

Tactic/Rewrite.agda

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open import Data.Product using (map₂)
99
open import Relation.Nullary.Decidable using (⌊_⌋)
1010

1111
open import Reflection hiding (_>>=_; _>>_; _≟_)
12+
open import Reflection.QuotedDefinitions
1213
open import Reflection.Syntax
1314
open import Reflection.Tactic
1415
open import Reflection.Utils.Debug; open Debug ("tactic.rewrite" , 100)
@@ -21,7 +22,7 @@ open import Class.Show
2122

2223
viewEq : Term TC (Term × Term)
2324
viewEq eq = do
24-
(def (quote _≡_) (_ ∷ _ ∷ vArg x ∷ vArg y ∷ [])) inferType eq
25+
x ``≡ y inferType eq
2526
where _ error "Can only write with equalities `x ≡ y`."
2627
return (x , y)
2728

0 commit comments

Comments
 (0)