Reputation: 7327
Typing the following into a GHC interpreter yields no error:
let head' (x:_) = x
But if we remove the parentheses:
let head' x:_ = x
...we obtain:
Parse error in pattern: head'
Why are the parentheses necessary?
Upvotes: 2
Views: 126
Reputation: 26117
In Haskell, function application has higher precedence than any operator, and pattern-matching reflects that.
So, without the parentheses, head' x:_
is parsed as (head' x):_
, which doesn't make sense in this context, and causes an error.
Upvotes: 10