
Hi everybody, 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) ? right now it is take::Int->[a]->[a] I was thinking may be take::(Integral b)=>b->[a]->[a] would be better... Thanks, Sunil.

To require an Integer implies you have a list of 2 billion+ elements
and that's pretty huge for a list. Take is used a lot, and using an
Int instead of Integer for something that gets called so often is just
common sense.
On Wed, Aug 10, 2011 at 10:14 AM, Sunil S Nandihalli
Hi everybody, 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) ? right now it is take::Int->[a]->[a] I was thinking may be take::(Integral b)=>b->[a]->[a] would be better... Thanks, Sunil. _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Sunil S Nandihalli
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/

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
Sunil S Nandihalli
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@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Wednesday 10 August 2011, 20:42:05, Sunil S Nandihalli wrote:
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 ...
Use fromInteger or fromIntegral
Thanks, Sunil.

ah that is exactly what I wanted .. thanks Daniel. Sunil. On Thu, Aug 11, 2011 at 12:22 AM, Daniel Fischer < daniel.is.fischer@googlemail.com> wrote:
On Wednesday 10 August 2011, 20:42:05, Sunil S Nandihalli wrote:
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 ...
Use fromInteger or fromIntegral
Thanks, Sunil.

At 12:28 AM +0530 8/11/11, Sunil S Nandihalli wrote:
ah that is exactly what I wanted .. thanks Daniel. Sunil.
On Thu, Aug 11, 2011 at 12:22 AM, Daniel Fischer <mailto:daniel.is.fischer@googlemail.comdaniel.is.fischer@googlemail.com> wrote:
On Wednesday 10 August 2011, 20:42:05, Sunil S Nandihalli wrote:
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 ...
Use fromInteger or fromIntegral
Thanks, Sunil.
But realize that truncation can result: Prelude> fromInteger 12345678900 :: Int -539222988 Dean

2011/8/10 Daniel Fischer
Use fromInteger or fromIntegral
Wouldn't it be cool if Hoogle came up with fromInteger as the first result for "Integer -> Int" ? As it is now, you have to search for "Integer -> Int -syb -containers -time -deepseq" Don't know if it's easy though. David.
participants (6)
-
Daniel Fischer
-
David McBride
-
David Virebayre
-
Dean Herington
-
Ertugrul Soeylemez
-
Sunil S Nandihalli