[OT] Language design question

Robert Fraser fraserofthenight at gmail.com
Tue May 26 16:54:58 PDT 2009


Hey all,

Without revealing too much I'm currently working on a programming 
language for a research project (it's implemented in D, of course!). I'm 
trying to figure out a good syntax for type annotations. I realized that 
under my current scheme the "fun" keyword in my language now serves 
three purposes:
- syntax sugar for declaring a function
- a type annotation for a function
- introducing a literal function/lambda

So a lazy evaluation/application could be written something like:

fun fun $a() lazyApply(fun $a($b) f, $b x) => fun $a() => f(x);

Where the first "fun" starts a function declaration, the next two 
indicate function types, and the last one indicates a lambda expression. 
This, if you'll forgive the pun, might not be so fun. Of course, since 
the language supports type inference, it could be written more simply as 
one of:

fun lazyApply(f, x) => fun() => f(x);
fun lazyApply(f, x) => f@(x);

(All are equavalent to the D2 closure function:

T delegate() lazyApply(t, U)(T delegate(U) f, U x)
	{ return T() { return f(x); } }

)

What do you think of this? Do I need to find a different syntax? Some 
other possible syntaxes I thought of (where x, y, and z are types)

{y, z -> x}
{(y, z) -> x}
'x(y, z)
\x(y, z) (Might be confusing since \ introduces lambda expressions in 
other languages)

Which would make the above monstrosity look like:

fun {-> $a} lazyApply({$b -> $a} f, $b x) => fun {-> $a} => f(x);
fun {() -> $a} lazyApply({($b) -> $a} f, $b x) => fun {() -> $a} => f(x);
fun '$a() lazyApply('$a($b) f, $b x) => fun '$a() => f(x);
fun \$a() lazyApply(\$a($b) f, $b x) => fun \$a() => f(x);

The short versions would remain the same in all cases:

fun lazyApply(f, x) => fun() => f(x);
fun lazyApply(f, x) => f@(x);

Any thoughts/suggestions?

Thanks,
Robert



More information about the Digitalmars-d mailing list