Skip to content

Commit c4b1d6b

Browse files
Addressed 2nd round of Nils' feedback
1 parent e292421 commit c4b1d6b

File tree

1 file changed

+36
-42
lines changed

1 file changed

+36
-42
lines changed

paper/paper.md

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ authors:
1010
orcid: 0000-0002-2552-3671
1111
corresponding: true
1212
affiliation: 1
13+
- name: Danielsson, Nils Anders
14+
affliation: 11
1315
- name: Allais, Guillaume
1416
orcid: 0000-0002-4091-657X
1517
affiliation: 2
@@ -54,8 +56,6 @@ authors:
5456
- name: Kokke, Wen
5557
orcid: 0000-0002-1662-0381
5658
affiliation: 7
57-
- name: Others to come
58-
affiliation: 100
5959
affiliations:
6060
- name: University of Western Australia, Australia
6161
index: 1
@@ -77,14 +77,12 @@ affiliations:
7777
index: 9
7878
- name: Russian Academy of Sciences, Russia
7979
index: 10
80-
- name: University of Gothenburg, Sweden
80+
- name: University of Gothenburg and Chalmers University of Technology, Sweden
8181
index: 11
8282
- name : Northwestern University, USA
8383
index: 12
8484
- name : Huawei Technologies Research & Development, United Kingdom
8585
index: 13
86-
- name: UNKNOWN
87-
index: 100
8886
date: 24 September 2024
8987
bibliography: paper.bib
9088
---
@@ -101,23 +99,23 @@ Through the Curry-Howard lens [@DBLP:journals/cacm/Wadler15],
10199
these types and programs can be seen respectively as theorem
102100
statements and proofs.
103101

104-
This paper presents the Agda standard library [@agda-stdlib-v2.0], hereafter referred to as `agda-stdlib`, which offers fundamental definitions necessary for users to quickly begin developing Agda programs and proofs.
105-
Unlike the standard libraries of traditional programming languages, `agda-stdlib` provides not only standard utilities and data structures, but also a substantial portion of the basic discrete mathematics essential for proving the correctness of programs.
102+
This paper presents the Agda standard library [@agda-stdlib-v2.0], hereafter referred to as `agda-stdlib`, which provides definitions intended to be helpful for users to develop Agda programs and proofs.
103+
Unlike the standard libraries of traditional programming languages, `agda-stdlib` provides not only standard utilities and data structures, but also a range of basic discrete mathematics useful for proving the correctness of programs.
106104

107105
# Statement of need
108106

109107
Most programming languages include a "standard" library offering a basic set of algorithms, data structures, and operating system procedures.
110-
However, there are two reasons why a standard library is more important for Agda compared to traditional programming languages.
108+
However, there are two reasons why a standard library is particularly significant for Agda compared to traditional programming languages.
111109

112110
First, like other theorem provers, the Agda language provides only a small set of primitives from which programs can be constructed.
113111
As a result, many concepts traditionally considered part of a language must be defined within the program itself.
114112
This approach reduces compiler complexity and enhances its reliability, and also demonstrates the strength of the core Agda language as it can push these concepts out to the library.
115113
For example, in a fresh Agda environment, there is no predefined notion of an integer, let alone more complex data structures such as vectors or maps.
116-
This lack of basic data types increases the need for a standard library when compared to more main stream languages.
114+
This lack of basic data types increases the need for a standard library when compared to more mainstream languages.
117115

118-
Second, Agda users often seek to prove that programs constructed using data types from the standard library are "correct."
119-
Therefore, the standard library provides both operations over these data types _and_ proofs of their basic properties (e.g., that integer addition is commutative or list concatenation is associative).
120-
Starting from just the Agda language, something as simple as defining a function to sort a list and proving that it preserves the length of its input would require hundreds of lines of code.
116+
Second, Agda users often seek to prove that programs constructed using data types in the standard library are "correct."
117+
Constructing the proof that a function obeys a specification (e.g. that a sorting function outputs a permutation of the original list in non-decreasing order) typically requires far more effort, both in terms of lines of code and in developer time, than writing the original operation.
118+
By frequently providing proofs of correctness for the operations it defines, the standard library saves users significant time during proof development.
121119

122120
# Impact
123121

@@ -136,65 +134,62 @@ In the list below we present a selection of such projects:
136134

137135
- Verification of routing protocols [@daggitt2023routing]
138136

139-
The development of `agda-stdlib` has also had a synergistic relationship with that of Agda itself, prompting the implementation of several new language features, which we now discuss.
137+
The library has also been used as a test bed for the design of co-inductive data types in Agda itself, as evidenced by the three different notions of co-inductive data present in the library.
140138

141-
First, Agda is a research compiler supporting a wide range of not necessarily inter-compatible language extensions via command line options.
139+
On occasion, the development of `agda-stdlib` has also had a synergistic relationship with that of Agda itself, prompting the implementation of several new language features, which we now discuss.
140+
Firstly, Agda is a research compiler supporting a wide range of not necessarily inter-compatible language extensions via command line options.
142141
Examples include `--cubical` (changing the underlying type theory to cubical type theory [@DBLP:journals/jfp/VezzosiMA21]),
143142
`--with-K` (adding support for Streicher's axiom K [@streicher1993investigations], a reasoning principle incompatible with the `--cubical`-enabled type theory),
144-
or `--safe` (an ITP-oriented option enforcing that nothing is postulated and consequently disabling the FFI mechanism).
143+
or `--safe` (an ITP-oriented option enforcing that nothing is postulated and disabling parts of the FFI mechanism).
145144
In order for `agda-stdlib` to be compatible with as many different compiler options as possible, we designed the library to be broken into units
146145
requesting the minimal expressive power needed.
147-
To enable this, in 2019 Agda allowed language options to be categorised into "infective", "coinfective" and "neither".
146+
To enable this, in 2019 Agda's language options were categorised as "infective", "coinfective" or "neither".
148147
Once used in a module, an "infective" option will impact all the import*ing* modules; these are typically for theory-changing options like `--cubical` or `--with-K`.
149148
On the contrary, "coinfective" options affect the import*ed* modules; these are typically for options adding extra safety checks like `--safe`.
150149
This categorisation enables libraries to integrate safe Agda code with code that uses unsafe operating system calls, while maintaining the safety guarantees of the former.
151-
152-
Second, the development of `agda-stdlib` motivated adding the ability to attach custom messages to definitions, which are then displayed by the compiler when the definitions are used. This enabled the implementation of deprecation warnings amongst other features, and lets end-users more easily evolve their code alongside new versions of `agda-stdlib`.
153-
Thirdly, `agda-stdlib` has been used as a test bed for the design of co-inductive data types, as evidenced by the three different otions of co-inductive data present in the library.
150+
Secondly, the development of `agda-stdlib` motivated adding the ability to attach custom messages to definitions, which are then displayed by the compiler when the definitions are used.
151+
This enabled the implementation of deprecation warnings, which makes it easier for end-users to evolve their code alongside new versions of `agda-stdlib`.
154152

155153
# Design
156154

157155
Designing a standard library for an ITP such as Agda presents several challenges.
158156

159-
Firstly, as discussed, `agda-stdlib` contains much of the basic mathematics useful for proving program correctness.
160-
While the focus on discrete mathematics and algebra reflects the bias in its user base towards programming language theory, organising this material into a coherent and logical structure is difficult, though some recent efforts exist in this direction [@carette2020leveraging] [@cohen2020hierarchy].
161-
There is constant tension between being as general as possible (e.g., defining operations over general algebraic structures) and providing clear, straightforward, and intuitive definitions (e.g., defining operations concretely over integers).
157+
Firstly, as discussed, `agda-stdlib` contains the basic discrete mathematics and algebra useful for proving program correctness (the lack of continuous mathematics reflects the bias in its user base towards programming language theory).
158+
Organising this material into a coherent and logical structure is difficult, although some recent efforts have looked at generating such structure mechanistically [@carette2020leveraging] [@cohen2020hierarchy].
159+
The main tension in organising the material is between being as general as possible (e.g., defining subtraction using addition and inverse over some abstract algebraic structure) and providing clear, straightforward, and intuitive definitions (e.g., defining subtraction directly over integers).
162160
Additionally, there is the temptation to introduce new representations of existing mathematical objects that are easier to work with for a particular application, which comes at the cost of duplicating the theory for the new representation.
163-
Theorem provers like Isabelle [@paulson1994isabelle] and Coq [@coq2024manual] have very minimal standard libraries and encouraging the use of external libraries developed by the community, which reduces the emphasis on ensuring the existence of canonical definitions for certain concepts, at the cost of lack of interoperability between various packages.
161+
Some theorem provers such as Coq [@coq2024manual] have comparatively small standard libraries and a rich ecosystem of external libraries, which reduces the emphasis on ensuring the existence of canonical definitions for common concepts, at the slightly increased risk of incompatibilities between various libraries.
164162
On the other hand, MathLib [@van2020maintaining] for Lean provides a repository of canonical definitions.
165-
Philisophically, `agda-stdlib` is more closely aligned with the approach of the MathLib community, and aims to provide canonical definitions for mathematical objects and introduce new representations only sparingly.
163+
Philisophically, `agda-stdlib` is more closely aligned with the approach of the MathLib library, and aims to provide canonical definitions for mathematical objects and introduce new representations only sparingly.
166164

167165
A second challenge is that Agda was the first major ITP to fully embrace dependently-typed programming as the default.
168-
With the exception of Idris, a more recent entrant to the field [@brady2013idris], either other major theorem provers do not support dependent types or their communities and libraries encourage their use only sparingly.
169-
In contrast, nearly everything in `agda-stdlib` makes use of dependent types, with correctness-related invariants being closely integrated with definitions.
170-
For example, we can specify that `reverse` defined on length-indexed vectors is length-preserving *by virtue of its type*.
171-
Furthermore, most proofs consist of evidence-bearing terms for the relevant types and therefore can themselves be computed on.
172-
By using dependent types, the library provides sophisticated features like polymorphic n-ary functions [@allais2019generic] and regular expressions which provide proof of membership when compiled and applied.
173-
While widespread use of dependent types provides powerful tools for users, learning how to design a large, dependently-typed library is an ongoing journey, and we believe the Agda standard library has been one of the first such standard libraries to tackle the challenge.
174-
175-
Another significant influence on the design of the standard library is Agda’s module system [@ivardeBruin2023].
166+
Many definitions in `agda-stdlib` makes use of instrinsic dependent types, with correctness-related invariants being defined as part of, rather than after, the main definition.
167+
Furthermore, the proofs of the invariants are evidence-bearing terms for the relevant types and therefore can themselves be computed on.
168+
For example, the final definition of a rational number is a record that alongside the numerator and denominator, contains a third term that proves that the numerator and denominator have no common factors.
169+
Using this approach, `agda-stdlib` implements features such as polymorphic n-ary functions [@allais2019generic] and regular expressions which provide proof of membership when compiled and applied.
170+
While the widespread use of dependent types provides powerful tools for enforcing code invariants, learning how to design a large, dependently-typed library is an ongoing journey, and we believe the Agda standard library has been one of the first such standard libraries to tackle the challenge.
171+
172+
Another significant influence on the design of the standard library is Agda’s module system [@ivardeBruin2023] which support lists of parameters whose types are dependent on the value of parameters earlier in the list.
176173
Many functional languages, such as Haskell [@haskell2010], and ITP libraries, like Lean's MathLib, use type classes as the primary mechanism for ad-hoc polymorphism and overloading syntax.
177-
While Agda supports a more general form of type-classes via instances [@devriese2011bright], we have found that the use of qualified, parameterised modules can reproduce most of the abstraction capabilities of type-classes.
178-
In particular, Agda modules support lists of parameters whose types are dependent on the value of parameters earlier in the list.
179-
The main benefits of using such modules instead of type-classes, is that it allows users to explicitly describe which objects are being used to instantiate the abstract code and reduces the risk of time-consuming searches at type-checking time.
180-
The main drawback is that users may sometimes need to use qualified imports when instantiating the abstract code twice in the same scope.
174+
While Agda supports an alternative to type-classes known as instance arguments [@devriese2011bright], we have found that the use of qualified, parameterised modules can reproduce most of the capabilities of instances/type-classes to abstract operations over unknown types.
175+
The main benefits of using parameterised modules instead of type-classes is that it allows users to explicitly specify which objects are being used to instantiate the abstract code and removes the overhead of instance search at type-checking time.
176+
The main drawback is that users may sometimes need to use qualified imports or other similar mechanisms when instantiating the abstract code twice in the same scope.
181177
Another benefit of parameterised modules in the design of `agda-stdlib`, is that they have facilitated the safe and scalable embedding of non-constructive mathematics into what is primarily a constructive library.
182178
Non-constructive operations, such as classical reasoning, can be made available by passing the operations as parameters to the current module, allowing code access to them throughout the module.
183-
This enables users to write non-constructive code, without either having to postulate the axioms (which would incompatible with the `--safe` flag), or explicitly pass them through as arguments to every function in the module.
179+
This enables users to write non-constructive code, without either having to postulate axioms incompatible with the `--safe` flag, or explicitly pass them through as arguments to every function in the module.
184180

185181
# Testing
186182

187-
In ITPs, correctness proofs are regarded as an integral part of creating a collection of operations.
188-
One of the advantages of this approach is that the need for test suites that verify functional correctness is reduced.
183+
Many of the core operations in `agda-stdlib` are accompanied by correctness proofs, and consequently the need for test suites that verify functional correctness is reduced.
189184
However the library’s tests do cover two critical areas.
190185
Firstly, correctness of bindings to an external library or the underlying OS primitives cannot be reasoned about in Agda itself.
191186
Therefore functions that use the foreign function interface with the underlying operating system (e.g., reading from the command line, file access, timers) and tactics that use Agda macros, are still tested in the library's test suite.
192-
Secondly, performance of type-checking and compiled code cannot be analysed inside Agda itself, making it necessary for the library include performance tests.
187+
Secondly, performance of type-checking and compiled code cannot be analysed inside Agda itself, making it necessary for the library to include performance tests.
193188
This part of the library's test suite is sparser, as this has not yet been a major priority for the community.
194189

195190
# Notable achievements in version 2.0
196191

197-
Finally, we will briefly discuss the state of `agda-stdlib` version 2.0 [@agda-stdlib-v2.0] for which HTML-annotated sources are available at \url{https://agda.github.io/agda-stdlib/v2.0/}).
192+
Finally, we will briefly discuss the state of `agda-stdlib` version 2.0 [@agda-stdlib-v2.0] for which HTML-annotated sources are available at \url{https://agda.github.io/agda-stdlib/v2.0/}.
198193
We believe we have successfully addressed some of the design flaws and missing functionality present in versions 1.0-1.7, including:
199194

200195
- Minimised Dependency Graphs: We have reduced the depth of dependency graphs within the library, ensuring that the most commonly used modules rely on fewer parts of the library. This change has resulted in significantly faster load times for users during interactive development.
@@ -208,7 +203,6 @@ We believe we have successfully addressed some of the design flaws and missing f
208203
# Acknowledgements
209204

210205
We would like to thank the core Agda development team who are not authors on this paper, but nonetheless whose work on Agda makes the standard library possible. This includes, but is not limited to,
211-
Nils Anders Danielsson,
212206
Andrés Sicard-Ramírez,
213207
Jesper Cockx and
214208
Andrea Vezzosi,

0 commit comments

Comments
 (0)