Andriy Drozdyuk
Andriy Drozdyuk

Reputation: 61091

"Pattern syntax in expression context" error

No idea what the problem is. Following exactly the 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

Upvotes: 1

Views: 1741

Answers (1)

Daniel Fischer
Daniel Fischer

Reputation: 183888

In the docs, the markup wasn't properly escaped, it must be

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

The haddock markup was

{- | 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))@

-}

The backslashes need to be escaped for them to be displayed.

Upvotes: 4

Related Questions