forked from agda/agda-stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.agda
337 lines (259 loc) · 10.5 KB
/
README.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
module README where
------------------------------------------------------------------------
-- The Agda standard library, version 1.3-dev
--
-- Authors: Nils Anders Danielsson, Matthew Daggitt, Guillaume Allais
-- with contributions from Andreas Abel, Stevan Andjelkovic,
-- Jean-Philippe Bernardy, Peter Berry, Bradley Hardy Joachim Breitner,
-- Samuel Bronson, Daniel Brown, Jacques Carette, James Chapman,
-- Liang-Ting Chen, Dominique Devriese, Dan Doel, Érdi Gergő,
-- Zack Grannan, Helmut Grohne, Simon Foster, Liyang Hu, Jason Hu,
-- Patrik Jansson, Alan Jeffrey, Wen Kokke, Evgeny Kotelnikov,
-- Sergei Meshveliani, Eric Mertens, Darin Morrison, Guilhem Moulin,
-- Shin-Cheng Mu, Ulf Norell, Noriyuki Ohkawa, Nicolas Pouillard,
-- Andrés Sicard-Ramírez, Lex van der Stoep, Sandro Stucki, Milo Turner,
-- Noam Zeilberger and other anonymous contributors.
------------------------------------------------------------------------
-- This version of the library has been tested using Agda 2.6.0.1.
-- The library comes with a .agda-lib file, for use with the library
-- management system.
-- Currently the library does not support the JavaScript compiler
-- backend.
------------------------------------------------------------------------
-- Module hierarchy
------------------------------------------------------------------------
-- The top-level module names of the library are currently allocated
-- as follows:
--
-- • Algebra
-- Abstract algebra (monoids, groups, rings etc.), along with
-- properties needed to specify these structures (associativity,
-- commutativity, etc.), and operations on and proofs about the
-- structures.
-- • Axiom
-- Types and consequences of various additional axioms not
-- necessarily included in Agda, e.g. uniqueness of identity
-- proofs, function extensionality and excluded middle.
import README.Axiom
-- • Category
-- Category theory-inspired idioms used to structure functional
-- programs (functors and monads, for instance).
-- • Codata
-- Coinductive data types and properties. There are two different
-- approaches taken. The `Codata` folder contains the new more
-- standard approach using sized types. The `Codata.Musical`
-- folder contains modules using the old musical notation.
-- • Data
-- Data types and properties.
import README.Data
-- • Function
-- Combinators and properties related to functions.
-- • Foreign
-- Related to the foreign function interface.
-- • Induction
-- A general framework for induction (includes lexicographic and
-- well-founded induction).
-- • IO
-- Input/output-related functions.
-- • Level
-- Universe levels.
-- • Reflection
-- Support for reflection.
-- • Relation
-- Properties of and proofs about relations.
-- • Size
-- Sizes used by the sized types mechanism.
-- • Strict
-- Provides access to the builtins relating to strictness.
------------------------------------------------------------------------
-- A selection of useful library modules
------------------------------------------------------------------------
-- Note that module names in source code are often hyperlinked to the
-- corresponding module. In the Emacs mode you can follow these
-- hyperlinks by typing M-. or clicking with the middle mouse button.
-- • Some data types
import Data.Bool -- Booleans.
import Data.Char -- Characters.
import Data.Empty -- The empty type.
import Data.Fin -- Finite sets.
import Data.List -- Lists.
import Data.Maybe -- The maybe type.
import Data.Nat -- Natural numbers.
import Data.Product -- Products.
import Data.String -- Strings.
import Data.Sum -- Disjoint sums.
import Data.Unit -- The unit type.
import Data.Vec -- Fixed-length vectors.
-- • Some co-inductive data types
import Codata.Stream -- Streams.
import Codata.Colist -- Colists.
-- • Some types used to structure computations
import Category.Functor -- Functors.
import Category.Applicative -- Applicative functors.
import Category.Monad -- Monads.
-- • Equality
-- Propositional equality:
import Relation.Binary.PropositionalEquality
-- Convenient syntax for "equational reasoning" using a preorder:
import Relation.Binary.Reasoning.Preorder
-- Solver for commutative ring or semiring equalities:
import Algebra.Solver.Ring
-- • Properties of functions, sets and relations
-- Monoids, rings and similar algebraic structures:
import Algebra
-- Negation, decidability, and similar operations on sets:
import Relation.Nullary
-- Properties of homogeneous binary relations:
import Relation.Binary
-- • Induction
-- An abstraction of various forms of recursion/induction:
import Induction
-- Well-founded induction:
import Induction.WellFounded
-- Various forms of induction for natural numbers:
import Data.Nat.Induction
-- • Support for coinduction
import Codata.Musical.Notation
import Codata.Thunk
-- • IO
import IO
------------------------------------------------------------------------
-- Record hierarchies
------------------------------------------------------------------------
-- When an abstract hierarchy of some sort (for instance semigroup →
-- monoid → group) is included in the library the basic approach is to
-- specify the properties of every concept in terms of a record
-- containing just properties, parameterised on the underlying
-- operations, sets etc.:
--
-- record IsSemigroup {A} (≈ : Rel A) (∙ : Op₂ A) : Set where
-- open FunctionProperties ≈
-- field
-- isEquivalence : IsEquivalence ≈
-- assoc : Associative ∙
-- ∙-cong : ∙ Preserves₂ ≈ ⟶ ≈ ⟶ ≈
--
-- More specific concepts are then specified in terms of the simpler
-- ones:
--
-- record IsMonoid {A} (≈ : Rel A) (∙ : Op₂ A) (ε : A) : Set where
-- open FunctionProperties ≈
-- field
-- isSemigroup : IsSemigroup ≈ ∙
-- identity : Identity ε ∙
--
-- open IsSemigroup isSemigroup public
--
-- Note here that `open IsSemigroup isSemigroup public` ensures that the
-- fields of the isSemigroup record can be accessed directly; this
-- technique enables the user of an IsMonoid record to use underlying
-- records without having to manually open an entire record hierarchy.
-- This is not always possible, though. Consider the following definition
-- of preorders:
--
-- record IsPreorder {A : Set}
-- (_≈_ : Rel A) -- The underlying equality.
-- (_∼_ : Rel A) -- The relation.
-- : Set where
-- field
-- isEquivalence : IsEquivalence _≈_
-- -- Reflexivity is expressed in terms of an underlying equality:
-- reflexive : _≈_ ⇒ _∼_
-- trans : Transitive _∼_
--
-- module Eq = IsEquivalence isEquivalence
--
-- ...
--
-- The Eq module in IsPreorder is not opened publicly, because it
-- contains some fields which clash with fields or other definitions
-- in IsPreorder.
-- Records packing up properties with the corresponding operations,
-- sets, etc. are also defined:
--
-- record Semigroup : Set₁ where
-- infixl 7 _∙_
-- infix 4 _≈_
-- field
-- Carrier : Set
-- _≈_ : Rel Carrier
-- _∙_ : Op₂ Carrier
-- isSemigroup : IsSemigroup _≈_ _∙_
--
-- open IsSemigroup isSemigroup public
--
-- setoid : Setoid
-- setoid = record { isEquivalence = isEquivalence }
--
-- record Monoid : Set₁ where
-- infixl 7 _∙_
-- infix 4 _≈_
-- field
-- Carrier : Set
-- _≈_ : Rel Carrier
-- _∙_ : Op₂ Carrier
-- ε : Carrier
-- isMonoid : IsMonoid _≈_ _∙_ ε
--
-- open IsMonoid isMonoid public
--
-- semigroup : Semigroup
-- semigroup = record { isSemigroup = isSemigroup }
--
-- open Semigroup semigroup public using (setoid)
--
-- Note that the Monoid record does not include a Semigroup field.
-- Instead the Monoid /module/ includes a "repackaging function"
-- semigroup which converts a Monoid to a Semigroup.
-- The above setup may seem a bit complicated, but we think it makes the
-- library quite easy to work with, while also providing enough
-- flexibility.
------------------------------------------------------------------------
-- More documentation
------------------------------------------------------------------------
-- Examples of how decidability is handled in the library.
import README.Decidability
-- Some examples showing how the case expression can be used.
import README.Case
-- Some examples showing how combinators can be used to emulate
-- "functional reasoning"
import README.Function.Reasoning
-- An example showing how to use the debug tracing mechanism to inspect
-- the behaviour of compiled Agda programs.
import README.Debug.Trace
-- An exploration of the generic programs acting on n-ary functions and
-- n-ary heterogeneous products
import README.Nary
-- Explaining the inspect idiom: use case, equivalent handwritten
-- auxiliary definitions, and implementation details.
import README.Inspect
-- Explaining string formats and the behaviour of printf
import README.Text.Printf
-- Showcasing the pretty printing module
import README.Text.Pretty
-- Explaining how to display tables of strings:
import README.Text.Tabular
-- Explaining how to display a tree:
import README.Text.Tree
------------------------------------------------------------------------
-- Core modules
------------------------------------------------------------------------
-- Some modules have names ending in ".Core". These modules are
-- internal, and have (mostly) been created to avoid mutual recursion
-- between modules. They should not be imported directly; their
-- contents are reexported by other modules.
------------------------------------------------------------------------
-- All library modules
------------------------------------------------------------------------
-- For short descriptions of every library module, see Everything;
-- to exclude unsafe modules, see EverythingSafe:
import Everything
import EverythingSafe
-- Note that the Everything* modules are generated automatically. If
-- you have downloaded the library from its Git repository and want
-- to type check README then you can (try to) construct Everything by
-- running "cabal install && GenerateEverything".
-- Note that all library sources are located under src or ffi. The
-- modules README, README.* and Everything are not really part of the
-- library, so these modules are located in the top-level directory
-- instead.