Created
April 23, 2011 22:07
-
-
Save cqfd/939020 to your computer and use it in GitHub Desktop.
OCaml implementation of a nub function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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