[Haskell-beginners] the first argument of take is an Int and not Integral..

Ertugrul Soeylemez es at ertes.de
Wed Aug 10 16:35:08 CEST 2011


Sunil S Nandihalli <sunil.nandihalli at gmail.com> wrote:

>  I feel forcing the first argument of take to be an Int is
> unnecessarily restrictive .. Is there a rationale behind not making it
> just (Integral a) ?

This would be an overgeneralization and you would pay for it with a
performance loss.  There is no reason to generalize here, because most
indexing and counting functions use an Int.

If you feel that you might exhaust Int (which is very unlikely on 32 bit
and practically impossible on 64 bit), you can use genericTake from
Data.List.

    Data.List.genericTake :: Integral i => i -> [a] -> [a]


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/





More information about the Beginners mailing list