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

Ben Franksen ben.franksen at online.de
Mon Feb 18 13:41:57 EST 2008


Wilhelm B. Kloke wrote:
> 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.

Obviously ;)

> 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.

I agree completely.

Cheers
Ben



More information about the Haskell-Cafe mailing list