Hacker News new | ask | show | jobs
by iman 5976 days ago
What about functions of type A x B -> A ?

An example would be C++ stream << operator which takes a stream on the left, a string on the right, and returns a stream (after writing the string into the stream). This is so that you can do chaining:

    cout << "Hello" << "World";
I don't think that there are any mathematical operators that work this way though.
2 comments

It seems like, to have associativity in the sense of "(a+b)+c = a+(b+c)", you'd have to extend << to also become the string concatenation operator in C++. There are quite a few rules that need to hold to make it work...
One of the comments on the post (by Mathnerd314) says that Icon implements its comparison operators that way (if the comparison succeeds, it returns the 2nd argument).