Thread overview
[OT] Language design question
May 26, 2009
Robert Fraser
May 27, 2009
Robert Fraser
May 28, 2009
Ary Borenszweig
May 26, 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
May 27, 2009
Robert Fraser wrote:
> fun fun $a() lazyApply(fun $a($b) f, $b x) => fun $a() => f(x);

And don't forget to take your fun fun (a banger in the mouth if you get the reference :-)).
May 28, 2009
Robert Fraser wrote:
> 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?

I like the 'x(y, z) syntax because its short. Too much fun is not fun. :-P

Do you need an extra symbol to denote a function type? Can't you just write:

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

Do you have ambiguities with that? I don't know your language, but if you only use function types when declaring a type, then I think there's no problem.