@@ -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,23 @@ 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:
234
+
235
+ ```idris
229
236
data Bool : Type where
230
237
True : Bool
231
238
False : Bool
232
239
```
233
240
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
+
234
244
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
236
246
implementation of the booleans in its standard library , together with a
237
247
multitude of useful functions and lemmas . (Take a look at `Prelude` in the Idris
238
248
library documentation if you're interested.) Whenever possible , we'll name our
@@ -272,8 +282,8 @@ truth table -- for the `orb` function:
272
282
-- TODO: Edit this
273
283
274
284
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 .
277
287
\color{black}
278
288
279
289
> infixl 4 /\, \/
@@ -291,10 +301,10 @@ definition, and `infixl` specifies left-associative fixity.
291
301
292
302
=== Exercises: 1 star (nandb)
293
303
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`.
298
308
299
309
> nandb : (b1 : Bool) -> (b2 : Bool) -> Bool
300
310
> nandb b1 b2 = ?nandb_rhs
@@ -348,7 +358,7 @@ For example, the type of `negb True` is `Bool`.
348
358
```idris
349
359
λΠ> :type True
350
360
-- True : Bool
351
- λΠ> :t negb True : Bool
361
+ λΠ> :t negb True
352
362
-- negb True : Bool
353
363
```
354
364
@@ -385,9 +395,9 @@ Idris provides a _module system_, to aid in organizing large developments.
385
395
> namespace Numbers
386
396
387
397
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 :
391
401
392
402
```idris
393
403
data Nat : Type where
@@ -461,7 +471,7 @@ These are all things that can be applied to a number to yield a number. However,
461
471
there is a fundamental difference between the first one and the other two:
462
472
functions like `pred` and `minusTwo` come with _computation rules_ -- e.g., the
463
473
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
465
475
in the sense that it can be applied to an argument, it does not _do_ anything at
466
476
all!
467
477
@@ -489,7 +499,7 @@ definition that is a bit easier to work with:
489
499
> testOddb2 : oddb 4 = False
490
500
> testOddb2 = Refl
491
501
492
- Naturally we can also define multi -argument functions by recursion .
502
+ Naturally, we can also define multi-argument functions by recursion .
493
503
494
504
> namespace Playground2
495
505
> plus : (n : Nat) -> (m : Nat) -> Nat
@@ -532,7 +542,7 @@ mult (S k) = plus m (mult k m)
532
542
> testMult1 : (mult 3 3) = 9
533
543
> testMult1 = Refl
534
544
535
- You can match two expression at once:
545
+ You can match two expressions at once:
536
546
537
547
```idris
538
548
minus : (n, m : Nat) -> Nat
@@ -680,19 +690,14 @@ Other similar theorems can be proved with the same pattern.
680
690
> mult_0_l : (n : Nat) -> 0 * n = 0
681
691
> mult_0_l n = Refl
682
692
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."
684
694
685
695
Although simplification is powerful enough to prove some fairly general facts,
686
696
there are many statements that cannot be handled by simplification alone. For
687
697
instance, we cannot use it to prove that `0` is also a neutral element for `+`
688
698
_on the right_.
689
699
690
700
691
- ```idris
692
- plus_n_Z : (n : Nat) -> n = n + 0
693
- plus_n_Z n = Refl
694
- ```
695
-
696
701
```idris
697
702
plus_n_Z : (n : Nat) -> n = n + 0
698
703
plus_n_Z n = Refl
@@ -719,6 +724,11 @@ The next chapter will introduce _induction_, a powerful technique that can be
719
724
used for proving this goal. For the moment, though, let's look at a few more
720
725
simple tactics .
721
726
727
+
728
+ == Proof by Rewriting
729
+
730
+ This theorem is a bit more interesting than the others we've seen :
731
+
722
732
> plus_id_example : (n, m : Nat) -> (n = m)
723
733
> -> n + n = m + m
724
734
0 commit comments