#2110: Rules to eliminate casted id's
--------------------------------+-------------------------------------------
    Reporter:  igloo            |       Owner:             
        Type:  feature request  |      Status:  new        
    Priority:  normal           |   Milestone:  6.10 branch
   Component:  Compiler         |     Version:  6.8.2      
    Severity:  normal           |    Keywords:             
  Difficulty:  Unknown          |    Testcase:             
Architecture:  Unknown          |          Os:  Unknown    
--------------------------------+-------------------------------------------
 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?

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2110>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to