| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Documentation for List membership |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
module README.Data.List.Membership where |
| 8 |
|
| 9 |
open import Data.Char.Base using (Char; fromℕ) |
| 10 |
open import Data.Char.Properties as Char hiding (setoid) |
| 11 |
open import Data.List.Base using (List; []; _∷_; map) |
| 12 |
open import Data.Nat as ℕ using (ℕ) |
| 13 |
open import Relation.Binary.PropositionalEquality |
| 14 |
using (_≡_; refl; cong; setoid) |
| 15 |
|
| 16 |
------------------------------------------------------------------------ |
| 17 |
-- Membership |
| 18 |
|
| 19 |
-- Membership of a list is simply a special case of `Any` where |
| 20 |
-- `x ∈ xs` is defined as `Any (x ≈_) xs`. |
| 21 |
|
| 22 |
-- Just like pointwise equality of lists, the exact membership module |
| 23 |
-- that should be used depends on whether the equality on the |
| 24 |
-- underlying elements of the list is i) propositional or setoid-based |
| 25 |
-- and ii) decidable. |
| 26 |
|
| 27 |
import Data.List.Membership.Setoid as SetoidMembership |
| 28 |
import Data.List.Membership.DecSetoid as DecSetoidMembership |
| 29 |
import Data.List.Membership.Propositional as PropMembership |
| 30 |
import Data.List.Membership.DecPropositional as DecPropMembership |
| 31 |
|
| 32 |
-- For example if we want to reason about membership for `List ℕ` |
| 33 |
-- then you would use the `DecPropMembership` as we use |
| 34 |
-- propositional equality over `ℕ` and it is also decidable. Therefore |
| 35 |
-- the module `DecPropMembership` should be opened as follows: |
| 36 |
|
| 37 |
open DecPropMembership ℕ._≟_ |
| 38 |
|
| 39 |
-- As membership is just an instance of `Any` we also need to import |
| 40 |
-- the constructors `here` and `there`. (See issue #553 on Github for |
| 41 |
-- why we're struggling to have `here` and `there` automatically |
| 42 |
-- re-exported by the membership modules). |
| 43 |
|
| 44 |
open import Data.List.Relation.Unary.Any using (here; there) |
| 45 |
|
| 46 |
-- These modules provide the infix notation `_∈_` which can be used |
| 47 |
-- as follows: |
| 48 |
|
| 49 |
lem₁ : 1 ∈ 2 ∷ 1 ∷ 3 ∷ [] |
| 50 |
lem₁ = there (here refl) |
| 51 |
|
| 52 |
-- Properties of the membership relation can be found in the following |
| 53 |
-- two files: |
| 54 |
|
| 55 |
import Data.List.Membership.Setoid.Properties as SetoidProperties |
| 56 |
import Data.List.Membership.Propositional.Properties as PropProperties |
| 57 |
|
| 58 |
-- As of yet there are no corresponding files for properties of |
| 59 |
-- membership for decidable versions of setoid and propositional |
| 60 |
-- equality as we have no properties that only hold when equality is |
| 61 |
-- decidable. |
| 62 |
|
| 63 |
-- These `Properties` modules are NOT parameterised in the same way as |
| 64 |
-- the main membership modules as some of the properties relate |
| 65 |
-- membership proofs for lists of different types. For example in the |
| 66 |
-- following the first `∈` refers to lists of type `List ℕ` whereas |
| 67 |
-- the second `∈` refers to lists of type `List Char`. |
| 68 |
|
| 69 |
open DecPropMembership Char._≟_ renaming (_∈_ to _∈ᶜ_) |
| 70 |
open SetoidProperties using (∈-map⁺) |
| 71 |
|
| 72 |
lem₂ : {v : ℕ} {xs : List ℕ} → v ∈ xs → fromℕ v ∈ᶜ map fromℕ xs |
| 73 |
lem₂ = ∈-map⁺ (setoid ℕ) (setoid Char) (cong fromℕ) |