[Haskell-cafe] Can't figure out cmap in hmatrix
Mats Klingberg
maklingberg at gmail.com
Mon May 30 21:27:29 CEST 2011
Hello,
I'm playing around a bit with the hmatrix package (http://hackage.haskell.org/package/hmatrix) but can't quite figure out how to make the cmap function in Numeric.Container work.
An example:
ghci> import Numeric.LinearAlgebra
ghci> let v = fromList [1.0,2.0,3.0]
ghci> v
fromList [1.0,2.0,3.0] :: Data.Vector.Storable.Vector
ghci> :t v
v :: Vector Double
ghci> cmap sqrt v
<interactive>:1:1:
No instance for (Container Vector e0)
arising from a use of `cmap'
Possible fix: add an instance declaration for (Container Vector e0)
In the expression: cmap sqrt v
In an equation for `it': it = cmap sqrt v
ghci> :t cmap
cmap
:: (Container c e, Element b, Element a) => (a -> b) -> c a -> c b
There is an instance for (Container Vector Double) but I assume that since the signature of cmap doesn't mention the type variable 'e' GHCi can't infer it. Googling hasn't helped me so far, except for digging up another post to this list with the same (?) problem, but no answer: http://www.haskell.org/pipermail/haskell-cafe/2011-April/091390.html
Is there a way to tell GHC what instance to use, or how should cmap be used?
Thanks!
Mats
More information about the Haskell-Cafe
mailing list