[EMAIL PROTECTED] <[EMAIL PROTECTED]> writes:
>
> GHC has strange behavior on perverse numeric instances. Given this:
>
> newtype T = T Integer deriving (Show)
> instance Eq T
> instance Num T
> main = putStrLn $ case T 2 of
> 4 -> "4"
> _ -> "_"
>
> it outputs 4, even though (==) and fromInteger are undefined. With
> (==) explicitly defined as undefined, it fails as expected - but
> omitting the (==) definition should give the same effect (modulo
> the error message). It seems to not use fromInteger at all, even in
> expressions, if T is a newtype for Int or Integer, but uses it for
> other types and always for data.
>
Really, it terminates? My copy (ghc-4.05) blows the stack, which is
sort of what I'd expect here ( Eq.(==) is defined in terms of Eq.(/=),
and vice versa, so if you haven't got neither you're kind of stuck.)
Re: fromInteger, make sure you try this on integer literals outside
of Int's range, so that GHC's machinery for using Num.fromInt
doesn't kick in.
--sigbjorn