1

This code:

validate :: Matrix-> Bool
validate x: [] = length x
validate x: xs = (length x == lenght.head $ xs) == (validate tail xs)

produces this error:

Parse error in pattern: validate

Why?

My aim is to return true if the matrix is in the correct patterns, ie the number of columns in all the rows are equal, or vice versa.

0

1 Answer 1

13

Function application has higher precedence than operators such as :. So the compiler thinks:

validate x:[]

means:

(validate x):[] = ..

which is of course wrong.

So you should explicitly disambiguate this using brackets:

validate (x:[]) = ..

Similarly for the second line:

validate (x:xs) = ..

Also if you don't provide any brackets in function application then it is assumed to be left associative, so:

validate tail xs

is same as:

(validate tail) xs

and not:

validate (tail xs)

A common practice is to use the $ operator, as in:

validate $ tail xs
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.