Skip to content

Instantly share code, notes, and snippets.

@ThePhD
Created September 24, 2016 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ThePhD/414c828773dc292bec92228ba5e6d21d to your computer and use it in GitHub Desktop.
Save ThePhD/414c828773dc292bec92228ba5e6d21d to your computer and use it in GitHub Desktop.
:I
let list_print (l: string list) : unit =
(* *)
List.iter ( print_endline ) l;;
let rec oxford (l: string list) : string =
(* match the value of list, or replace with foldL
somehow until it works? *)
match List.length l with
| [] -> ""
| h :: [] -> h
| h :: t when List.length t = 1 -> h ^ " and " ^ oxford t
| h :: t when List.length t <> 1 -> h ^ ", " ^ oxford t
| _ -> "?" (* wat *)
oxford [];;
oxford ["a"];;
oxford ["a"; "b"];;
oxford ["a"; "b"; "c"];;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment