Why is (.) called infix as just . rather than `(.)`

后端 未结 1 850
抹茶落季
抹茶落季 2021-01-23 06:46

I learned that functions can be invoked in two ways; prefix and infix. For example, say I\'ve created this function:

example :: [Char] -> [Char] -> [Char]
         


        
相关标签:
1条回答
  • 2021-01-23 07:05

    There's nothing deep here. There's just two kinds of identifiers that have different rules about how they're parsed: by-default-infix, and by-default-prefix. You can tell which is which, because by-default-infix identifiers contain only punctuation, while by-default-prefix identifiers contain only numbers, letters, apostrophes, and underscores.

    Recognizing that the default isn't always the right choice, the language provides conversions away from the default behavior. So there are two separate syntax rules, one that converts a by-default-infix identifier to prefix (add parentheses), and one that converts a by-default-prefix identifier to infix (add backticks). You can not nest these conversions: a by-default-infix identifier converted to prefix form is not a by-default-prefix identifier.

    That's it. Nothing fundamentally interesting -- all of them become just function applications once parsed -- it's just syntax sugar.

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