Skip to content

Commit d293e88

Browse files
author
Alex Gryzlov
committed
Fix signatures for Church exercises, add spaces
1 parent abf078c commit d293e88

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/Poly.lidr

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ polymorphic lists...
304304
> test_rev1 : rev (1::2::[]) = 2::1::[]
305305
> test_rev1 = Refl
306306

307-
> test_rev2: rev (True::[]) = True::[]
307+
> test_rev2 : rev (True::[]) = True::[]
308308
> test_rev2 = Refl
309309

310-
> test_length1: length (1::2::3::[]) = 3
310+
> test_length1 : length (1::2::3::[]) = 3
311311
> test_length1 = Refl
312312

313313

@@ -381,7 +381,7 @@ $\square$
381381

382382
Here are some slightly more interesting ones...
383383

384-
> rev_app_distr: (l1, l2 : List x) -> rev (l1 ++ l2) = rev l2 ++ rev l1
384+
> rev_app_distr : (l1, l2 : List x) -> rev (l1 ++ l2) = rev l2 ++ rev l1
385385
> rev_app_distr l1 l2 = ?rev_app_distr_rhs
386386

387387
> rev_involutive : (l : List x) -> rev (rev l) = l
@@ -544,7 +544,7 @@ The argument `f` here is itself a function (from `x` to `x`); the body of
544544
> test_doit3times : doit3times Numbers.minusTwo 9 = 3
545545
> test_doit3times = Refl
546546

547-
> test_doit3times': doit3times Booleans.negb True = False
547+
> test_doit3times' : doit3times Booleans.negb True = False
548548
> test_doit3times' = Refl
549549

550550

@@ -570,7 +570,8 @@ For example, if we apply `filter` to the predicate `evenb` and a list of numbers
570570
> length_is_1 : (l : List x) -> Bool
571571
> length_is_1 l = beq_nat (length l) 1
572572

573-
\todo[inline]{Why doesn't this work without {x=Nat}?}
573+
\todo[inline]{Why doesn't this work without {x=Nat}? Apparently it even works
574+
with {x=_}!}
574575

575576
> test_filter2 : filter (length_is_1 {x=Nat})
576577
> [ [1,2], [3], [4], [5,6,7], [], [8] ]
@@ -607,15 +608,15 @@ without declaring it at the top level or giving it a name.
607608

608609
\todo[inline]{Can't use `*` here due to the interference from our tuple sugar}
609610

610-
> test_anon_fun': doit3times (\n => mult n n) 2 = 256
611+
> test_anon_fun' : doit3times (\n => mult n n) 2 = 256
611612
> test_anon_fun' = Refl
612613

613614
The expression `\n => mult n n` can be read as "the function that, given a
614615
number `n`, yields `n * n`."
615616

616617
Here is the `filter` example, rewritten to use an anonymous function.
617618

618-
> test_filter2': filter (\l => beq_nat (length l) 1)
619+
> test_filter2' : filter (\l => beq_nat (length l) 1)
619620
> [ [1,2], [3], [4], [5,6,7], [], [8] ]
620621
> = [ [3], [4], [8] ]
621622
> test_filter2' = Refl
@@ -643,7 +644,7 @@ $\square$
643644

644645
Use `filter` to write an Idris function `partition`:
645646

646-
> partition : (test: x -> Bool) -> (l : List x) -> (List x) * (List x)
647+
> partition : (test : x -> Bool) -> (l : List x) -> (List x) * (List x)
647648
> partition f xs = ?partition_rhs
648649

649650
Given a set `x`, a test function of type `x -> Bool` and a `List x`, `partition`
@@ -655,7 +656,7 @@ two sublists should be the same as their order in the original list.
655656
> test_partition1 : partition Numbers.oddb [1,2,3,4,5] = ([1,3,5], [2,4])
656657
> test_partition1 = ?test_partition1_rhs
657658

658-
> test_partition2: partition (\x => false) [5,9,0] = (([], [5,9,0]))
659+
> test_partition2 : partition (\x => false) [5,9,0] = (([], [5,9,0]))
659660
> test_partition2 = ?test_partition2_rhs
660661

661662
$\square$
@@ -712,10 +713,10 @@ by 'flattening' the results of `f`, like so:
712713
flat_map (\n => [n,n+1,n+2]) [1,5,10] = [1,2,3, 5,6,7, 10,11,12]
713714
```
714715

715-
> flat_map : (f: x -> List y) -> (l : List x) -> List y
716+
> flat_map : (f : x -> List y) -> (l : List x) -> List y
716717
> flat_map f l = ?flat_map_rhs
717718

718-
> test_flat_map1: flat_map (\n => [n,n,n]) [1,5,4] = [1,1,1, 5,5,5, 4,4,4]
719+
> test_flat_map1 : flat_map (\n => [n,n,n]) [1,5,4] = [1,1,1, 5,5,5, 4,4,4]
719720
> test_flat_map1 = ?test_flat_map1_rhs
720721

721722
$\square$
@@ -999,21 +1000,21 @@ corresponding unit tests pass by proving them with `Refl`.
9991000

10001001
Successor of a natural number:
10011002

1002-
> succ : (n : Nat') -> Nat'
1003-
> succ n = ?succ_rhs
1003+
> succ' : (n : Nat' {x}) -> Nat' {x}
1004+
> succ' n = ?succ'_rhs
10041005

1005-
> succ_1 : succ zero = one
1006-
> succ_1 = ?succ_1_rhs
1006+
> succ'_1 : succ' zero = one
1007+
> succ'_1 = ?succ_1_rhs
10071008

1008-
> succ_2 : succ one = two
1009-
> succ_2 = ?succ_2_rhs
1009+
> succ'_2 : succ' one = two
1010+
> succ'_2 = ?succ_2_rhs
10101011

1011-
> succ_3 : succ two = three
1012-
> succ_3 = ?succ_3_rhs
1012+
> succ'_3 : succ' two = three
1013+
> succ'_3 = ?succ'_3_rhs
10131014

10141015
Addition of two natural numbers:
10151016

1016-
> plus' : (n, m : Nat') -> Nat'
1017+
> plus' : (n, m : Nat' {x}) -> Nat' {x}
10171018
> plus' n m = ?plus'_rhs
10181019

10191020
> plus'_1 : plus' zero one = one
@@ -1027,7 +1028,7 @@ Addition of two natural numbers:
10271028

10281029
Multiplication:
10291030

1030-
> mult' : (n, m : Nat') -> Nat'
1031+
> mult' : (n, m : Nat' {x}) -> Nat' {x}
10311032
> mult' n m = ?mult'_rhs
10321033

10331034
> mult'_1 : mult' one one = one
@@ -1041,13 +1042,14 @@ Multiplication:
10411042

10421043
Exponentiation:
10431044

1044-
\todo[inline]{Edit the hint.}
1045+
\todo[inline]{Edit the hint. Can't make it work with `exp' : (n, m : Nat' {x})
1046+
-> Nat' {x}`.}
10451047

10461048
(Hint: Polymorphism plays a crucial role here. However, choosing the right type
10471049
to iterate over can be tricky. If you hit a "Universe inconsistency" error, try
10481050
iterating over a different type: `Nat'` itself is usually problematic.)
10491051

1050-
> exp' : (n, m : Nat') -> Nat'
1052+
> exp' : (n : Nat' {x}) -> (m : Nat' {x=x->x}) -> Nat' {x}
10511053
> exp' n m = ?exp'_rhs
10521054

10531055
> exp'_1 : exp' two two = plus' two two

0 commit comments

Comments
 (0)