Source file nonempty_list.ml

1
2
3
4
5
6
7
8
9
10
11
type 'a t = ( :: ) of 'a * 'a list

let hd (x :: _) = x

let of_list = function
  | [] -> None
  | x :: xs -> Some (x :: xs)
;;

let to_list (x :: xs) = List.cons x xs
let map (x :: xs) ~f = f x :: List.map xs ~f