Skip to content

Instantly share code, notes, and snippets.

@FunctionalFirst
Created September 18, 2014 21:35
Show Gist options
  • Save FunctionalFirst/c2e7d645aea0cda84e8e to your computer and use it in GitHub Desktop.
Save FunctionalFirst/c2e7d645aea0cda84e8e to your computer and use it in GitHub Desktop.
let binarySearch value (array: 'T[]) =
let rec loop lo hi =
if lo <= hi then
let mid = lo + ((hi - lo) >>> 1)
match array.[mid] with
| x when x = value -> Some mid
| x when x < value -> loop (mid + 1) hi
| _ -> loop lo (mid - 1)
else None
loop 0 (array.Length - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment