[Haskell-beginners] splicing

Shrivats shrvtsnvs at gmail.com
Mon Jun 15 02:38:25 UTC 2015


Hi,

I don't see anything as a Prelude function, but you can do something with a
combination of take and drop:

rangeOf:: Int -> Int -> [a]
rangeOf x y = take y . drop x

rangeOf 2 4 [1 .. 5] -- [3,4,5]

I have not included any bounds check. It's up to you. For added benefits,
look up dropWhile and takeWhile.

HTH.
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150615/effb2644/attachment.html>


More information about the Beginners mailing list