[Haskell-cafe] Re: A question about "monad laws"

Wilhelm B. Kloke wb at arb-phys.uni-dortmund.de
Fri Feb 15 02:37:05 EST 2008

Ben Franksen <ben.franksen at online.de> schrieb:
> Wilhelm B. Kloke wrote:
>> ajb at spamcop.net <ajb at spamcop.net> schrieb:
>> I would consider a good idea if ghc would provide language support to
>> this sort of integers.
> No need, you can do that for yourself:
> {-# LANGUAGE GeneralizedNewtypeDeriving #-}
> newtype DInt = DInt Double deriving (Eq, Ord, Enum, Num)
> instance Show DInt where show (DInt x) = show (truncate x :: Integer)

Probably you missed the point I wanted to make. This works only properly,
if you can catch the Inexact Trap which indicates the overflow. The problem
whith normal Ints is that the hardware does not support overflow detection.
You get silent wrong results if you use an Int type which maps to
C int, but not if it maps to C float or double with Inexact trap enabled.
Therefore you need add runtime checks to be sure that you notice
a possible overflow condition.
Dipl.-Math. Wilhelm Bernhard Kloke
Institut fuer Arbeitsphysiologie an der Universitaet Dortmund
Ardeystrasse 67, D-44139 Dortmund, Tel. 0231-1084-257
PGP: http://vestein.arb-phys.uni-dortmund.de/~wb/mypublic.key

More information about the Haskell-Cafe mailing list