@@ -304,10 +304,10 @@ polymorphic lists...
304
304
> test_rev1 : rev (1::2::[]) = 2::1::[]
305
305
> test_rev1 = Refl
306
306
307
- > test_rev2: rev (True::[]) = True::[]
307
+ > test_rev2 : rev (True::[]) = True::[]
308
308
> test_rev2 = Refl
309
309
310
- > test_length1: length (1::2::3::[]) = 3
310
+ > test_length1 : length (1::2::3::[]) = 3
311
311
> test_length1 = Refl
312
312
313
313
@@ -381,7 +381,7 @@ $\square$
381
381
382
382
Here are some slightly more interesting ones...
383
383
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
385
385
> rev_app_distr l1 l2 = ?rev_app_distr_rhs
386
386
387
387
> 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
544
544
> test_doit3times : doit3times Numbers .minusTwo 9 = 3
545
545
> test_doit3times = Refl
546
546
547
- > test_doit3times': doit3times Booleans .negb True = False
547
+ > test_doit3times' : doit3times Booleans .negb True = False
548
548
> test_doit3times' = Refl
549
549
550
550
@@ -570,7 +570,8 @@ For example, if we apply `filter` to the predicate `evenb` and a list of numbers
570
570
> length_is_1 : (l : List x ) -> Bool
571
571
> length_is_1 l = beq_nat (length l ) 1
572
572
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=_}!}
574
575
575
576
> test_filter2 : filter (length_is_1 {x=Nat})
576
577
> [ [1,2], [3], [4], [5,6,7], [], [8] ]
@@ -607,15 +608,15 @@ without declaring it at the top level or giving it a name.
607
608
608
609
\todo[inline]{Can't use `*` here due to the interference from our tuple sugar}
609
610
610
- > test_anon_fun': doit3times (\n => mult n n) 2 = 256
611
+ > test_anon_fun' : doit3times (\n => mult n n) 2 = 256
611
612
> test_anon_fun' = Refl
612
613
613
614
The expression `\n => mult n n` can be read as "the function that, given a
614
615
number `n`, yields `n * n`."
615
616
616
617
Here is the `filter` example, rewritten to use an anonymous function .
617
618
618
- > test_filter2': filter (\l => beq_nat (length l ) 1)
619
+ > test_filter2' : filter (\l => beq_nat (length l ) 1)
619
620
> [ [1,2], [3], [4], [5,6,7], [], [8] ]
620
621
> = [ [3], [4], [8] ]
621
622
> test_filter2' = Refl
@@ -643,7 +644,7 @@ $\square$
643
644
644
645
Use `filter` to write an Idris function `partition`:
645
646
646
- > partition : (test: x -> Bool) -> (l : List x ) -> (List x ) * (List x )
647
+ > partition : (test : x -> Bool) -> (l : List x ) -> (List x ) * (List x )
647
648
> partition f xs = ?partition_rhs
648
649
649
650
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.
655
656
> test_partition1 : partition Numbers .oddb [1,2,3,4,5] = ([1,3,5], [2,4])
656
657
> test_partition1 = ?test_partition1_rhs
657
658
658
- > test_partition2: partition (\x => false) [5,9,0] = (([], [5,9,0]))
659
+ > test_partition2 : partition (\x => false) [5,9,0] = (([], [5,9,0]))
659
660
> test_partition2 = ?test_partition2_rhs
660
661
661
662
$\square$
@@ -712,10 +713,10 @@ by 'flattening' the results of `f`, like so:
712
713
flat_map (\n => [n,n+1,n+2]) [1,5,10] = [1,2,3, 5,6,7, 10,11,12]
713
714
```
714
715
715
- > flat_map : (f: x -> List y ) -> (l : List x ) -> List y
716
+ > flat_map : (f : x -> List y ) -> (l : List x ) -> List y
716
717
> flat_map f l = ?flat_map_rhs
717
718
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]
719
720
> test_flat_map1 = ?test_flat_map1_rhs
720
721
721
722
$\square$
@@ -999,21 +1000,21 @@ corresponding unit tests pass by proving them with `Refl`.
999
1000
1000
1001
Successor of a natural number:
1001
1002
1002
- > succ : (n : Nat') -> Nat'
1003
- > succ n = ?succ_rhs
1003
+ > succ' : (n : Nat' {x} ) -> Nat' {x}
1004
+ > succ' n = ?succ'_rhs
1004
1005
1005
- > succ_1 : succ zero = one
1006
- > succ_1 = ?succ_1_rhs
1006
+ > succ'_1 : succ' zero = one
1007
+ > succ'_1 = ?succ_1_rhs
1007
1008
1008
- > succ_2 : succ one = two
1009
- > succ_2 = ?succ_2_rhs
1009
+ > succ'_2 : succ' one = two
1010
+ > succ'_2 = ?succ_2_rhs
1010
1011
1011
- > succ_3 : succ two = three
1012
- > succ_3 = ?succ_3_rhs
1012
+ > succ'_3 : succ' two = three
1013
+ > succ'_3 = ?succ'_3_rhs
1013
1014
1014
1015
Addition of two natural numbers:
1015
1016
1016
- > plus' : (n, m : Nat') -> Nat'
1017
+ > plus' : (n, m : Nat' {x} ) -> Nat' {x}
1017
1018
> plus' n m = ?plus'_rhs
1018
1019
1019
1020
> plus'_1 : plus' zero one = one
@@ -1027,7 +1028,7 @@ Addition of two natural numbers:
1027
1028
1028
1029
Multiplication:
1029
1030
1030
- > mult' : (n, m : Nat') -> Nat'
1031
+ > mult' : (n, m : Nat' {x} ) -> Nat' {x}
1031
1032
> mult' n m = ?mult'_rhs
1032
1033
1033
1034
> mult'_1 : mult' one one = one
@@ -1041,13 +1042,14 @@ Multiplication:
1041
1042
1042
1043
Exponentiation:
1043
1044
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}`.}
1045
1047
1046
1048
(Hint: Polymorphism plays a crucial role here . However, choosing the right type
1047
1049
to iterate over can be tricky . If you hit a "Universe inconsistency " error, try
1048
1050
iterating over a different type: `Nat'` itself is usually problematic .)
1049
1051
1050
- > exp' : (n, m : Nat') -> Nat'
1052
+ > exp' : (n : Nat' {x}) -> ( m : Nat' {x=x->x} ) -> Nat' {x}
1051
1053
> exp' n m = ?exp'_rhs
1052
1054
1053
1055
> exp'_1 : exp' two two = plus' two two
0 commit comments