Skip to content

Instantly share code, notes, and snippets.

@jessecogollo
Created June 28, 2021 04:59
Show Gist options
  • Save jessecogollo/4cd5f6b2e8364bdaf67e38c462e4557e to your computer and use it in GitHub Desktop.
Save jessecogollo/4cd5f6b2e8364bdaf67e38c462e4557e to your computer and use it in GitHub Desktop.
speller exersise
getLetter :: [Char] -> [Char]
getLetter word =
take 1 word
createSinglePhrase :: [Char] -> [Char]
createSinglePhrase word =
getLetter word ++ " is for " ++ word
createPhrase :: [Char] -> [[Char]] -> [Char]
createPhrase word lst =
if ( length lst == 1 )
then createSinglePhrase word ++ ", and "
else createSinglePhrase word ++ ", "
speller :: [[Char]] -> [Char]
speller words
| words == [] = ""
| length words == 1 = createSinglePhrase (head words)
| otherwise = let x:xs = words in createPhrase x xs ++ speller xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment