I want to write a function called trained that takes a string replacement function and a list of word pairs (two-tuples of strings).
I have tried using map and lambda function but still getting some error. Any help on this problem would be much appreciated!
Function train should have this type of signature: train :: Eq a => (a -> t) -> [(a, t)] -> a -> t
Here is some error:
Couldn't match expected type
[Char] -> b'
with the actual type[[Char] -> [Char]]
Here is my code:
extend repl old new = \str -> if (str == old) then new
else if (str == new) then old
else (repl str)
train fn lst = map (\(a,b) -> extend fn a b) lst
The function train should work out like this:
In: let improved = train (\s->s) [("kittens","puppies"),
("tea","coffee"),("Java","Haskell")]
In: map improved ["my","favorite","things","are",
"kittens","Java","tea","and","rainbows"]
Out: ["my","favorite","things","are","puppies","Haskell","coffee","and","rainbows"]