Created
October 11, 2018 09:27
-
-
Save jeremysinger/d59d10a99123ca1b1338bb0e1b7e4968 to your computer and use it in GitHub Desktop.
Spelling book solution for https://www.futurelearn.com/courses/functional-programming-haskell/4/steps/334999
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | 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