GHC: Ticket #2099: Storable instance for Complex
http://ghc.haskell.org/trac/ghc/ticket/2099
<p>
I propose that the following instance be added to base:
</p>
<pre class="wiki">instance (RealFloat a, Storable a) => Storable (Complex a) where
sizeOf z = 2 * sizeOf (realPart z)
alignment z = sizeOf (realPart z)
peek p = do
[r,i] <- peekArray 2 (castPtr p)
return (r :+ i)
poke p (r :+ i) = pokeArray (castPtr p) [r,i]
</pre><p>
This instance is binary compatible with C99, C++ and Fortran complex types.
</p>
<p>
It is currently needed by at least two independent packages: hmatrix and fft. Since it is natural for user code to use both of these packages, we need to move the instance to a common location.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/2099
Trac 1.0.1iglooSat, 16 Feb 2008 13:56:45 GMTdifficulty, milestone set
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:1
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:1
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
<li><strong>milestone</strong>
set to <em>Not GHC</em>
</li>
</ul>
TicketsimonmarMon, 18 Feb 2008 12:12:23 GMT
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:2
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:2
<p>
This is slightly dubious. <tt>Storable</tt> is for types that have a single direct analogue on the C side: for example, <tt>CInt</tt> maps to <tt>int</tt>, <tt>Double</tt> maps to <tt>HsDouble</tt>. What does <tt>Complex Int64</tt> map to? Perhaps you don't really mean <tt>Storable (Complex a)</tt>, but instead the three instances for <tt>CFloat</tt>, <tt>CDouble</tt> and <tt>CLongDouble</tt>?
</p>
TicketjedbrownMon, 18 Feb 2008 14:01:43 GMT
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:3
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:3
<p>
Care to write a RealFloat instance for Int64?
</p>
<p>
It is true that what you describe would be sufficient for my needs, but I don't think the general instance is too general. All this instance prescribes is the ordering of real and imaginary components which is quite standard. With regard to Haskell versus C types, how likely is it that Double /= CDouble at some point? I'm curious what the best practice is for high performance numerics libraries where marshaling arrays in and out of each foreign call is not acceptable. This appears to mean that C types must extend arbitrarily deeply into the Haskell world which seems to defeat the point of having separate types. The libraries that I'm familiar with (hmatrix and fft) assume that Double == CDouble so they are broken if this doesn't hold.
</p>
<p>
Note: There is now 'storable-vector' on Hackage which defines this instance. fft-0.1.1 depends on it and Alberto tells me that hmatrix will soon.
</p>
TicketiglooMon, 18 Feb 2008 14:55:16 GMT
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:4
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:4
<p>
A bit off-topic, but you should assume that Double /= CDouble, and convert with realToFrac (in a thin wrapper around the FFI imports, where you are doing things like checking errno and reading results in from pointers, is normally a sensible place to do the conversion). When Double == CDouble, this should be optimised away to no code.
</p>
TicketiglooFri, 11 Jul 2008 13:27:47 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:5
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:5
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>wontfix</em>
</li>
</ul>
<p>
This proposal seems to be abandoned
</p>
TicketsimonmarTue, 30 Sep 2008 15:45:16 GMTarchitecture changed
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:6
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:6
<ul>
<li><strong>architecture</strong>
changed from <em>Multiple</em> to <em>Unknown/Multiple</em>
</li>
</ul>
TicketsimonmarTue, 30 Sep 2008 15:54:53 GMTos changed
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:7
http://ghc.haskell.org/trac/ghc/ticket/2099#comment:7
<ul>
<li><strong>os</strong>
changed from <em>Multiple</em> to <em>Unknown/Multiple</em>
</li>
</ul>
Ticket