modeller
modeller

Reputation: 3850

Why does "(`subtract`) 1 2" fail?

If back-tick changes a prefix function to infix, and parenthesis changes a infix function to prefix, then:

Syntactically, why would (`subtract`) 1 2 fail?

Upvotes: 9

Views: 259

Answers (2)

Daniel Wagner
Daniel Wagner

Reputation: 152707

Although "backticks turn prefix to infix and parentheses turn infix to prefix" is a convenient mental shortcut, it is not a precise description of the Haskell syntax. For that, you should turn to the Report, which makes it clear that the class of things that can go inside backticks (or parentheses) is quite restricted. The only thing allowed in backticks is simple identifiers, and likewise for the kind of parentheses that make infix things prefix.

Upvotes: 19

J. Abrahamson
J. Abrahamson

Reputation: 74344

Backticks are "just syntax". Which is a kind way of saying that they're a hack. Instead of trying to build them an everywhere consistent mechanism the designers of Haskell opted to just give one simple trick as syntax sugar.

Sadly there's not really a much more interesting answer to be had.

Upvotes: 7

Related Questions