I am trying to write a function that takes two lists (list1 & list2) expressed as strings as arguments and after recursively iterating list1 and comparing a value from list2. when the value of list1 and list2 are equal, the recursion should break and return the two lists (modified).
For example. list1= "abcdef". list2= "def"
pseudo code:
- for char in list1
- if char==list2[0] --> [char:] list2[1:]
In the case above this would be returning: "def" "ef"
What I got so far:
isEqual :: String -> String -> String ->String
isEqual (s : os) (p : ps)
| p /= s = isEqual os (p : ps)
| otherwise = s:os ps
However, I get the following error message from vs-code:
• Couldn't match expected type ‘String -> String’ with actual type ‘[Char]’ Possible cause: ‘(:)’ is applied to too many arguments
In the expression: s : os ps In an equation for ‘isEqual’: isEqual (s : os) (p : ps) | p /= s = isEqual os (p : ps) | otherwise = s : os pstypecheck(-Wdeferred-type-errors)
Couldn't match expected type ‘[Char] -> [Char]’ with actual type ‘[Char]’ The function ‘os’ is applied to one argument, but its type ‘[Char]’ has none
In the second argument of ‘(:)’, namely ‘os ps’
In the expression: s : os pstypecheck(-Wdeferred-type-errors)
s:os pssupposed to mean?list1= "abcdef". list2= "def", what should be the output? Could you give more examples with indata and outdata?(String, String)tuple.