単語の削除

30分プログラム、その792。anarchy golf - delete wordsにインスパイアされました。

使い方

*Main> deleteWord "golf" "flogwaiurhgm"
"    waiurh m"

ソースコード

replace :: Eq a => a -> a -> [a] -> [a]

replace _ _ [] = []
replace old new (x:xs) =
    if old == x then
        new : replace old new xs
    else
        x : replace old new xs

deleteWord :: String -> String -> String
deleteWord xs ys =
    foldr (\x str -> replace x ' ' str) ys xs