[Haskell-cafe] GHC optimisations

Neil Mitchell ndmitchell at gmail.com
Wed Aug 22 04:43:32 EDT 2007


Hi

> Other rules that could be interesting are:
>  > forall a b. fromInteger a + fromInteger b = fromInteger (a + b)
>  > forall a b. fromInteger a * fromInteger b = fromInteger (a * b)

This is wrong, since the class function can do what it wants. Imagine:

instance Num String where
   (+) = (++)
   fromInteger x = show x

1 + 2 :: String

this expression now goes from "12" to "3" by applying this rule.

You need to be incredibly careful if there are any classes floating around.

Thanks

Neil


More information about the Haskell-Cafe mailing list