| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Wrapper for the proof irrelevance modality |
| 5 |
-- |
| 6 |
-- This allows us to store proof irrelevant witnesses in a record and |
| 7 |
-- use projections to manipulate them without having to turn on the |
| 8 |
-- unsafe option --irrelevant-projections. |
| 9 |
-- Cf. Data.Refinement for a use case |
| 10 |
------------------------------------------------------------------------ |
| 11 |
|
| 12 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 13 |
|
| 14 |
module Data.Irrelevant where |
| 15 |
|
| 16 |
open import Level using (Level) |
| 17 |
|
| 18 |
private |
| 19 |
variable |
| 20 |
a b c : Level |
| 21 |
A : Set a |
| 22 |
B : Set b |
| 23 |
C : Set c |
| 24 |
|
| 25 |
------------------------------------------------------------------------ |
| 26 |
-- Type |
| 27 |
|
| 28 |
record Irrelevant (A : Set a) : Set a where |
| 29 |
constructor [_] |
| 30 |
field .irrelevant : A |
| 31 |
open Irrelevant public |
| 32 |
|
| 33 |
------------------------------------------------------------------------ |
| 34 |
-- Algebraic structure: Functor, Appplicative and Monad-like |
| 35 |
|
| 36 |
map : (A → B) → Irrelevant A → Irrelevant B |
| 37 |
map f [ a ] = [ f a ] |
| 38 |
|
| 39 |
pure : A → Irrelevant A |
| 40 |
pure x = [ x ] |
| 41 |
|
| 42 |
infixl 4 _<*>_ |
| 43 |
_<*>_ : Irrelevant (A → B) → Irrelevant A → Irrelevant B |
| 44 |
[ f ] <*> [ a ] = [ f a ] |
| 45 |
|
| 46 |
infixl 1 _>>=_ |
| 47 |
_>>=_ : Irrelevant A → (.A → Irrelevant B) → Irrelevant B |
| 48 |
[ a ] >>= f = f a |
| 49 |
|
| 50 |
------------------------------------------------------------------------ |
| 51 |
-- Other functions |
| 52 |
|
| 53 |
zipWith : (A → B → C) → Irrelevant A → Irrelevant B → Irrelevant C |
| 54 |
zipWith f a b = ⦇ f a b ⦈ |