{-# 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.Visibility
open import Reflection.AST.Argument.Relevance
open import Reflection.AST.Argument.Quantity
open import Reflection.AST.Argument.Modality
open import Reflection.AST.Argument.Information as Information
private
variable
a b : Level
A B : Set a
i j : ArgInfo
x y : A
open import Agda.Builtin.Reflection public using (Arg)
open Arg public
pattern defaultModality = modality relevant quantity-ω
pattern vArg ty = arg (arg-info visible defaultModality) ty
pattern hArg ty = arg (arg-info hidden defaultModality) ty
pattern iArg ty = arg (arg-info instance′ defaultModality) ty
Args : (A : Set a) → Set a
Args A = List (Arg A)
infixr 5 _⟨∷⟩_
pattern _⟨∷⟩_ x args = vArg x ∷ args
infixr 5 _⟅∷⟆_
pattern _⟅∷⟆_ x args = hArg x ∷ args
map : (A → B) → Arg A → Arg B
map f (arg i x) = arg i (f x)
map-Args : (A → B) → Args A → Args B
map-Args f xs = List.map (map f) xs
arg-injective₁ : arg i x ≡ arg j y → i ≡ j
arg-injective₁ refl = refl
arg-injective₂ : arg i x ≡ arg j y → x ≡ y
arg-injective₂ refl = refl
arg-injective : arg i x ≡ arg j y → i ≡ j × x ≡ y
arg-injective = < arg-injective₁ , arg-injective₂ >
unArg : Arg A → A
unArg (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)