I have a program that uses both Int
and Integer
, because a few of the functions return results that are quite large. I'm tired of having to use fromIntegral
everywhere and I was wondering if there's a way to get Haskell to ignore the distinction between Int
and Integer
upon compilation.
What's the difference between Integer and Int ? Integer can represent arbitrarily large integers, up to using all of the storage on your machine. Int can only represent integers in a finite range.
It states that this function is of type Int -> Int , that is to say, it takes an integer as its argument and it returns an integer as its value.
In practice, Int is defined by the compiler to be equivalent to a 32-bit integer value. The reason for this is that Int can be optimized in certain ways that a machine word cannot. Pointer tagging is important for Haskell performance, and so implementations are free to use some number of bits.
Solution: remove the Int
s from your program and just use all Integer
s. As noted by geekosaur, you can use the generic functions from Data.List (e.g. genericLength
). If you provide us with your specific program code, then we could give more specific suggestions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With