[Haskell-beginners] splicing

Alexey Shmalko rasen.dubi at gmail.com
Mon Jun 15 04:12:06 UTC 2015


Hi, Derek!

Binary search algorithm requires random access, so you can't implement
it (efficiently) using lists. You'd better try using something as
vector [1]. It has both index and slice operations that work in O(1),
so implementing binary search is a breeze.

[1]: http://hackage.haskell.org/package/vector-0.10.12.3/docs/Data-Vector.html

On Mon, Jun 15, 2015 at 1:09 AM, derek riemer <driemer.riemer at gmail.com> wrote:
> Hi guys,
> As a newby to haskell, I was curious, what is the best way to splice an
> array or do things in the middle?
> For example, binary search requires i do in sudocode
> define binary search array target.
> Find middle element.
> If target is middle element then return target
> else if target < middle element then
>     binary search array[0:target]
> else
>     binary search array[target:end]
>
> How can I get this splicing with haskell?
> I can't just use head here.
> I can't do array!!n: where n is some number.
>
> Thanks,
> Derek
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


More information about the Beginners mailing list