Haskell infix syntax

Simen kjaeraas simen.kjaras at gmail.com
Sun Mar 6 09:40:36 PST 2011


bearophile <bearophileHUGS at lycos.com> wrote:

>> So I think it's not worth adding to D.
>
> But if you don't agree... talk.

This is basically already possible in D:

struct InfixOperator( alias fn ) {
     auto opBinaryRight( string op : "/", T )( T lhs ) {
         struct crazy {
             T value;
             auto opBinary( string op : "/", U )( U rhs ) {
                 return fn( rhs, value );
             }
         }
         return crazy(lhs);
     }
}

@property auto _( alias fn )( ) {
     return InfixOperator!fn( );
}

T add( T )( T a, T b ) {
	return a + b;
}
unittest {
     assert( 2 /_!add/ 3 == 5 );
}



-- 
Simen


More information about the Digitalmars-d mailing list