Parentheses in the pattern matching in a function declaration Haskell

后端 未结 1 1477
温柔的废话
温柔的废话 2021-01-18 12:32

Do we have to use parentheses in pattern matching in function declarations ?

In example below, I have a pattern x:xs where x takes first el

相关标签:
1条回答
  • 2021-01-18 13:02

    Parentheses are not part of pattern matching, in the same sense that they are not part of expression evaluation. That being said, parentheses are certainly part of pattern and expression syntax.

    Look, if you write

    h x:xs
    

    this looks like

    (h x) : xs
    

    to the parser. Hence we write

    h (x:xs)
    

    both on the left hand side and on the right hand side of the equal sign. As expression, it means "function h applied to a list constructed of x and xs", and on the left hand side it defines an equation for that application.

    0 讨论(0)
提交回复
热议问题