Skip to content

Instantly share code, notes, and snippets.

@cqfd
Created April 23, 2011 22:07
Show Gist options
  • Save cqfd/939020 to your computer and use it in GitHub Desktop.
Save cqfd/939020 to your computer and use it in GitHub Desktop.
OCaml implementation of a nub function
let rec elem x xs =
match xs with
| [] -> false
| y :: ys -> x = y || elem x ys
let rec uniques l =
let rec helper l acc =
match l with
| [] -> acc
| x :: xs ->
if elem x acc then
helper xs acc
else
helper xs (x :: acc)
in List.rev (helper l [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment