Function type -postfix

Rémi Forax forax at univ-mlv.fr
Tue Feb 9 03:24:40 PST 2010


Le 09/02/2010 08:29, Stefan Schulz a écrit :
> And I still wonder, why not using a clear, lambda-resembling syntax 
> with mandatory brackets instead of a leading #. It would clearly 
> separate nested function types and not require extra parens for throws 
> declaration. Having optional parens that are mandatory in some cases 
> does not sound convincing to me, despite that postfix syntax "reads 
> the wrong direction" for the common Java developer's eye.
>
> Examples within for comparison.
>
> On 09.02.2010 02:14, Rémi Forax wrote:
>> int->int
>
> #int(int)   // draft
> [int(int)]  // brackets
>
>> int,int->int
>
> #int(int,int)
> [int(int,int)]
>
>> I think this syntax will not generate conflicts despite the fact
>> that ',' can be used in expressions if int->int.class and
>> implementing a function type are not allowed.
>
> #int(int).class // not sure
> [int(int)].class
>
>> Here parenthesis are mandatory, the rule is if you want to have
>> a function type in a function type, parens are required:
>> int, (int->int)->int
>
> #int(int, #int(int))
> [int(int, [int(int)])]
>
>> this means that int ->  int ->  int is illegal and
>> should be written:
>> int ->  (int ->  int) or (int ->  int) ->  int
>
> ##int(int)(int) or #int(#int(int))
> [[int(int)](int)] or [int([int(int)])]
>
>> (int->int)[]
>
> #int(int)[]
> [int(int)][]
>
>> int,int throws Exception->int
>
> #int(int,int) (throws Exception)
> [int(int,int) throws Exception]
>
>> int, (int ->  int) throws Exception->int
>
> #int(int, #int(int) (throws Exception))
> [int(int, [int(int) throws Exception])]
>
>> int, (int throws Exception ->  int) ->  int
>
> #int(int, #int(int) (throws Exception))
> [int(int, [int(int) throws Exception])]
>
> "brackets" add one character per function type compared to "draft" but 
> parenthesises a type, not only introduces one.
>
> I only can think of one place of "visual" conflict, where an array is 
> defined giving its size by a method:
>
> Object[size(param)]
>
> But maybe I overlooked something.
>
> Stefan
>

Stefan,
I've tried to explain prefix and postfix notation last week-end at FOSDEM.
At the end of the talk and the day after, I've talked to 'real' people 
about that.
Here are the questions often asked about the function type syntax:
- I prefer prefix syntax: #int(int) is more Java-like than int -> int
- why do you need parenthesis between the throws [in the prefix syntax] ?
- I don't understand ##int()int()int could you explain it ?

Now you know as much as me :)

About your syntax, I wonder if there is not a conflict with upcoming 
coin syntax
for collection litteral.
As Peter says mixing parenthesis and brackets make the syntax is barely 
unreadable.

In my opinion, if you have function type that contains a function type,
having parenthesis is mandatory because it's more readable.
Having encompassing parenthesis doesn't play well with
prefix syntax that also required parenthesis to separate return type from
parameter types.

Rémi








More information about the lambda-dev mailing list