Skip to content

Commit dadb6a4

Browse files
committed
Add some further useful definitions and add some options
1 parent 6c915ed commit dadb6a4

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
docs/*.html
2+
*.agdai

Generics.agda

+46-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS --safe --without-K #-}
12
------------------------------------------------------------------------
23
-- Meta-programming utilities
34
------------------------------------------------------------------------
@@ -7,7 +8,7 @@ open import Level hiding (suc)
78
open import Function
89

910
open import Reflection hiding (visibility)
10-
open import Reflection.Term
11+
open import Reflection.Term hiding (getName)
1112
import Reflection.Name as Name
1213
open import Reflection.Pattern
1314
import Reflection.Abstraction as Abs
@@ -30,8 +31,6 @@ open import Relation.Nullary using (Dec)
3031
open import Relation.Nullary.Decidable using (⌊_⌋)
3132
open import Relation.Binary.PropositionalEquality hiding ([_])
3233

33-
open import Category.Applicative
34-
3534
private variable
3635
: Level
3736
A B : Set
@@ -68,6 +67,9 @@ pattern ⟦_⦅_⦆⇒_⟧ x tel k = clause tel (vArg x ∷ []) k
6867
pattern ⟦_∣_⇒_⟧ x y k = clause [] (vArg x ∷ vArg y ∷ []) k
6968
pattern ⟦_∣_⦅_⦆⇒_⟧ x y tel k = clause tel (vArg x ∷ vArg y ∷ []) k
7069

70+
pattern ⟦_∣_∣_⇒_⟧ x y z k = Clause.clause [] (vArg x ∷ vArg y ∷ vArg z ∷ []) k
71+
pattern ⟦_∣_∣_⦅_⦆⇒_⟧ x y z tel k = Clause.clause tel (vArg x ∷ vArg y ∷ vArg z ∷ []) k
72+
7173
-- lambdas
7274
pattern `λ_⇒_ x k = lam visible (abs x k)
7375
pattern `λ⟦_∣_⇒_⟧ x y k = `λ x ⇒ `λ y ⇒ k
@@ -90,6 +92,7 @@ pattern _∙ n = def n []
9092
pattern _∙⟦_⟧ n x = def n (vArg x ∷ [])
9193
pattern _∙⟦_∣_⟧ n x y = def n (vArg x ∷ vArg y ∷ [])
9294
pattern _∙⟦_∣_∣_⟧ n x y z = def n (vArg x ∷ vArg y ∷ vArg z ∷ [])
95+
pattern _∙⟦_∣_∣_∣_⟧ n x y z w = def n (vArg x ∷ vArg y ∷ vArg z ∷ vArg w ∷ [])
9396

9497
pattern _◆ n = con n []
9598
pattern _◆⟦_⟧ n x = con n (vArg x ∷ [])
@@ -102,13 +105,51 @@ pattern _◇⟦_∣_⟧ n x y = Pattern.con n (vArg x ∷ vArg y ∷ [])
102105
-------------------------------------------------
103106
-- ** Other utilities
104107

108+
getName : Abs A String
109+
getName (abs s x) = s
110+
111+
getVisibility : {a} {A : Set a} Arg A Visibility
112+
getVisibility (arg (arg-info v _) _) = v
113+
114+
findMetas : Term List Term
115+
findMetas' : List (Arg Term) List Term
116+
findMetasCl : List Clause List Term
117+
118+
findMetas (var x args) = findMetas' args
119+
findMetas (con c args) = findMetas' args
120+
findMetas (def f args) = findMetas' args
121+
findMetas (lam v (abs _ x)) = findMetas x
122+
findMetas (pat-lam cs args) = findMetasCl cs Data.List.++ findMetas' args
123+
findMetas (pi (arg _ a) (abs _ b)) = findMetas a Data.List.++ findMetas b
124+
findMetas (agda-sort s) = []
125+
findMetas (lit l) = []
126+
findMetas m@(meta x args) = m ∷ findMetas' args
127+
findMetas unknown = []
128+
129+
findMetas' [] = []
130+
findMetas' ((arg _ t) ∷ ts) = findMetas t Data.List.++ findMetas' ts
131+
132+
findMetasCl [] = []
133+
findMetasCl (Clause.clause tel ps t ∷ c) = findMetas t Data.List.++ findMetasCl c
134+
findMetasCl (Clause.absurd-clause tel ps ∷ c) = findMetasCl c
135+
136+
isMeta : Term Bool
137+
isMeta (meta _ _) = true
138+
isMeta _ = false
139+
140+
UnquoteDecl : Set
141+
UnquoteDecl = TC ⊤
142+
105143
unArgs : Args A List A
106144
unArgs = map unArg
107145

108-
{-# TERMINATING #-}
109146
mapVariables : (ℕ ℕ) (Pattern Pattern)
110147
mapVariables f (Pattern.var n) = Pattern.var (f n)
111-
mapVariables f (Pattern.con c args) = Pattern.con c $ map (λ{ (arg i p) arg i (mapVariables f p) }) args
148+
mapVariables f (Pattern.con c args) = Pattern.con c $ mapVariables′ args
149+
where
150+
mapVariables′ : List (Arg Pattern) List (Arg Pattern)
151+
mapVariables′ [] = []
152+
mapVariables′ (arg i p ∷ l) = arg i (mapVariables f p) ∷ mapVariables′ l
112153
mapVariables _ p = p
113154

114155
-- alternative view of function types as a pair of a list of arguments and a return type

0 commit comments

Comments
 (0)