2011-12-08 25 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