I'm writing a recursive OCaml function that concatenates strings in a string list joined by a separator without placing a separator on the last item but I'm running into some issues. I know that there's a string.concat function, but I prefer not to use that so as to learn how OCaml performs these operations under the hood. Here is what I have so far:
`
let rec join (separator: string) (l: string list) : string =
begin match l with
| []-> ""
| [hd]-> hd
| hd::tl-> if hd != "" then hd^separator else .....
end
`
I'm using pattern matching to match the string list l and cover three cases: case 1 return nothing if the string list is empty; case 2 returns just the head if the list contains no tail. Tail three performs the concatenation while simultaneously recursing on the join function to concatenate the other items in the list with the string separator in between. However I'm unsure as to how to implement this while simultaneously recursing on the tail and paying respect to OCaml's need for every statement to evaluate to an expression. This is a trivial problem in C or Java, but can't figure this out and any help or pointers is appreciated