Haskell Operator Priority

I got confused about the rules for operator precedence in Haskell.
In particular, why is this:

*Main> 2 * 3 `mod` 2 0 

different from this?

 *Main> 2 * mod 3 2 2 
+6
source share
2 answers

Functional calls connect the densest, therefore

 2 * mod 3 2 

coincides with

 2 * (mod 3 2) 

Keep in mind that mod not used as an operator here, as there are no backlinks.

Now that mod used in infix form, it has priority 7, which also has (*) . Since they have the same predictability and are left-associative, they are simply analyzed from left to right:

 (2 * 3) `mod` 2 
+13
source

2 * 3 = 6, and then mod 2 = 3 without a remainder ... so 6 mod 2 = 0 is your answer. In your second case, you make 2 * the result of mod 3 2 , which is 2 * 1 = 2 . Therefore, your answer is 2 .... Your priority of your operator has not changed, you just agreed on this so that the answers are expressed accordingly.

+2
source

All Articles