@@ -110,7 +110,7 @@ object types {
110
110
// EXERCISE 13
111
111
//
112
112
// Prove that `A + 0` is equivalent to `A` by implementing the following two
113
- // functions.
113
+ // functions in a way that loses no information .
114
114
//
115
115
def to3 [A ](t : Either [A , Nothing ]): A = ???
116
116
def from3 [A ](a : A ): Either [A , Nothing ] = ???
@@ -335,7 +335,7 @@ object functions {
335
335
def draw2 (size : Int /* ... */ ): ??? = ???
336
336
}
337
337
338
- object higher_order {
338
+ object parametric {
339
339
//
340
340
// EXERCISE 1
341
341
//
@@ -399,11 +399,9 @@ object higher_order {
399
399
else Right ((input.drop(1 ), input.charAt(0 )))
400
400
)
401
401
}
402
- }
403
402
404
- object poly_functions {
405
403
//
406
- // EXERCISE 1
404
+ // EXERCISE 7
407
405
//
408
406
// Create a polymorphic function of two type parameters `A` and `B` called
409
407
// `snd` that returns the second element out of any pair of `A` and `B`.
@@ -415,7 +413,7 @@ object poly_functions {
415
413
snd((true , List (1 , 2 , 3 ))) // List(1, 2, 3)
416
414
417
415
//
418
- // EXERCISE 2
416
+ // EXERCISE 8
419
417
//
420
418
// Create a polymorphic function called `repeat` that can take any
421
419
// function `A => A`, and apply it repeatedly to a starting value
@@ -430,15 +428,15 @@ object poly_functions {
430
428
repeat[Int => Int ](100 )(identity, _ andThen (_ + 1 )) // (_ + 100)
431
429
432
430
//
433
- // EXERCISE 3
431
+ // EXERCISE 9
434
432
//
435
433
// Count the number of unique implementations of the following method.
436
434
//
437
435
def countExample1 [A , B ](a : A , b : B ): Either [A , B ] = ???
438
436
val countExample1Answer = ???
439
437
440
438
//
441
- // EXERCISE 4
439
+ // EXERCISE 10
442
440
//
443
441
// Count the number of unique implementations of the following method.
444
442
//
@@ -447,7 +445,7 @@ object poly_functions {
447
445
val countExample2Answer = ???
448
446
449
447
//
450
- // EXERCISE 5
448
+ // EXERCISE 11
451
449
//
452
450
// Implement the function `groupBy1`.
453
451
//
@@ -472,7 +470,7 @@ object poly_functions {
472
470
groupBy1(TestData , ByDate )(Reducer ) == ExpectedResults
473
471
474
472
//
475
- // EXERCISE 6
473
+ // EXERCISE 12
476
474
//
477
475
// Make the function `groupBy1` as polymorphic as possible and implement
478
476
// the polymorphic function. Compare to the original.
0 commit comments