Debian Codegraph @

src/Reflection/AST/Argument.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Arguments used in the reflection machinery
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Reflection.AST.Argument where
10
11 open import Data.List.Base as List using (List; []; _∷_)
12 open import Data.Product.Base using (_×_; <_,_>; uncurry)
13 open import Relation.Nullary.Decidable.Core using (Dec; map′; _×-dec_)
14 open import Relation.Binary.Definitions using (DecidableEquality)
15 open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong₂)
16 open import Level using (Level)
17 open import Reflection.AST.Argument.Visibility
18 open import Reflection.AST.Argument.Relevance
19 open import Reflection.AST.Argument.Quantity
20 open import Reflection.AST.Argument.Modality
21 open import Reflection.AST.Argument.Information as Information
22
23 private
24 variable
25 a b : Level
26 A B : Set a
27 i j : ArgInfo
28 x y : A
29
30 ------------------------------------------------------------------------
31 -- Re-exporting the builtins publicly
32
33 open import Agda.Builtin.Reflection public using (Arg)
34 open Arg public
35
36 -- Pattern synonyms
37
38 pattern defaultModality = modality relevant quantity-ω
39
40 pattern vArg ty = arg (arg-info visible defaultModality) ty
41 pattern hArg ty = arg (arg-info hidden defaultModality) ty
42 pattern iArg ty = arg (arg-info instance′ defaultModality) ty
43
44 ------------------------------------------------------------------------
45 -- Lists of arguments
46
47 Args : (A : Set a) → Set a
48 Args A = List (Arg A)
49
50 -- Pattern for appending a visible argument
51 infixr 5 _⟨∷⟩_
52 pattern _⟨∷⟩_ x args = vArg x ∷ args
53
54 -- Pattern for appending a hidden argument
55 infixr 5 _⟅∷⟆_
56 pattern _⟅∷⟆_ x args = hArg x ∷ args
57
58 ------------------------------------------------------------------------
59 -- Operations
60
61 map : (A → B) → Arg A → Arg B
62 map f (arg i x) = arg i (f x)
63
64 map-Args : (A → B) → Args A → Args B
65 map-Args f xs = List.map (map f) xs
66
67 ------------------------------------------------------------------------
68 -- Decidable equality
69
70 arg-injective₁ : arg i x ≡ arg j y → i ≡ j
71 arg-injective₁ refl = refl
72
73 arg-injective₂ : arg i x ≡ arg j y → x ≡ y
74 arg-injective₂ refl = refl
75
76 arg-injective : arg i x ≡ arg j y → i ≡ j × x ≡ y
77 arg-injective = < arg-injective₁ , arg-injective₂ >
78
79 -- We often need decidability of equality for Arg A when implementing it
80 -- for A. Unfortunately ≡-dec makes the termination checker unhappy.
81 -- Instead, we can match on both Arg A and use unArg-dec for an
82 -- obviously decreasing recursive call.
83
84 unArg : Arg A → A
85 unArg (arg i a) = a
86
87 unArg-dec : {arg1 arg2 : Arg A} → Dec (unArg arg1 ≡ unArg arg2) → Dec (arg1 ≡ arg2)
88 unArg-dec {arg1 = arg i x} {arg j y} arg1≟arg2 =
89 map′ (uncurry (cong₂ arg)) arg-injective (i Information.≟ j ×-dec arg1≟arg2)
90
91 ≡-dec : DecidableEquality A → DecidableEquality (Arg A)
92 ≡-dec _≟_ x y = unArg-dec (unArg x ≟ unArg y)