検索語のリスト、置換語のリスト、およびそれらが使用される文字列を取る関数を作成しようとしています。
listReplace :: [String] -> [String] -> String -> String
注意が必要なのは、適切な検索語が n 番目の場合、n 番目の置換語を使用する必要があることです。また、置換語が使用されている場合、それが実際に検索語自体である場合は、別の置換語に置き換えてはなりません。私はすでにこれらの種類の関数を書いています
replace :: String -> String -> String -> String:
replace x y [] = []
replace x y (z:zs) = if isPrefixOf x (z:zs) then y ++ replace x y (drop (length x) (z:zs)) else z: (replace x y zs)
と
replace' :: String -> [String] -> String -> String:
replace' x y [] = []
replace' x [] (z:zs) = []
replace' x y (z:zs) = if isPrefixOf x (z:zs) then concat (take 1 y) ++ replace' x (drop 1 y) (drop (length x) (z:zs)) else z: (replace' x y zs)
このreplaceList関数から始める方法がわかりません。これまでに見つけた実際に役立つ唯一のものは、リストのn番目の要素を置き換える関数だけです。しかし、この場合にそれを使用する方法を理解できないようです:
replace :: Int -> a -> [a] -> [a]
replace n a [] = []
replace 0 a (x:xs) = a : xs
replace n a (x:xs) = x : replace (n-1) a xs
うまくいけば、あなたの一人が私を助けることができます! 前もって感謝します :)