@@ -61,9 +61,9 @@ that can be used to prove simple properties of Idris programs.
61
61
62
62
One unusual aspect of Coq is that its set of built-in features is _extremely_
63
63
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 .
67
67
68
68
Naturally, the Coq distribution comes with an extensive standard library
69
69
providing definitions of booleans , numbers, and many common data structures like
@@ -153,7 +153,7 @@ definition.
153
153
Having defined a function , we should check that it works on some examples. There
154
154
are actually three different .ways to do this in Idris .
155
155
156
- First, we can evalute an expression involving `nextWeekday` in a REPL.
156
+ First, we can evaluate an expression involving `nextWeekday` in a REPL.
157
157
158
158
```idris
159
159
λΠ> nextWeekday Friday
@@ -226,13 +226,20 @@ members `False` and `True`.
226
226
227
227
```idris
228
228
||| 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 (which is more powerful ):
234
+
235
+ ```idris
229
236
data Bool : Type where
230
237
True : Bool
231
238
False : Bool
232
239
```
233
240
234
241
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
242
+ everything from scratch, Idris does , of course , provide a default
236
243
implementation of the booleans in its standard library , together with a
237
244
multitude of useful functions and lemmas . (Take a look at `Prelude` in the Idris
238
245
library documentation if you're interested.) Whenever possible , we'll name our
@@ -272,7 +279,7 @@ truth table -- for the `orb` function:
272
279
-- TODO: Edit this
273
280
274
281
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
282
+ just defined . The `syntax` command defines a new notation for an existing
276
283
definition, and `infixl` specifies left -associative fixity .
277
284
\color{black}
278
285
@@ -291,10 +298,10 @@ definition, and `infixl` specifies left-associative fixity.
291
298
292
299
=== Exercises: 1 star (nandb)
293
300
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`.
301
+ Fill in the hole `?nandb_rhs` and complete the following function; then make
302
+ sure that the assertions below can each be verified by Idris. (Fill in each of
303
+ the holes , following the model of the `orb` tests above .) The function should
304
+ return `True` if either or both of its inputs `False`.
298
305
299
306
> nandb : (b1 : Bool) -> (b2 : Bool) -> Bool
300
307
> nandb b1 b2 = ?nandb_rhs
@@ -348,7 +355,7 @@ For example, the type of `negb True` is `Bool`.
348
355
```idris
349
356
λΠ> :type True
350
357
-- True : Bool
351
- λΠ> :t negb True : Bool
358
+ λΠ> :t negb True
352
359
-- negb True : Bool
353
360
```
354
361
@@ -385,9 +392,9 @@ Idris provides a _module system_, to aid in organizing large developments.
385
392
> namespace Numbers
386
393
387
394
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 :
395
+ definitions explicitly enumerate a finite set of elements . A More interesting
396
+ way of defining a type is to give a collection of _inductive rules_ describing
397
+ its elements . For example , we can define the natural numbers as follows :
391
398
392
399
```idris
393
400
data Nat : Type where
@@ -461,7 +468,7 @@ These are all things that can be applied to a number to yield a number. However,
461
468
there is a fundamental difference between the first one and the other two:
462
469
functions like `pred` and `minusTwo` come with _computation rules_ -- e.g., the
463
470
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
471
+ definition of `S` has no such behavior attached. Although it is like a function
465
472
in the sense that it can be applied to an argument, it does not _do_ anything at
466
473
all!
467
474
@@ -489,7 +496,7 @@ definition that is a bit easier to work with:
489
496
> testOddb2 : oddb 4 = False
490
497
> testOddb2 = Refl
491
498
492
- Naturally we can also define multi -argument functions by recursion .
499
+ Naturally, we can also define multi-argument functions by recursion .
493
500
494
501
> namespace Playground2
495
502
> plus : (n : Nat) -> (m : Nat) -> Nat
@@ -532,7 +539,7 @@ mult (S k) = plus m (mult k m)
532
539
> testMult1 : (mult 3 3) = 9
533
540
> testMult1 = Refl
534
541
535
- You can match two expression at once:
542
+ You can match two expressions at once:
536
543
537
544
```idris
538
545
minus : (n, m : Nat) -> Nat
@@ -680,19 +687,14 @@ Other similar theorems can be proved with the same pattern.
680
687
> mult_0_l : (n : Nat) -> 0 * n = 0
681
688
> mult_0_l n = Refl
682
689
683
- The `_l` suffix in the names of these theorems is pronounces "on the left."
690
+ The `_l` suffix in the names of these theorems is pronounced "on the left."
684
691
685
692
Although simplification is powerful enough to prove some fairly general facts,
686
693
there are many statements that cannot be handled by simplification alone. For
687
694
instance, we cannot use it to prove that `0` is also a neutral element for `+`
688
695
_on the right_.
689
696
690
697
691
- ```idris
692
- plus_n_Z : (n : Nat) -> n = n + 0
693
- plus_n_Z n = Refl
694
- ```
695
-
696
698
```idris
697
699
plus_n_Z : (n : Nat) -> n = n + 0
698
700
plus_n_Z n = Refl
@@ -719,6 +721,11 @@ The next chapter will introduce _induction_, a powerful technique that can be
719
721
used for proving this goal. For the moment, though, let's look at a few more
720
722
simple tactics .
721
723
724
+
725
+ == Proof by Rewriting
726
+
727
+ This theorem is a bit more interesting than the others we've seen :
728
+
722
729
> plus_id_example : (n, m : Nat) -> (n = m)
723
730
> -> n + n = m + m
724
731
0 commit comments