Binary search implementation in PureScript
root
Binary search implementation in Haskell.
binsearch :: [Int] -> Int -> Int -> Int -> Int
binsearch xs value low high
| high < low = -1
| xs!!mid > value = binsearch xs value low (mid-1)
| xs!!mid < value = binsearch xs value (mid+1) high
| otherwise = mid
where
mid = low + ((high - low) `div` 2)
In a functional language, linear search is faster. So this is just a demo.