Skip to content

Commit b96c785

Browse files
authored
Merge pull request #7 from clayrat/patch-1
Basics: fix typos, add some explanations
2 parents f784625 + 819dada commit b96c785

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

src/Basics.lidr

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ that can be used to prove simple properties of Idris programs.
6161

6262
One unusual aspect of Coq is that its set of built-in features is _extremely_
6363
small, For example, instead of providing the usual palette of atomic data types
64-
(booleans, integers, strings, etc.), Coq offers a powerl mechanism for defining
65-
new data types from scratch, from which all these familiar types arise as
66-
instances.
64+
(booleans, integers, strings, etc.), Coq offers a powerful mechanism for
65+
defining new data types from scratch, from which all these familiar types arise
66+
as instances.
6767

6868
Naturally, the Coq distribution comes with an extensive standard library
6969
providing definitions of booleans, numbers, and many common data structures like
@@ -153,7 +153,7 @@ definition.
153153
Having defined a function, we should check that it works on some examples. There
154154
are actually three different .ways to do this in Idris.
155155

156-
First, we can evalute an expression involving `nextWeekday` in a REPL.
156+
First, we can evaluate an expression involving `nextWeekday` in a REPL.
157157

158158
```idris
159159
λΠ> nextWeekday Friday
@@ -226,13 +226,23 @@ members `False` and `True`.
226226

227227
```idris
228228
||| Boolean Data Type
229+
data Bool = True | False
230+
```
231+
232+
This definition is written in the simplified style, similar to `Day`. It can
233+
also be written in the verbose style:
234+
235+
```idris
229236
data Bool : Type where
230237
True : Bool
231238
False : Bool
232239
```
233240

241+
The verbose style is more powerful because it allows us to assign precise
242+
types to individual constructors. This will become very useful later on.
243+
234244
Although we are rolling our own booleans here for the sake of building up
235-
everything from scratch, Idiris does, of course, provide a default
245+
everything from scratch, Idris does, of course, provide a default
236246
implementation of the booleans in its standard library, together with a
237247
multitude of useful functions and lemmas. (Take a look at `Prelude` in the Idris
238248
library documentation if you're interested.) Whenever possible, we'll name our
@@ -272,8 +282,8 @@ truth table -- for the `orb` function:
272282
-- TODO: Edit this
273283

274284
We can also introduce some familiar syntax for the boolean operations we have
275-
just defined. The `syntax` command defines new notation for an existing
276-
definition, and `infixl` specifies left-associative fixity.
285+
just defined. The `syntax` command defines a new symbolic notation for an
286+
existing definition, and `infixl` specifies left-associative fixity.
277287
\color{black}
278288

279289
> infixl 4 /\, \/
@@ -291,10 +301,10 @@ definition, and `infixl` specifies left-associative fixity.
291301

292302
=== Exercises: 1 star (nandb)
293303

294-
Fill in the hole `?nandb_rhs` and omplete the following function; then make sure
295-
that the assertions below can each be verified by Idris. (Fill in each of the
296-
holes, following the model of the `orb` tests above.) The function should return
297-
`True` if either or both of its inputs `False`.
304+
Fill in the hole `?nandb_rhs` and complete the following function; then make
305+
sure that the assertions below can each be verified by Idris. (Fill in each of
306+
the holes, following the model of the `orb` tests above.) The function should
307+
return `True` if either or both of its inputs are `False`.
298308

299309
> nandb : (b1 : Bool) -> (b2 : Bool) -> Bool
300310
> nandb b1 b2 = ?nandb_rhs
@@ -348,7 +358,7 @@ For example, the type of `negb True` is `Bool`.
348358
```idris
349359
λΠ> :type True
350360
-- True : Bool
351-
λΠ> :t negb True : Bool
361+
λΠ> :t negb True
352362
-- negb True : Bool
353363
```
354364

@@ -385,9 +395,9 @@ Idris provides a _module system_, to aid in organizing large developments.
385395
> namespace Numbers
386396

387397
The types we have defined so far are examples of "enumerated types": their
388-
definitions explicitly enumerate a finit set of elements. A More interesting way
389-
of defining a type is to give a collection of _inductive rules_ describing its
390-
elements. For example, we can define the natural numbers as follows:
398+
definitions explicitly enumerate a finite set of elements. A More interesting
399+
way of defining a type is to give a collection of _inductive rules_ describing
400+
its elements. For example, we can define the natural numbers as follows:
391401

392402
```idris
393403
data Nat : Type where
@@ -461,7 +471,7 @@ These are all things that can be applied to a number to yield a number. However,
461471
there is a fundamental difference between the first one and the other two:
462472
functions like `pred` and `minusTwo` come with _computation rules_ -- e.g., the
463473
definition of `pred` says that `pred 2` can be simplified to `1` -- while the
464-
definition of `S` has no such behavior attached. Althrough it is like a function
474+
definition of `S` has no such behavior attached. Although it is like a function
465475
in the sense that it can be applied to an argument, it does not _do_ anything at
466476
all!
467477

@@ -489,7 +499,7 @@ definition that is a bit easier to work with:
489499
> testOddb2 : oddb 4 = False
490500
> testOddb2 = Refl
491501

492-
Naturally we can also define multi-argument functions by recursion.
502+
Naturally, we can also define multi-argument functions by recursion.
493503

494504
> namespace Playground2
495505
> plus : (n : Nat) -> (m : Nat) -> Nat
@@ -532,7 +542,7 @@ mult (S k) = plus m (mult k m)
532542
> testMult1 : (mult 3 3) = 9
533543
> testMult1 = Refl
534544

535-
You can match two expression at once:
545+
You can match two expressions at once:
536546

537547
```idris
538548
minus : (n, m : Nat) -> Nat
@@ -680,19 +690,14 @@ Other similar theorems can be proved with the same pattern.
680690
> mult_0_l : (n : Nat) -> 0 * n = 0
681691
> mult_0_l n = Refl
682692

683-
The `_l` suffix in the names of these theorems is pronounces "on the left."
693+
The `_l` suffix in the names of these theorems is pronounced "on the left."
684694

685695
Although simplification is powerful enough to prove some fairly general facts,
686696
there are many statements that cannot be handled by simplification alone. For
687697
instance, we cannot use it to prove that `0` is also a neutral element for `+`
688698
_on the right_.
689699

690700

691-
```idris
692-
plus_n_Z : (n : Nat) -> n = n + 0
693-
plus_n_Z n = Refl
694-
```
695-
696701
```idris
697702
plus_n_Z : (n : Nat) -> n = n + 0
698703
plus_n_Z n = Refl
@@ -719,6 +724,11 @@ The next chapter will introduce _induction_, a powerful technique that can be
719724
used for proving this goal. For the moment, though, let's look at a few more
720725
simple tactics.
721726

727+
728+
== Proof by Rewriting
729+
730+
This theorem is a bit more interesting than the others we've seen:
731+
722732
> plus_id_example : (n, m : Nat) -> (n = m)
723733
> -> n + n = m + m
724734

0 commit comments

Comments
 (0)