Debian Codegraph @

doc/README/Data/Record.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- An example of how the Record module can be used
5 ------------------------------------------------------------------------
6
7 -- Taken from Randy Pollack's paper "Dependently Typed Records in Type
8 -- Theory".
9
10 {-# OPTIONS --with-K #-}
11
12 module README.Data.Record where
13
14 open import Data.Product.Base using (_,_)
15 open import Data.String
16 open import Function.Base using (flip)
17 open import Level
18 open import Relation.Binary.Definitions using (Symmetric; Transitive)
19
20 import Data.Record as Record
21
22 -- Let us use strings as labels.
23
24 open Record String _≟_
25
26 -- Partial equivalence relations.
27
28 PER : Signature _
29 PER = ∅ , "S" ∶ (λ _ → Set)
30 , "R" ∶ (λ r → r · "S" → r · "S" → Set)
31 , "sym" ∶ (λ r → Lift _ (Symmetric (r · "R")))
32 , "trans" ∶ (λ r → Lift _ (Transitive (r · "R")))
33
34 -- Given a PER the converse relation is also a PER.
35
36 converse : (P : Record PER) →
37 Record (PER With "S" ≔ (λ _ → P · "S")
38 With "R" ≔ (λ _ → flip (P · "R")))
39 converse P =
40 rec (rec (_ ,
41 lift λ {_} → lower (P · "sym")) ,
42 lift λ {_} yRx zRy → lower (P · "trans") zRy yRx)