Мне нужно переопределить функцию слова с помощью рекурсии. У меня есть 2 вспомогательные функции, но я не могу собрать окончательную функцию. Есть идеи?
takeWord :: String -> String
takeWord "" = ""
takeWord (' ':xs) = ""
takeWord (x :xs) = x : takeWord xs
dropWord :: String -> String
dropWord "" = ""
dropWord (' ':xs) = ' ' : xs
dropWord (x :xs) = dropWord xs
words' :: String -> [String]
words' "" = []
words' (' ':xs) = takeWord xs : words' xs
words' (x:xs) = takeWord (x:xs) : words' (dropWord xs)
Результат для этого ввода " Correct answer is this"
должен быть ["Correct","answer","is","this"]
. Теперь я получаю этот вывод: ["","","Correct","Correct","","","answer","answer","","","is","is","","","this","this"]