In the F# code I’m trying to convert to OCaml, I’ve run into the following:
let rec parseList lst off =
seq {
if List.isEmpty lst then ()
else
match parse off <| List.head lst with
| (Unmatched, _) as y -> yield y
| (y, z) -> yield (y, z)
yield! parseList (List.tail lst) z
}
I’m wondering about how to convert that seq{…} expression with yield‘s to OCaml? My first guess is that the seq would have to become a list.
Simplest translation (not tail recursive) is:
Tail recursive version is:
Note that the F# code you’re starting from leaves a lot to be desired. The calls to
List.headandList.tailare unnecessary potential sources of exceptions when you can more easily use pattern matching instead. And there are superfluous parentheses.