“表达式上下文中的模式语法”错误

时间:2011-12-08 16:55:43

标签: haskell

不知道问题是什么。完全遵循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

1 个答案:

答案 0 :(得分: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))@

-}

需要转义反斜杠才能显示它们。