Skip to content

Instantly share code, notes, and snippets.

@mattearly
Last active April 18, 2017 16:31
Show Gist options
  • Save mattearly/0b677b7119161eef0b18dd1871e3c005 to your computer and use it in GitHub Desktop.
Save mattearly/0b677b7119161eef0b18dd1871e3c005 to your computer and use it in GitHub Desktop.
(*find i within the lst*)
let rec member i lst =
match lst with
[] -> false
| hd::tl -> hd = i || member i tl;;
(*with if else instead*)
let rec member i lst =
match lst with
[] -> false
| hd::tl -> if hd = i then true else member i tl;;
(*total up a list*)
let rec total lst =
match lst with
[] -> 0;
| hd::tl -> hd + total tl;;
(*compare function*)
let cmp x y =
if x > y then 1
else if x < y then -1
else 0;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment