| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Abstractions used in the reflection machinery |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Reflection.AST.Abstraction where |
| 10 |
|
| 11 |
open import Data.String.Base as String using (String) |
| 12 |
open import Data.String.Properties as String using (_≟_) |
| 13 |
open import Data.Product.Base using (_×_; <_,_>; uncurry) |
| 14 |
open import Level using (Level) |
| 15 |
open import Relation.Nullary.Decidable.Core using (Dec; map′; _×-dec_) |
| 16 |
open import Relation.Binary.Definitions using (DecidableEquality) |
| 17 |
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong₂) |
| 18 |
|
| 19 |
private |
| 20 |
variable |
| 21 |
a b : Level |
| 22 |
A B : Set a |
| 23 |
s t : String |
| 24 |
x y : A |
| 25 |
|
| 26 |
------------------------------------------------------------------------ |
| 27 |
-- Re-exporting the builtins publicly |
| 28 |
|
| 29 |
open import Agda.Builtin.Reflection public |
| 30 |
using (Abs) |
| 31 |
|
| 32 |
open Abs public |
| 33 |
|
| 34 |
------------------------------------------------------------------------ |
| 35 |
-- Operations |
| 36 |
|
| 37 |
map : (A → B) → Abs A → Abs B |
| 38 |
map f (abs s x) = abs s (f x) |
| 39 |
|
| 40 |
------------------------------------------------------------------------ |
| 41 |
-- Decidable equality |
| 42 |
|
| 43 |
abs-injective₁ : abs s x ≡ abs t y → s ≡ t |
| 44 |
abs-injective₁ refl = refl |
| 45 |
|
| 46 |
abs-injective₂ : abs s x ≡ abs t y → x ≡ y |
| 47 |
abs-injective₂ refl = refl |
| 48 |
|
| 49 |
abs-injective : abs s x ≡ abs t y → s ≡ t × x ≡ y |
| 50 |
abs-injective = < abs-injective₁ , abs-injective₂ > |
| 51 |
|
| 52 |
-- We often need decidability of equality for Abs A when implementing it |
| 53 |
-- for A. Unfortunately ≡-dec makes the termination checker unhappy. |
| 54 |
-- Instead, we can match on both Abs A and use unAbs-dec for an |
| 55 |
-- obviously decreasing recursive call. |
| 56 |
|
| 57 |
unAbs : Abs A → A |
| 58 |
unAbs (abs s a) = a |
| 59 |
|
| 60 |
unAbs-dec : {abs1 abs2 : Abs A} → Dec (unAbs abs1 ≡ unAbs abs2) → Dec (abs1 ≡ abs2) |
| 61 |
unAbs-dec {abs1 = abs s a} {abs t a′} a≟a′ = |
| 62 |
map′ (uncurry (cong₂ abs)) abs-injective (s String.≟ t ×-dec a≟a′) |
| 63 |
|
| 64 |
≡-dec : DecidableEquality A → DecidableEquality (Abs A) |
| 65 |
≡-dec _≟_ x y = unAbs-dec (unAbs x ≟ unAbs y) |