On Monday, June 15, 2015, derek riemer <<a href="mailto:driemer.riemer@gmail.com">driemer.riemer@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi guys,<br>
As a newby to haskell, I was curious, what is the best way to splice an array or do things in the middle?<br>
For example, binary search requires i do in sudocode<br>
define binary search array target.<br>
Find middle element.<br>
If target is middle element then return target<br>
else if target < middle element then<br>
    binary search array[0:target]<br>
else<br>
    binary search array[target:end]<br>
<br>
How can I get this splicing with haskell?<br>
I can't just use head here.<br>
I can't do array!!n: where n is some number.</blockquote><div><br></div><div>You probably shouldn't use lists for binary search, since indexing a list is linear time. Binary searching a list is slower than a linear search. However, if you must, you can use splitAt for that purpose.</div><div><br></div><div>Where you should really be looking for Array-like uses are Data.Vector or Data.Array. The former is probably better suited for this use case.</div><div><br></div><div>You should also consider adding arguments to the search function for start and end indexes, rather than slicing the array itself. That's the more traditional way to implement it.</div><div><br></div><div>-bob</div>