Haskell CW II.3
This page is full of tiny pieces to help you get better at programming Haskell.
Goals:
- Range notation
[a,b..c]
to make lists of integers.
- Apply a function to everything in a list by using the “list
comprehension”.
- Filter out some elements from an existing list using a list
comprehension.
Micro-projects
- A list of the first 1000 integers.
- A list of the first 1000 perfect cubes.
- Find the sum of the first 100 perfect squares.
- The type signature for the integer sum above.
- A list of all of the perfect squares between 90 and 1919.
- The type signature for a list of integers.
- The product of the numbers in the list of perfect squares above.
- A function
sqList
to give all of the perfect squares between lower
and
upper
.
- The type signature for the function
sqList
.
- Use your function to get the first 17 perfect squares between 1500
and 4500.
- Write a new function sq25 that will return the first 25 perfect
squares between
lower
and upper
. (If there are not 25, the
function will return however many there are.)
- A list with every fourth lowercase letter, starting at ‘a’ then
’d’. (Hint: letters work the same as numbers.)
- A string with the last half of the alphabet (beginning with ‘n’).
- Write a function that takes in a list and produces a list of
ordered pairs
(item, more)
, giving the item and how many more
items after it are in the list.
Basic functions
- The remainder when 921013 is divided by 31.
- The whole number of times that 23148 is divisible by 17.
- Find five to the twelfth power.
- Find seven to the 707 power.
Medium functions
Write the signature for each.
- Write a function
mySmall
that takes in four integer inputs and returns the
smallest.
- Create a function
myStarts
that takes in two lists and returns a tuple with
the first element from each list.
Write myMix
that takes in two lists and gives a tuple with the
first element from the first list and the last element from the
second list.
myMix [1,2,3] [10,20,30] == (1,30)
Create dublr
that takes in one list and returns a new list
consisting of the same information forward then backward.
dublr [1,2,3] == [1,2,3,3,2,1]
Step up
Write a function sqLast25 lower upper
that will return the last 25 perfect
squares between lower and upper (inclusive).
sqLast25 :: Int -> Int -> [Int]
Obscure
- What is the successor of the character ‘Z’?
- How about the predecessor of the character ‘A’?
Notes
Practice quiz
- Make the a list with the