Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haskell

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?

like image 899
modeller Avatar asked Aug 07 '14 02:08

modeller


2 Answers

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.

like image 169
Daniel Wagner Avatar answered Sep 22 '22 02:09

Daniel Wagner


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.

like image 35
J. Abrahamson Avatar answered Sep 23 '22 02:09

J. Abrahamson