Rules to eliminate casted id's
|Reported by:||igloo||Owned by:|
|Keywords:||Cc:||rl, dimitris@…, ryani.spam@…, mail@…, sweirich@…, hackage.haskell.org@…, bgamari@…, eir@…|
|Type of failure:||None/Unknown||Test Case:||tests/simplCore/should_run/T2110|
|Related Tickets:||#8767||Differential Rev(s):|
Some people (e.g. jedbrown, who originally brought this up) have/use C libraries that deal with arrays of doubles (i.e. CDouble) that they would like to use from Haskell code, with the Double type (perhaps there are instances of some classes for Double, but not CDouble). In jedbrown's case he has a CArray datastructure that wraps the C array and is an instance of Haskell's IArray.
However, people doing this sort of thing tend to care a lot about performance, so don't want to spend O(n) time doing O(n) allocation. Thus the temptation is to make the assumption that CDouble == Double, and to create the CArray i Double directly.
The more correct way to do it would be to make a CArray i CDouble and then use amap realToFrac to convert it to a CArray i Double. However, I don't believe that GHC is currently smart enough to optimise away amap realToFrac.
Let's look at a simpler example:
cdoubles :: [CDouble] cdoubles = read "foo" doubles :: [Double] doubles = map realToFrac cdoubles
(here map is playing the role of amap). The core for this looks like (very simplified)
Q.a1 = \ (ds_aMc :: Foreign.C.Types.CDouble) -> ds_aMc Q.doubles = GHC.Base.map (Q.a1 `cast` <mumble>) Q.cdoubles
It looks to me that if we could produce
Q.doubles = GHC.Base.map (id `cast` <mumble>) Q.cdoubles
instead then we might be able to have a rule
forall mumble . map (id `cast` mumble) = id `cast` mumble'
The major problem, as far as I can see, is how to construct the mumble'.
Does that sound plausible?
Change History (49)
comment:5 follow-up: ↓ 21 Changed 7 years ago by simonpj
- Cc rl dimitris@… added
- Type of failure set to None/Unknown
comment:7 Changed 6 years ago by igloo
- Milestone changed from 6.12.3 to 6.14.1
- Priority changed from normal to low
comment:11 Changed 5 years ago by igloo
- Milestone changed from 7.4.1 to 7.6.1
- Priority changed from low to lowest
comment:48 Changed 3 years ago by nomeata
- Resolution set to fixed
- Status changed from patch to closed