Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 529

I want to do 2 things after a "then" statement in a "if.. then.. else" statement

$
0
0
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?


Viewing all articles
Browse latest Browse all 529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>