2

So I wanted to understand the functions foldl and foldr in Hoogle they say that these functions apply to binary operators. But I don't get what these binary operators are. I know that (+) and (-) are binary operators but what defines them ?

2
  • 1
    In Haskell a binary function is a function which doesn't deal with functors, aplicative functors, monadic values etc as arguments or returned values. In another words just simple functions are binary functions. Commented Jul 18, 2017 at 19:58
  • @Redu That's not what a binary function is. I'm not sure I know of a term for what you're describing, actually ("first-order function" almost comes close "in spirit," but they can involve functors, etc). Commented Jul 18, 2017 at 23:37

1 Answer 1

3

Usually mathematicians define a binary operator is a function that takes two arguments. In some papers it is a requirement that the arguments and the result are defined over the same set.

The fact that the function ? takes two arguments results in the fact that mathematicians frequently use infix notation (like x ? y). For instance (+), (*), etc. are clearly binary operators.

Sign up to request clarification or add additional context in comments.

8 Comments

Oh so that binary stands for the operator is taking two elements.. well that should be obvious to me. Thanks
I don't think the term usually implies that both operands are from the same set. Like, I'd imagine most people consider division to be a binary operator even though it's type is R * R \ {0} -> R, not R * R -> R. And in the specific context of the fold functions, "binary operator" definitely does not imply that the operand types must be the same, as that is not the case.
Yes you are right but the word binary is kind of a hint for that.
@sepp2k surely the division operator is partial with type R * R -> R?
(:) is an obvious example of a binary operator whose two arguments are not of the same type.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.