2011-12-08 23 views
1

不知道问题出在哪。继完全HMATRIX buildMatrix DOC:“表达式上下文中的模式语法”错误

Prelude Data.Packed.Matrix> let k= buildMatrix 3 4 ((r,c) -> fromIntegral r * fromIntegral c) 

<interactive>:1:26: 
    Pattern syntax in expression context: 
     (r, c) -> fromIntegral r * fromIntegral c 
+3

缺少lambda的反斜线? '(\(r,c) - > ...)'? –

+0

很酷的工作!在这里,我想也许有某种特殊的导入使得元组的工作方式不同。 – drozzy

+0

@drozzy考虑标记他的答案作为答案然后:) – Phyx

回答

4

在文档中,标记不正确转义,它必须是

let k = buildMatrix 3 4 (\(r,c) -> fromIntegral r * fromIntegral c) 

的黑线鳕标记被

{- | creates a Matrix of the specified size using the supplied function to 
to map the row\/column position to the value at that row\/column position. 

@> buildMatrix 3 4 (\ (r,c) -> fromIntegral r * fromIntegral c) 
(3><4) 
[ 0.0, 0.0, 0.0, 0.0, 0.0 
, 0.0, 1.0, 2.0, 3.0, 4.0 
, 0.0, 2.0, 4.0, 6.0, 8.0]@ 

Hilbert matrix of order N: 

@hilb n = buildMatrix n n (\(i,j)->1/(fromIntegral i + fromIntegral j +1))@ 

-} 

反斜线需要为了逃避他们的显示。

+0

谢谢,现在它似乎不工作在我的代码:-) http://stackoverflow.com/questions/8434808/how-to-build-matrix-of-zeros-using-hmatrix – drozzy