realToFrac into Complex Double has no specialization
Example:
module Foo where
import Data.Complex
f :: Double -> Complex Double
f x = realToFrac x
ghc -O -ddump-simpl
gives:
f =
\ (w_s17v :: Double) ->
case w_s17v of _ [Occ=Dead] { GHC.Types.D# ww1_s17y ->
case GHC.Float.$w$ctoRational ww1_s17y
of _ [Occ=Dead] { (# ww3_a152, ww4_a153 #) ->
case GHC.Float.rationalToDouble ww3_a152 ww4_a153
of dt_a15c { GHC.Types.D# ipv_a15g ->
Data.Complex.:+ @ Double dt_a15c Data.Complex.$fFloatingComplex1
}
}
}
This means the conversion goes through Rational. However, in this case, the conversion could be done much more efficiently with (:+0)
. It would be nice if this happened automatically.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |