I am new to OCaml (and still new to learning programming in general), and I have a quick question about checking which line contains the next item in a list of strings.
I want it to put a separator between each element of the line (except the last), but I cannot figure out how to make the program "know" that the last element is the last element.
Here is my code as of 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!
list functional-programming ocaml
flymonkey
source share