Skip to content

Instantly share code, notes, and snippets.

@jeremysinger
Created October 11, 2018 09:27
Show Gist options
  • Save jeremysinger/d59d10a99123ca1b1338bb0e1b7e4968 to your computer and use it in GitHub Desktop.
Save jeremysinger/d59d10a99123ca1b1338bb0e1b7e4968 to your computer and use it in GitHub Desktop.
-- | The 'wordPhrase' function spells out an individual word
-- For example, "a is for apple"
wordPhrase :: String -> String
wordPhrase x = (head x) : " is for " ++ x
-- | The 'speller' function generates text for a spelling book
-- from a list of words
speller :: [String] -> String
speller [] = []
speller [x] = wordPhrase x
speller [x,y] = xPhrase ++ ", and " ++ yPhrase
where
xPhrase = wordPhrase x
yPhrase = wordPhrase y
speller (x:xs) = wordPhrase x ++ ", " ++ speller xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment