-
Notifications
You must be signed in to change notification settings - Fork 62
refine Callable
attributes as if they were functions and vice‐versa
#6424
Comments
Shortcut refinement supports both directions already: abstract class Foo()
{
shared formal String(String) surround;
}
class Bar()
extends Foo()
{
surround(String str) => "\{RIGHT DOUBLE QUOTATION MARK}``str``\{LEFT DOUBLE QUOTATION MARK}";
} abstract class Foo()
{
shared formal String id(String str);
}
class Bar()
extends Foo()
{
id = identity<String>;
} abstract class Foo<out T>()
{
shared formal T member;
}
class Bar()
extends Foo<String(String)>()
{
member(String str) => "\"``string``\"";
} |
Fascinating. I guess that means it works for locals as well, right? I’m sure this used to not compile: shared void run()
{
String(String) foo;
foo(String str) => "\"``str``\"";
} Although, I know this did: shared void run()
{
String foo(String str);
foo = identity<String>;
} Wat about the last example? Can something like this work? It currently doesn’t. shared void run()
{
String foo(String str);
foo => identity<String>; // note the `=>`
} |
It’s also important to note that this doesn’t compile: shared void run()
{
abstract class Foo()
{
shared formal String(String) surround;
}
class Bar()
extends Foo()
{
surround(String str) => "\{RIGHT DOUBLE QUOTATION MARK}``str``\{LEFT DOUBLE QUOTATION MARK}";
}
print(Bar().surround{str = "Hello World!";}); // Named arguments not supported for indirect invocations
} |
Callable
attributes as if they were functions and vice versaCallable
attributes as if they were functions and vice‐versa
I think it would be very confusing to allow a method to be refined by a lazy value, since you would normally expect the two examples below to be equivalent: Foo f = Bar();
// example 1: both calls to the *same* randomly selected function
value fun = f.member;
fun("");
fun("");
// example 2: each call to its own randomly selected function!
f.member("");
f.member(""); Further, I don't believe the above can actually be implemented, because if OTOH, if |
@Zambonifofex It's 100% intentional that you can't assign to a function using a fat arrow |
@Zambonifofex I agree that it would be nice to make the following code compile: abstract class WithFunctionAndValueAbstract() {
shared formal String fun(String str);
shared formal String(String) val;
}
class WithValueAndFunctionShouldWork()
extends WithFunctionAndValueAbstract() {
shared actual String(String) fun = identity<String>;
shared actual String val(String str) => str;
} It's especially reasonable, given that it already works for shortcut refinement. We only decided not to support it in order to ease implementation on the Java backend. I'm not sure how relevant that concern is now. Having said that, it's not a high priority. |
I'm not sure allowing the long-form mix-and-match refinements would be an improvement. To me, the following seem unambiguous:
This is different from the flexibility offered by shortcut refinements, because, at least the way I read them, shortcut refinements don't re-state declarations, and are therefore less indicative of whether the declarations they are "assigning to" are functions or values. Why does this matter? In Ceylon, functions and values are not the same things:
I presume with the mix-and-match idea that from outside the defining class or interface, I'm not aware of any real practical benefit to this, and I think the change would only hurt from a purity or design standpoint, drawing an equivalence where none exists. |
@jvasileff as I said, I don't perceive this issue as being at all a priority. |
Derp derp derp. ceylon/ceylon-spec#1472
It’d be nice to be able to refine
Callable
attributes as if they were functions and vice versa. Things that I’d like to see working:A little harder to support:
The text was updated successfully, but these errors were encountered: