2025-12-12 Class and Instance Review

  1. Make a class Food so that when a is a Food, then a has a function calories :: a -> Int and a function taste :: a -> String.

  2. Make String an instance of Food. Use 15 * length for calories and “Yummy " followed by the string for the taste.

  3. Make a data type StirFry that contains both an Int variable rice and a [String] called ing (for ingredients).

  4. Make StirFry an instance of Food. For calories, use the sum of the calories of the Food in the list, plus 20 times the rice. For taste, use “StirFry of x,y,z” (see question 5).

  5. Write the commas function shown below.

     commas :: [String] -> String
     test_commas = commas ["a","beta","c"] == "a,beta,c"
    

    Use recursion.