| GHC's Int and Word modules export a vast amount of coercion functions
| (like int8ToInt16, intToWord16, ...) which are all subsumed by the
| single standard function fromIntegral. But currently one can't tell
| GHC, e.g.:
| 
|    {-# SPECIALIZE fromIntegral :: Int8 -> Int16 = int8ToInt16 #-}
| 
| because the "=..." clause has vanished. Are there plans to 
| resurrect it?

Aha.  I have a good answer to that!  Use:

{-# RULES
        "fromIntegral/Int8->Int16" fromIntegral = int8ToInt16
#-}

The compiler adds the type stuff to get the typed rule

        forall (d1::Integral Int8) (d2::Num Int16) .
                fromIntegral Int8 Int16 d1 d2 = int8ToInt16

and that matches at exactly the right moment.  What's more,
this rule does not need to be in the same file as fromIntegral,
unlike the SPECIALISE pragmas which currently do (so that they
have an original definition available to specialise).

Simoin

Reply via email to