Function type -postfix

Stefan Schulz schulz at the-loom.de
Tue Feb 16 10:52:52 PST 2010


On 09.02.2010 09:14, Peter Levart wrote:
> On Tuesday 09 February 2010 08:29:49 Stefan Schulz wrote:
>>
>> ##int(int)(int) or #int(#int(int)) [[int(int)](int)] or
>> [int([int(int)])]
>
> I have one objection to this syntax - it's too noisy on
> parens/brackets. The above example shows that even prefix notation is
> easier on the eye than your proposed bracketed syntax. It's nice if a
> pair of brackets or parens enclose the whole construct, but then it
> should not require a second pair of parens/brackets inside.

So I had a glimpse at Neal's blog, whose suggestion would result in:

   (int) -> (int) -> int
and
   ((int) -> int) -> int

for the above examples. To me, it's hard to spot the difference, which 
is in shifting braces a bit. I think that defining function types not 
necessarily has to resemble lambdas (although I thought this to be 
advantageous in the first). So having a syntax for function types that 
resembles the mathematical definition of a function could work quite 
well. I still advocate for some parentheses ;)

Mathematics (sort of):

   f: int -> (f: int -> int)
and
   f: (f: int -> int) -> int

Java function types, for example:

   (:int -> (:int -> int))
and
   (:(:int -> int) -> int)

While still the same amount of parens, this looks much clearer to me. 
But I might be wrong again. One could drop the colon, of course, but 
here's a smiley within ... actually it kind of resembles the f: if one 
squints. ;)

Would make the following syntax:

   FunctionType:
     (: TypeList_opt -> ResultType Throws_opt )


This also is very easy to distinct from concrete lambdas. To return to 
Neal's blog and his example:

static <T,U,V,X extends Throwable>
(:T->(:U->V throws X)) curry((:T,U->V throws X) function) {
    return #(T t)(#(U u)(function.(t,u)));
}


Cheers,
Stefan


More information about the lambda-dev mailing list