123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293-------------------------------------------------------------------------- The Agda standard library---- Arguments used in the reflection machinery------------------------------------------------------------------------ {-# OPTIONS --cubical-compatible --safe #-} module Reflection.AST.Argument where open import Data.List.Base as List using (List; []; _∷_)open import Data.Product.Base using (_×_; <_,_>; uncurry)open import Relation.Nullary.Decidable.Core using (Dec; map′; _×-dec_)open import Relation.Binary.Definitions using (DecidableEquality)open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong₂)open import Level open import Reflection.AST.Argument.Visibilityopen import Reflection.AST.Argument.Relevanceopen import Reflection.AST.Argument.Quantityopen import Reflection.AST.Argument.Modalityopen import Reflection.AST.Argument.Information as Information private variable a b : Level A B : Set a i j : ArgInfo x y : A -------------------------------------------------------------------------- Re-exporting the builtins publicly open import Agda.Builtin.Reflection public using (Arg)open Arg public -- Pattern synonyms pattern defaultModality = modality relevant quantity-ω pattern vArg ty = arg (arg-info visible defaultModality) typattern hArg ty = arg (arg-info hidden defaultModality) typattern iArg ty = arg (arg-info instance′ defaultModality) ty -------------------------------------------------------------------------- Lists of arguments Args : (A : Set a) → Set aArgs A = List (Arg A) -- Pattern for appending a visible argumentinfixr 5 _⟨∷⟩_pattern _⟨∷⟩_ x args = vArg x ∷ args -- Pattern for appending a hidden argumentinfixr 5 _⟅∷⟆_pattern _⟅∷⟆_ x args = hArg x ∷ args -------------------------------------------------------------------------- Operations map : (A → B) → Arg A → Arg Bmap f (arg i x) = arg i (f x) map-Args : (A → B) → Args A → Args Bmap-Args f xs = List.map (map f) xs -------------------------------------------------------------------------- Decidable equality arg-injective₁ : arg i x ≡ arg j y → i ≡ jarg-injective₁ refl = refl arg-injective₂ : arg i x ≡ arg j y → x ≡ yarg-injective₂ refl = refl arg-injective : arg i x ≡ arg j y → i ≡ j × x ≡ yarg-injective = < arg-injective₁ , arg-injective₂ > -- We often need decidability of equality for Arg A when implementing it-- for A. Unfortunately ≡-dec makes the termination checker unhappy.-- Instead, we can match on both Arg A and use unArg-dec for an-- obviously decreasing recursive call. unArg : Arg A → AunArg (arg i a) = a unArg-dec : {arg1 arg2 : Arg A} → Dec (unArg arg1 ≡ unArg arg2) → Dec (arg1 ≡ arg2)unArg-dec {arg1 = arg i x} {arg j y} arg1≟arg2 = map′ (uncurry (cong₂ arg)) arg-injective (i Information.≟ j ×-dec arg1≟arg2) ≡-dec : DecidableEquality A → DecidableEquality (Arg A)≡-dec _≟_ x y = unArg-dec (unArg x ≟ unArg y)