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
f(x,y)you can now (as of v1.5) call the functoid using infix syntax as
x ^f^ yWe 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,
plus(2,3)is ok, but
2 ^plus^ 3reads 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^ 0means 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
f[X,Y]you can write
X %f% YSee 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