You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
761 B
31 lines
761 B
# Chapter Exercises |
|
|
|
1. `length :: [a] -> Int` (Why not `Integer`?) |
|
2. Answers: |
|
1. 5 |
|
2. 3 |
|
3. 2 |
|
4. 5 |
|
3. `(/)` takes two `Fractional` types. `length` returns and `Int` which is not `Fractional`. (`Float` and `Double` are) |
|
4. Use `div` instead: `div 6 $ length [1, 2, 3]` |
|
5. `Bool`. `True` (Note: `(+)` has higher precedence) |
|
6. `Bool`. `False` |
|
7. Answers: |
|
1. Works. `Bool`. `True` |
|
2. Won't work. List needs to have elements of the same type. |
|
3. Works. `Int`. `5` |
|
4. Works. `Bool`. `False` |
|
5. Won't work. `(&&)` needs two `Bool`'s, `9` isn't one. |
|
8. see src/chapter4.hs |
|
9. see src/chapter4.hs |
|
10. see src/chapter4.hs |
|
|
|
## Correcting syntax |
|
see src/chapter4.hs |
|
|
|
## Match the function names to their types |
|
1. (c) |
|
2. (b) |
|
3. (a) |
|
4. (d) |
|
|
|
|