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

Sunil S Nandihalli sunil.nandihalli at gmail.com
Wed Aug 10 20:42:05 CEST 2011


hmm.. I do agree that taking elements larger than say 2-billion is insane ..
however, I have no intention of doing that. But the thing is the value I am
getting is of type Integer but it actually very small and I am unable to
pass it as is. So is there a way to convert a value of type Integer to Int ?
This might be obvious.. But I am a newbie to the whole Haskell thing ...

Thanks,
Sunil.

On Wed, Aug 10, 2011 at 8:05 PM, Ertugrul Soeylemez <es at ertes.de> wrote:

> 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/
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110811/6f834991/attachment.htm>


More information about the Beginners mailing list