New infix syntax

FC++ v1.5 offers a new infix syntax that can be used with full functoids. The syntax is inspired by the Haskell programming language.

Given a two-argument full functoid which can normally be called as

you can now (as of v1.5) call the functoid using infix syntax as
   x ^f^ y
We overload operator^ for full functoids to make this work. The goal is to write more readable code, as some named functions "read" best infix (rather than prefix). For example,
is ok, but
   2 ^plus^ 3
reads more nicely.

(Note that this also works for 3-argument functoids using implicit currying. Here's an example using the 3-ary functoid foldl:

   plus ^foldl^ 0
means the same as
   foldl( plus, 0 )
which results in a function which sums the values in an integer list.)

For lambda expressions, we overload operator% so that instead of

you can write
   X %f% Y
See the discussion about lambda for more details.

Important: note that infix functions adopt the precedence and associativity of their C++ operators. So unless you know C++ operator precedence and associativity rules very well, we recommend that you use parentheses:

   // desired: y+3*x   ( Note: equals  y+(3*x) )
   y ^plus^ (3 ^multiplies^ x)   // good
   // probably wrong:   y ^plus^ 3^multiplies^x

Last updated on May 20, 2003 by Brian McNamara