I'm new at OCaml (and still a novice in learning programming in general) and I have a quick question about checking what kind of string the next element in the string list is.

I want it to put a separator between each element of the string (except for the last one), but I can't figure out how to make the program 'know' that the last element is the last element.

Here is my code as it is now:

let rec join (separator: string) (l : string list) : string = 
 begin match l with
    | []->""
    | head::head2::list-> if head2=[] then head^(join separator list) else head^separator^(join separator list)
 end


let test () : bool =
 (join "," ["a";"b";"c"]) = "a,b,c"
;; run_test "test_join1" test 

Thanks in advance!

Edit
Report