What it means to infix on Haskell

Asked

Viewed 150 times

8

What is and what this infixr 3 is for &&?

infixr 3 &&
(&&) :: Bool -> Bool -> Bool
True && True = True
_ && _ = False
  • 2

    If you understand English, see the answer to this question: http://stackoverflow.com/questions/27770118/how-does-the-infix-work

1 answer

6

Infixed notation means that the operator comes between operands, for example 1 + 1. Functions in Haskell usually use fixed notation, for example pow 1 2.

The r or l refers to the association, r for right associativity (right-wing associativity) and l for left associativity (left associativity). For example, the arrow operation is infixr, for A -> A -> A means A -> (A -> A).

But we can also use only the notation infix and not provide the associativity, in which case if you try to write a code using several times that operator without parentesis, will give error, because the interpreter will not know in which order to interpret.

In his example True && True && True will be interpreted as True && (True && True)

The number refers to precedence, the greater the number, the greater the precedence.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.