[Haskell-cafe] Re: A question about "monad laws"
wnoise at ofb.net
Thu Feb 14 13:04:01 EST 2008
On 2008-02-14, Roman Leshchinskiy <rl at cse.unsw.edu.au> wrote:
> Richard A. O'Keefe wrote:
>> Presumably the reason for having Int in the language at all is speed.
>> As people have pointed out several times on this list to my knowledge,
>> Integer performance is not as good as Int performance, not hardly,
>> and it is silly to pay that price if I don't actually need it.
> Do I understand correctly that you advocate using overflowing ints (even
> if they signal overflow) even if Integers are fast enough for a
> particular program? I strongly disagree with this. It's premature
> optimisation of the worst kind - trading correctness for unneeded
"Fast enough" is not absolute. It's not trading correctness, it's
trading /completion/. And if you expect everything to fit in
[-2^31..2^31-1] or [0..2^32-1], finding out it doesn't might be valuable
information about your problem domain. For "exploratory" coding, speed
and knowing when something breaks can be more important than knowing
that all possible corner case are covered, even ones you don't expect to
>> SafeInt is what you should use when you *THINK* your results should all fit
>> in a machine int but aren't perfectly sure. (And this is nearly all the
> Again, I strongly disagree. You should use Integer unless your program
> is too slow and profiling shows that Integer is the culprit. If and only
> if that is the case should you think about alternatives. That said, I
> doubt that your SafeInt would be significantly faster than Integer.
Why? GMP is pretty good, but it's not going to be anywhere near
>> The checking I am talking about is done by the hardware at machine speeds
>> and provides *certainty* that overflow did not occur.
> So you advocate using different hardware?
At a minimum, any usable hardware sets flags on overflow.
Testing on those is pretty cheap. Much cheaper than calling a GMP
routine to compare with 2^32, for instance.
More information about the Haskell-Cafe