|
![](/i/fill.gif) |
Orchid XP v8 wrote:
> find :: (Ord y) => (x -> y) -> y -> IArray x -> (Int,Int) -> Maybe x
> find field target array (base,size)
> | size < 0 = error "invalid subrange size"
> | size == 0 = Nothing
> | size == 1 = if field (array ! base) == target then Just (array !
> base) else Nothing
> | otherwise = find field target array (base, size `div` 2) `mappend`
> find field target array (base + size `div` 2, size `div` 2)
>
> Now I suppose I better go run that and see if it actually works.
Well, the final line is wrong for a start. (Due to rounding, if the
array size isn't even, one element gets elided from the search.)
| otherwise =
let size2 = size `div` 2
in find field target array (base, size2) `mappend` find field
target array (base + size2, size - size2)
That should work better. The division of a range into two subranges is
still unequal, but at least all elements are included now...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
![](/i/fill.gif) |