let rec filtersList2fromList1 (List1:string list) (List2:string list) : string list = let finalList = [] in match List1 with | s :: tl -> if List.mem s List2 = true then finalList @ [s] else filtersList2fromList1 tl List2 | [] -> []
so that,
filtersList2fromList1 ["x";"y";"z"] ["z";"x"] would be ["x";"z"] filtersList2fromList1 ["x";"y";"z"] ["x"] would be ["x"]
what I would like to add is, if the "if" statement is true, not only it would execute "finalList @ [s]", but also "filtersList2fromList1 tl List2" so that it will be a recursion. Without executing "filtersList2fromList1 tl List2" when it is true,
filtersList2fromList1 ["x";"y";"z"] ["z";"x"]
would only be ["x"]
, which is wrong.
How can I solve this problem?