0

I created this program to return a list of positions of a matrix that no has zero value.

This Code:

type Pos = (Int,Int)
type Matrix = [[Int]]

v0 [Pos]->Matrix->[Pos]
v0 [] m =[]
v0 [p:ps] m = if ((takeH m p) == 0) then v0 ps m
                                    else p:v0 ps m

takeH:: Matrix->Pos->Int
takeH m (i,j)= (m!!(i-1))!!(j-1)

Produces this error:

Parse error on input '->'
Failed,modules loades: nome.

Why ?

I hope that I've been clear.

1
  • 2
    Did you forget :: in v0 [Pos]->Matrix->[Pos] ? v0 :: [Pos]->Matrix->[Pos] Commented Oct 10, 2012 at 11:08

2 Answers 2

4

You need :: before the type of a function.

-- vv here
v0 :: [Pos] -> Matrix -> [Pos]
v0 [] _ = []
-- v    v also parenthesis, not square brackets
v0 (p:ps) m = if ((takeH m p) == 0) then v0 ps
                                    else p:v0 ps
Sign up to request clarification or add additional context in comments.

Comments

0

Also your takeH function needs to take a Matrix and a Pos as arguments, but you only seem to pass it a Pos...? I assume you want something like takeH x (i, j) = (x!!(i-1))!!(j-1).

In general, I highly warn against using partial functions such as !!. What if your Matrix doesn't contain enough values, and goes out of bounds? Your program will terminate and throw an error. Take that into consideration as well

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.