Function types syntax
Rémi Forax
forax at univ-mlv.fr
Wed Jan 27 05:44:42 PST 2010
Postfix notation (arrow) have also a problem with array brackets,
int -> int[] can be a function type that return int[] or an array of
function type that returns int.
Rémi
Le 27/01/2010 10:08, John Rose a écrit :
> On Jan 27, 2010, at 12:18 AM, Zdenek Tronicek wrote:
>
>
>> John Rose napsal(a):
>>
>>> stringLength = #(String s) int length: {
>>> if (s == null) break length = -1;
>>> length = s.length();
>>> };
>>>
>> Where will the throws clause be placed?
>>
>> #(String)->int (throws IOException, InterruptedException) stringLength;
>>
> I suppose that could work although it doesn't work well with higher-order functions.
>
> But to best exploit the postfix style, the normal return type should be last. So throws would go before a postfix return type:
>
> (String)->throws IOException | InterruptedException stringLength;
>
> public abstract (File) throws IOException -> (char[], int, int) throws IOException -> int streamOpener();
>
> (I've somewhat randomly changed (throws T, U) to throws T | U, just to air it a bit.)
>
>
>> stringLength = #(String s) int (throws IOException,
>> InterruptedException) length: {
>> if (s == null) break length = -1;
>> length = s.length();
>> };
>>
> Actually, I don't think explicit 'throws' clauses on lambdas (as opposed to function types) are either necessary or desirable.
>
> But supposing they were, the previous pattern probably works:
>
> stringLength = #(String s) throws IOException, InterruptedException
> int length: {
> if (s == null) break length = -1;
> length = s.length();
> };
>
> (Again, randomly airing throws T, U instead of the parenthesized version (throws T, U).)
>
> It would seem nice to me (this is primarily an esthetic judgement) if we modernized combined throw types to use bar '|'. The old comma ',' would be supported as a "classic" syntax, but only for method declarations, not types or expressions. Those commas get pretty dicey when you mix them up into an expression or type, especially when you add angle brackets also. If we must use ',' to separate throw types, we probably have to add parens around them. But at that point, since the resemblance to method declarations is spoiled, there's less reason to stay with commas, and '|' OTOH more clearly expresses the relevant union type.
>
> -- John
>
>
More information about the lambda-dev
mailing list