S.D.Mechveliani wrote:
> I wonder, why Haskell does not check/report the overflow for Int?
After thinking about this for awhile, I agree with Sergey that there
should be an Int datatype that truly implements partial functions, not
total functions modulo some large N. For a compiler emitting native
code, the overhead would be one instruction per operation, which is not
that bad, and the extra degree of safety is priceless, IMHO. For those
that don't want this feature, then I have no problem also providing an
IntMod32 datatype, or whatever; but let's call a spade a spade.
Of course I'm the last person that wants an endless debate to ensue
about this, given the trouble we have stabilizing the language, but
really, how many of you out there really want integer arithmetic modulo
some big N? I suspect almost none. Most of us would really prefer to
have an error signaled upon overflow.
Is there a way out of this mess? As Alastair has pointed out to me, the
Report apparently permits an implementation to realize Int's in either
manner. GHC and Hugs have chosen the easy way out -- i.e. ignore the
overflow -- but they could have just as well chosen to signal error on
overflow. So in the LEAST I would like to encourage the implementors
(he says shouting down the hall outside of his office :-) to provide a
compiler switch to allow overflow detection. A longer range goal could
be to tighten up the language spec, but for now we should at least allow
programmers to get the behavior that is "right".
-Paul