-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type inference keyword for lambda parameters #1391
Comments
@Zambonifofex do you have any usecases for annotating a parameter of an anonymous function? |
@gavinking well, you can annotate it |
Well a As for ceylondoc annotations I don't think they belong on the parameters of an anonymous function at all because (1) they would be ignored by ceylondoc (there is no doc generated for an anon function) and (2) adding doc strings and annotations in the middle of an expression seems just a bit awful. There are lots of other uses for annotations, but they're uses that only really apply to APIs, not to anonymous functions which are fundamentally internal implementation details of a body of something. So I guess I just don't see this. |
No, I mean documentate it for people reading the source code. For example: Someone might make a You don't do: foo = bar; Instead, you do: value foo = bar; Similarly, you don't do: foo(function(bar) => baz)); Instead, you do: foo(function(value bar) => baz)); |
Well that's what comments are for, no? :) Annotations are for tools and frameworks. |
Ah I see. But:
is a shortcut for:
It's already regular :-) |
Sure, but in my opinion, it's better to be explicit about the fact that you are declaring a new thing... At least allowing people to use a keyword can't be a bad thing, can it? :-P As well as allowing them to use the keyword if it's declared in the function body: foo(function(bar) { value bar; return baz; }); I don't know... I just don't like seeing |
The way I see this, it adding this little extra bit of explicit annotation is certainly more regular but that regularity does not buy us anything that would warrant the cost of more verbosity. Ceylon has so far managed to strike a pretty good balance between verbose keyword heavy declarative syntax and concise expressive code. I would argue that adding more verbose syntax to anonymous functions would tip that balance to the point where using anonymous functions becomes almost as verbose as declaring those functions on the top level explicitly and using function references explicitly. This is undesirable in my mind, as this will encourage wrong style of programming -- the code that makes sense only in the context of an anonymous function call site, will be divorced of it's context. I'd say, the anonymous function syntax in Ceylon is really just as light weight as it needs to be and no lighter than it has to be. |
I agree, but as I said,
Not forcing, but allowing. Similar to for(Character character in "Hello")
{} for(character in "Hello")
{} for(value character in "Hello")
{} |
Currently, the following is allowed:
I think that instead it should be:
And also:
This would allow us to annotate a parameter and simultaneously have its type inferred, which is impossible today as far as I know, besides being more regular...
The text was updated successfully, but these errors were encountered: