Debian Codegraph @

src/Data/Refinement/Base.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Refinement type: a value together with a proof irrelevant witness.
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Refinement.Base where
10
11 open import Data.Irrelevant as Irrelevant using (Irrelevant)
12 open import Function.Base using (id)
13 open import Level using (Level; _⊔_)
14 open import Relation.Unary using (IUniversal; _⇒_; _⊢_)
15
16 private
17 variable
18 a b p q : Level
19 A : Set a
20 B : Set b
21 P : A → Set p
22
23
24 ------------------------------------------------------------------------
25 -- Definition
26
27 record Refinement (A : Set a) (P : A → Set p) : Set (a ⊔ p) where
28 constructor _,_
29 field value : A
30 proof : Irrelevant (P value)
31 infixr 4 _,_
32 open Refinement public
33
34 -- The syntax declaration below is meant to mimic set comprehension.
35 -- It is attached to Refinement-syntax, to make it easy to import
36 -- Data.Refinement without the special syntax.
37
38 infix 2 Refinement-syntax
39 Refinement-syntax = Refinement
40 syntax Refinement-syntax A (λ x → P) = [ x ∈ A ∣ P ]
41
42 ------------------------------------------------------------------------
43 -- Basic operations
44
45 module _ {Q : B → Set q} where
46
47 map : (f : A → B) → ∀[ P ⇒ f ⊢ Q ] →
48 [ a ∈ A ∣ P a ] → [ b ∈ B ∣ Q b ]
49 map f prf (a , p) = f a , Irrelevant.map prf p
50
51 module _ {Q : A → Set q} where
52
53 refine : ∀[ P ⇒ Q ] → [ a ∈ A ∣ P a ] → [ a ∈ A ∣ Q a ]
54 refine = map id