I am trying to use pattern matching and recursion to replace some words in a list with other words. The pattern matching does not work in all cases, and my code does not produce a list of strings changed, using pattern matching, in all cases.
I was wondering if someone can help me identify why this is?
pattr :: [[Char]] -> [[Char]]
pattr [] = []
pattr ("you":as) = ("u":pattr as)
pattr ("see":"you":as) = ("seaya":pattr as)
pattr ("by":"the":"way":as) = ("btw":pattr as)
pattr ("laugh":"out":"loud":as) = ("lol":pattr as)
pattr ("for":"your":"information":as) = ("fyi":pattr as)
pattr (x:as) = (x:as)
Examples:
GHCi> pattr ["milk", "see", "you", "soon"]
> ["milk", "see", "you", "soon"]
GHCi> pattr ["see", "you", "soon"]
> ["cya", "soon"]
It seems that you only need to change the last line: