2025-11-20 Basics Quiz

Culmination of review. Takes 25 minutes.
  1. Define a new data type Plant that can hold either (Thistle) or (Dandelion with an Int field called num and a String field called flavor).

  2. A field contains a list of Plant. Each Thistle subtracts 0.50 from the value of the field. Dandelions add 1.25 times the num of each.

     landValue :: [Plant] -> Double
    
    1. Write a recursive version.
    2. Write a version that uses list comprehension.
  3. In springtime, thistles double in number and dandelions triple. Write a recursive function to make a new list:

     spring :: [Plant] -> [Plant]
    
     d = Dandelion 4 "bitter"
     check_spring = [
       spring [Thistle] == [Thistle, Thistle]
       ,spring [d] == [d,d,d]]
    
  4. (Refers to work from 2021 AoC 4.) True if any row (inner list) has all negative numbers.

     hwin :: [Int] -> Bool
     check_hwin = [
       hwin [[1,3,2],[-4,-5,-6]] == True
       ,hwin [[-1,1,-1]] == False
     ]
    
  5. Get feedback on question 4 and write it another way. Recursion, list comprehension, higher order function.

Last modified November 21, 2025: Haskell practice and quiz materials. (2542e6b)