Here are some useful snippets for when it comes to creating and using lists in OCaml.
(* One List *) let l = [0; 1; 2; 3; 4];; (* Another List *) let l' = [5; 6; 7; 8; 9];; (* Appending an item to a list *) let list1 = 0 :: l;;
Screenshot of above with Syntax Highlighting from emacs
Screen Shot 2014-11-02 at 17.36.05.png 35.64KB 0 downloads
Function to get the first item in the list (head) and to get the rest of the list (tail)
let hd = function |  -> failwith "hd" |x :: xs -> x ;; let tl = function | -> failwith "tl" | x :: xs -> xs ;; hd list1;; tl list1;;
Screen Shot 2014-11-02 at 17.41.12.png 38.23KB 0 downloads