Haskell CW II.6

Introduction to pattern matching in functions.

Simplified Design

  • Signature
  • Purpose (frequently given in the problem)
  • Examples
    • Build from simple to complex
    • Roadmap for writing
  • Write code.
  • Test (check-expect)

Opener

Examples:

lotsOfLetters [4] == "aaaa"
lotsOfLetters [3,1,4] == "aaabcccc"
lotsOfLetters [3,1,4,1,5] == "aaabccccdeeeee"

More than one approach works well!

Today: handle one letter at a time, use a helper.

Multiple simple helpers is good.

Check-Expect

Just make a list of Boolean values that should all be True.

checkLots = [
    lotsOfLetters [4] == "aaaa"
    ,lotsOfLetters [3,1,4] == "aaabcccc"
    ,lotsOfLetters [3,1,4,1,5] == "aaabccccdeeeee"
    ]

main = do putStrLn $ show checkLots
Last modified August 18, 2023: 2022-2023 End State (7352e87)