|
![]() |
||||||||||||||
Program Structure TutorialFunctional Operator SyntaxThe usage of higher order functions and partial application assumes that used abstractions are functions and not operators. To make the usage of operators in these contexts possible, Wafl allows special functional syntax for operators. Operators may be used as functions if referenced using the name operator<op>. Even if operator - is used as both unary and binary operator, when it is used in functional form it is used exclusively as binary function. Source code:{# operator+(_,5)(10), apply( operator+(_,5), 10), apply( operator+(_,5), _)(10), apply2( operator+, _, _ )(5,10), apply2(_,5,10)(operator+) #} where{ apply(f,x) = f(x); apply2(f,x,y) = f(x,y); } Result:{# 15, 15, 15, 15, 15 #}
|
|
||||||||||||||
© 2006 Saša Malkov | |||||||||||||||