Haskell CW II.3b

Learning questions to help with II.3.

A few places use this variable:

word = "alphabet soup is tasty"

Try each question, ask neighbors and discuss. These took about 25 minutes of thinking and talking, with some help along the way.

  1. Make the pattern [1,4,7,10,13,16,19,22,25,28] without so much typing.

  2. Make the pattern ['a','d','g','j','m'] without so much typing. Numbers and letters work in very similar ways.

  3. How do you take two lists of numbers and make a list of ordered pairs, like this:

     a3 = [10,20,30,40,50,60,70]
     b3 = [13,27..80]
     -- [13,27,41,55,69]
     want3 = [( 10,13), (20,27), (30, 41) ] -- etc
    
  4. What if you want to take the word from the start and make ordered pairs like this:

     [('a',10), ('l',20), ('p',30), ('h',40), ('a',50) ] -- etc
    
  5. What do you do if you want the pattern to stop after the word “alphabet”? What if you don’t want it to stop, but keep going for every letter in the word?

  6. How can you process word to only keep the letters that are 'h' or later in the alphabet?

  7. What does this do? (Without running.)

     [ x>='h' | x <- word]
    
  8. Learn what to put in the place of “…something…” to make y=3*x-5. (Attempt it; see a solution if needed.)

     [ y | x <- [0..5], ...something... ]
    
  9. Figure out what to put in the place of ...something... so that you get the same result as the previous exercise.

     [ y | x <- [0..5], y <- [...something...] ]
    
  10. Use the function y=3*x-5. Make a list of ordered pairs (x,y) that have x an integer between 0 and 50 (inclusive) and y less than 20.

  11. Annoying Detail I: Int is a 64 bit integer, Integer has no size limit. Run the code below and compare the values: ap and bp. What do you see?

    a :: [Int]
    a = [1..100]
    b :: [Integer]
    b = [1..100]
    ap = product a
    bp = product b
    
  12. Annoying Detail II: Try the same code, but change the upper limit from 100 to 50. Describe the difference you see.

Last modified August 18, 2023: 2022-2023 End State (7352e87)