So I have the following list of tuples and a string
type M a = [(String, String)]
m = [
("x", "a car"),
("y", "a animal")
]
s = "this is x and y"
I am trying to
strRep m s => “this is a car and a animal”
So this is my attempt so far
import Data.List.Utils
strRep :: (Show a) => M -> String -> String
strRep [] s = s
strRep (m:ms) s = replace (fst m) (snd m) s : strRep ms s
The above code returns a list of string. I cant quite figure out the proper way to do loop here.
I’m not sure where
replaceis coming from in your example above. But… assuming it exists, and does what you expect, you should be able to remove the cons(:)from yourstrRepfunction, and instead pass the result of replace into the next run of strRep, like so:Now, instead of returning a list of strings, each a version with one thing replaced. You are iteratively replacing each string, passing the new strings on for the next replacement.