Skip to content

Instantly share code, notes, and snippets.

@jessecogollo
Created July 21, 2021 06:32
Show Gist options
  • Save jessecogollo/244a9bdb94b99d05e49fa16303cc9ad8 to your computer and use it in GitHub Desktop.
Save jessecogollo/244a9bdb94b99d05e49fa16303cc9ad8 to your computer and use it in GitHub Desktop.
Ejercicio deletreador en Haskell
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 ++ ", "
deletreador :: [[Char]] -> [Char]
deletreador words
| words == [] = ""
| length words == 1 = createSinglePhrase (head words)
| otherwise = let x:xs = words in createPhrase x xs ++ deletreador xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment