| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- An explanation about how data types are laid out in the standard |
| 5 |
-- library. |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --sized-types --guardedness #-} |
| 9 |
|
| 10 |
module README.Data where |
| 11 |
|
| 12 |
-- The top-level folder `Data` contains all the definitions of datatypes |
| 13 |
-- and their associated properties. |
| 14 |
|
| 15 |
-- Datatypes can broadly split into two categories |
| 16 |
-- i) "Basic" datatypes which do not take other datatypes as generic |
| 17 |
-- arguments (Nat, String, Fin, Bool, Char etc.) |
| 18 |
-- ii) "Container" datatypes which take other generic datatypes as |
| 19 |
-- arguments, (List, Vec, Sum, Product, Maybe, AVL trees etc.) |
| 20 |
|
| 21 |
------------------------------------------------------------------------ |
| 22 |
-- Basic datatypes |
| 23 |
------------------------------------------------------------------------ |
| 24 |
|
| 25 |
-- Basic datatypes are usually organised as follows: |
| 26 |
|
| 27 |
|
| 28 |
-- 1. A `Base` module which either contains the definition of the |
| 29 |
-- datatype or reimports it from the builtin modules, along with common |
| 30 |
-- functions, operations and relations over elements of the datatype. |
| 31 |
|
| 32 |
import Data.Nat.Base |
| 33 |
import Data.Integer.Base |
| 34 |
import Data.Char.Base |
| 35 |
import Data.String.Base |
| 36 |
import Data.Bool.Base |
| 37 |
|
| 38 |
-- Commonly these modules don't need to be imported directly as their |
| 39 |
-- contents is re-exported by the top level module (see below). |
| 40 |
|
| 41 |
|
| 42 |
-- 2. A `Properties` module which contains the basic properties of the |
| 43 |
-- functions, operations and relations contained in the base module. |
| 44 |
|
| 45 |
import Data.Nat.Properties |
| 46 |
import Data.Integer.Properties |
| 47 |
import Data.Char.Properties |
| 48 |
import Data.String.Properties |
| 49 |
import Data.Bool.Properties |
| 50 |
|
| 51 |
|
| 52 |
-- 3. A top-level module which re-exports the contents of the base |
| 53 |
-- module as well as various queries (i.e. decidability proofs) from the |
| 54 |
-- properties file. |
| 55 |
|
| 56 |
import Data.Nat |
| 57 |
import Data.Integer |
| 58 |
import Data.Char |
| 59 |
import Data.String |
| 60 |
import Data.Bool |
| 61 |
|
| 62 |
|
| 63 |
-- 4. A `Solver` module (for those datatypes that have an algebraic solver) |
| 64 |
-- which can be used to automatically solve equalities over the basic datatype. |
| 65 |
|
| 66 |
import Data.Nat.Solver |
| 67 |
import Data.Integer.Solver |
| 68 |
import Data.Bool.Solver |
| 69 |
|
| 70 |
|
| 71 |
-- 5. More complex operations and relations are commonly found in their |
| 72 |
-- own module beneath the top-level directory. For example: |
| 73 |
|
| 74 |
import Data.Nat.DivMod |
| 75 |
import Data.Integer.Coprimality |
| 76 |
|
| 77 |
-- Note that eventually there is a plan to re-organise the library to |
| 78 |
-- have the top-level module export a far wider range of properties and |
| 79 |
-- additional operations in order to minimise the number of imports |
| 80 |
-- needed. Currently it is necessary to import each of these separately |
| 81 |
-- however. |
| 82 |
|
| 83 |
------------------------------------------------------------------------ |
| 84 |
-- Container datatypes |
| 85 |
------------------------------------------------------------------------ |
| 86 |
|
| 87 |
-- 1. As with basic datatypes, a `Base` module which contains the |
| 88 |
-- definition of the datatype, along with common functions and |
| 89 |
-- operations over that data. Unlike basic datatypes, the `Base` module |
| 90 |
-- for container datatypes does not export any relations or predicates |
| 91 |
-- over the datatype (see the `Relation` section below). |
| 92 |
|
| 93 |
import Data.List.Base |
| 94 |
import Data.Maybe.Base |
| 95 |
import Data.Sum.Base |
| 96 |
|
| 97 |
-- Commonly these modules don't need to be imported directly as their |
| 98 |
-- contents is re-exported by the top level module (see below). |
| 99 |
|
| 100 |
|
| 101 |
-- 2. As with basic datatypes, a `Properties` module which contains the |
| 102 |
-- basic properties of the functions, operations and contained in the |
| 103 |
-- base module. |
| 104 |
|
| 105 |
import Data.List.Properties |
| 106 |
import Data.Maybe.Properties |
| 107 |
import Data.Sum.Properties |
| 108 |
|
| 109 |
|
| 110 |
-- 3. As with basic datatypes, a top-level module which re-exports the |
| 111 |
-- contents of the base module. In some cases this may also contain |
| 112 |
-- additional functions which could not be placed into the corresponding |
| 113 |
-- Base module because of cyclic dependencies. |
| 114 |
|
| 115 |
import Data.List |
| 116 |
import Data.Maybe |
| 117 |
import Data.Sum |
| 118 |
|
| 119 |
|
| 120 |
-- 4. A `Relation.Binary` folder where binary relations over the datatypes |
| 121 |
-- are stored. Because relations over container datatypes often depend on |
| 122 |
-- relations over the parameter datatype, this differs from basic datatypes |
| 123 |
-- where the binary relations are usually defined in the `Base` module, e.g. |
| 124 |
-- equality over the type `List A` depends on equality over type `A`. |
| 125 |
|
| 126 |
-- For example the `Pointwise` relation that takes a relation over the |
| 127 |
-- underlying type A and lifts it to the container parameterised can be found |
| 128 |
-- as follows: |
| 129 |
|
| 130 |
import Data.List.Relation.Binary.Pointwise |
| 131 |
import Data.Maybe.Relation.Binary.Pointwise |
| 132 |
import Data.Sum.Relation.Binary.Pointwise |
| 133 |
|
| 134 |
-- Another useful subfolder in the `Data.X.Relation.Binary` folders is the |
| 135 |
-- `Data.X.Relation.Binary.Equality` folder which contains various forms of |
| 136 |
-- equality over the datatype. |
| 137 |
|
| 138 |
|
| 139 |
-- 5. A `Relation.Unary` folder where unary relations, or predicates, |
| 140 |
-- over the datatypes are stored. These can be viewed as properties |
| 141 |
-- over a single list. |
| 142 |
|
| 143 |
-- For example a common, useful example is `Data.X.Relation.Unary.Any` |
| 144 |
-- that contains the types of proofs that at least one element in the |
| 145 |
-- container satisfies some predicate/property. |
| 146 |
|
| 147 |
import Data.List.Relation.Unary.Any |
| 148 |
import Data.Vec.Relation.Unary.Any |
| 149 |
import Data.Maybe.Relation.Unary.Any |
| 150 |
|
| 151 |
-- Alternatively the `Data.X.Relation.Unary.All` module contains the |
| 152 |
-- type of proofs that all elements in the container satisfy some |
| 153 |
-- property. |
| 154 |
|
| 155 |
import Data.List.Relation.Unary.All |
| 156 |
import Data.Vec.Relation.Unary.All |
| 157 |
import Data.Maybe.Relation.Unary.All |
| 158 |
|
| 159 |
|
| 160 |
-- 6. An `Effectful` module/folder that contains effectful |
| 161 |
-- interpretations of the datatype. |
| 162 |
|
| 163 |
import Data.List.Effectful |
| 164 |
import Data.Maybe.Effectful |
| 165 |
import Data.Sum.Effectful.Left |
| 166 |
import Data.Sum.Effectful.Right |
| 167 |
|
| 168 |
|
| 169 |
-- 7. A `Function` folder that contains lifting of various types of |
| 170 |
-- functions (e.g. injections, surjections, bijections, inverses) to |
| 171 |
-- the datatype. |
| 172 |
|
| 173 |
import Data.Sum.Function.Propositional |
| 174 |
import Data.Sum.Function.Setoid |
| 175 |
import Data.Product.Function.Dependent.Propositional |
| 176 |
import Data.Product.Function.Dependent.Setoid |
| 177 |
|
| 178 |
|
| 179 |
------------------------------------------------------------------------ |
| 180 |
-- Full list of documentation for the Data folder |
| 181 |
------------------------------------------------------------------------ |
| 182 |
|
| 183 |
-- Some examples showing where the natural numbers/integers and some |
| 184 |
-- related operations and properties are defined, and how they can be |
| 185 |
-- used: |
| 186 |
|
| 187 |
import README.Data.Nat |
| 188 |
import README.Data.Nat.Induction |
| 189 |
|
| 190 |
import README.Data.Integer |
| 191 |
|
| 192 |
-- Some examples showing how the AVL tree module can be used. |
| 193 |
|
| 194 |
import README.Data.Tree.AVL |
| 195 |
|
| 196 |
-- Some examples showing how List module can be used. |
| 197 |
|
| 198 |
import README.Data.List |
| 199 |
|
| 200 |
-- Some examples showing how the Fresh list can be used. |
| 201 |
|
| 202 |
import README.Data.List.Fresh |
| 203 |
|
| 204 |
-- Example of an encoding of record types with manifest fields and "with". |
| 205 |
|
| 206 |
import README.Data.Record |
| 207 |
|
| 208 |
-- Example use case for a trie: a wee generic lexer |
| 209 |
|
| 210 |
import README.Data.Trie.NonDependent |
| 211 |
|
| 212 |
-- Examples of equational reasoning about vectors of non-definitionally |
| 213 |
-- equal lengths. |
| 214 |
|
| 215 |
import README.Data.Vec.Relation.Binary.Equality.Cast |
| 216 |
|
| 217 |
-- Examples how (indexed) containers and constructions over them (free |
| 218 |
-- monad, least fixed point, etc.) can be used |
| 219 |
|
| 220 |
import README.Data.Container.FreeMonad |
| 221 |
import README.Data.Container.Indexed.VectorExample |
| 222 |
import README.Data.Container.Indexed.MultiSortedAlgebraExample |
| 223 |
|
| 224 |
-- Wrapping n-ary relations into a record definition so type-inference |
| 225 |
-- remembers the things being related. |
| 226 |
|
| 227 |
import README.Data.Wrap |
| 228 |
|
| 229 |
-- Specifying the default value a function's argument should take if it |
| 230 |
-- is not passed explicitly. |
| 231 |
|
| 232 |
import README.Data.Default |