There is an annoyance with negative numbers that is mentioned.
Logical operations are basic building blocks of programs. How do you write:
Haskell follows mostly the normal order of operations from mathematics. However, in math functions must be written f(x)
with parentheses, whereas in Haskell functions can be written f x
without parentheses. This means we need to fit functions into the order of operations.
Write the function hypSquare a b
that computes the square of the length of the hypotenuse of a right triangle with legs a
and b
.
The apostrophe character ('
) is usually used for one of two purposes. List both:
Are you allowed to use the apostrophe in function or variable names?
In Racket you used (cons x listy) to make a list with x before an existing list. How do you do that in Haskell?
In Racket you used (concatenate firstStr secondStr) to put two strings together. How do you do that in Haskell?
Slightly longer exercise:
learn
containing the words “this” “is” “all” “good”.learnMore
containing “Hopefully” “this” “is” “all” “good”learnMore !! 4
.Complete the table of equivalents
Racket | Haskell language equivalent functions |
---|---|
first | … |
rest | … |
length | … |
empty? | … |
What are the signatures and purposes of these functions?
How can you ask the computer if the list called xs
contains the number 5?
There are several more functions that are used less often, but still make it into the basic starting out chapter. Write quick summaries as necessary.
Create a list of integers from 1 to 1000 (inclusive).
Create a list of letters from 'm'
to 'a'
in that order.
New functions: write signature and purpose for each.
Write a function that removes all of the vowels from a word.
What is the main difference between a tuple and a list?
New functions: write signature and purpose for each.
Write a function that takes in a list of words and puts out a list of ordered pairs (word, length of word).
Write a function that takes in a list of words and puts out a list with the second word doubled in its own list, the third word tripled in its own list, etc.
For example, the function call
amplify ["hill","rock","star","four"]
should produce
[["hill"],["rock","rock"],["star","star","star"], ["four","four","four","four"]]