[Haskell-cafe] A question about "monad laws"
Richard A. O'Keefe
ok at cs.otago.ac.nz
Mon Feb 11 20:21:05 EST 2008
On 12 Feb 2008, at 10:35 am, David Benbennick wrote:
> Some months ago I pointed out that Ratio Int (which is an Ord
> instance) doesn't satisfy this property. I provided a patch to fix
> the problem, but my bug report was closed as wontfix:
I'm not happy about that response.
Basically, if the inputs to a mathematical operation are representable,
and the mathematically correct result is representable, I expect a
to deliver it or die trying. What the intermediate calculations get up
to is the implementor's problem, not the user's. On the other hand, if
I knew in advance whether a particular + or * was going to overflow, I
probably wouldn't need the computer to actually do it.
But if I give the computer some numbers that are clearly representable
and just ask it to *sort* them, it had better d--- well get that RIGHT.
I am extremely grateful for this report, because now I know
"NEVER USE Ratio Int, it's too broken".
Sad aside: back in the 70s I had my own Ratio Int written in Burroughs
Algol. I was not smart enough to use double precision numbers for
but because of one hardware feature, it didn't matter a lot. That
feature was that integer overflows were TRAPPED and REPORTED. I have
used precisely one C compiler on precisely one Unix system that took
of the fact that the C standard (both C89 and C99) was very carefully
to ALLOW TRAPPING of signed integer overflows. (Contrary to
only requires wrapping for unsigned integers.) I found that a
valuable debugging aid.
This all supports the general point, of course: data types whose
are so implemented as to break sensible laws can and WILL land you in
piles of fresh steaming hot fertiliser.
More information about the Haskell-Cafe