[Haskell-cafe] trying to go from FFT type to Vector.Storable

briand at aracnet.com briand at aracnet.com
Fri May 15 05:22:55 UTC 2015


On Thu, 14 May 2015 02:31:55 -0400
Leza Morais Lutonda <leza.ml at fecrd.cujae.edu.cu> wrote:

> On 05/14/2015 12:51 AM, briand at aracnet.com wrote:
> I think the problem is in the way of seeing the types and type classes.
> First, the type of `ys` is not `Vector.Storable (Complex Double)`, it is 
> Vector (Complex Double).

Well that may be, but when I try to use Vector (Complex Double) with hmatrix it doesn't work.  I have to make sure to use/import Vector.Storable.

Meanwhile, back at the fft example.

import qualified Data.Vector.Storable as V
import Data.Complex
import Math.FFT(dft)
import Math.FFT.Base(FFTWReal)
import Data.Array.IArray(elems)
import Data.Array.CArray(listArray)

vectorToArray v = listArray (0, V.length v - 1) (V.toList v)
arrayToVector = V.fromList . elems

fft :: FFTWReal r => V.Vector (Complex r) -> V.Vector (Complex r)
fft = arrayToVector . dft . vectorToArray

And the following error messages are why i get very little done in an evening of haskell hacking.
To understand those error messages I'd have to be so good with haskell that I wouldn't actually need those error messages, or so it seems to me.

Clearly I have something important to learn about what you are saying about type classes. 

So I'll stare at this for a few more hours, and try random type assignments until it works.  Meanwhile, along the way, I may type up one of Shakespeare's plays...

Thanks very much for your help.

simple.hs:9:17:
    No instance for (V.Storable a0) arising from a use of ‘V.fromList’
    The type variable ‘a0’ is ambiguous
    Relevant bindings include
      arrayToVector :: Data.Array.CArray.Base.CArray Int a0
                       -> V.Vector a0
        (bound at simple.hs:9:1)
    Note: there are several potential instances:
      instance V.Storable a => V.Storable (Complex a)
        -- Defined in ‘Data.Complex’
      instance V.Storable GHC.Fingerprint.Type.Fingerprint
        -- Defined in ‘Foreign.Storable’
      instance V.Storable GHC.Int.Int16 -- Defined in ‘Foreign.Storable’
      ...plus 18 others
    In the first argument of ‘(.)’, namely ‘V.fromList’
    In the expression: V.fromList . elems
    In an equation for ‘arrayToVector’:
        arrayToVector = V.fromList . elems

simple.hs:12:7:
    Couldn't match type ‘a0’ with ‘Complex r’
      because type variable ‘r’ would escape its scope
    This (rigid, skolem) type variable is bound by
      the type signature for
        fft :: FFTWReal r => V.Vector (Complex r) -> V.Vector (Complex r)
      at simple.hs:11:8-65
    Expected type: Data.Array.CArray.Base.CArray Int a0
                   -> V.Vector (Complex r)
      Actual type: Data.Array.CArray.Base.CArray Int a0 -> V.Vector a0
    Relevant bindings include
      fft :: V.Vector (Complex r) -> V.Vector (Complex r)
        (bound at simple.hs:12:1)
    In the first argument of ‘(.)’, namely ‘arrayToVector’
    In the expression: arrayToVector . dft . vectorToArray


More information about the Haskell-Cafe mailing list