> Is the implementation of emulating functions completed ?
I didn't hear about it in a long time and didn't try it myself, so I honestly don't know. I'm interested in that too!
> class WannabeFunction {
> call(int a, int b) => a + b;
> }
I think it isn't called 'call' anymore... or maybe it is, there were some renamings lately and I can't remember now.
I'd advise you to look at the specification and if it is still called 'call', then file a bug (if there really are no open bugs about it anymore).
LT
OK, so I looked at it and I believe that your code is correct and that all your expectations are correct too. It should work -- but it looks like it isn't implemented yet. And the specification mentions that too in 14.5: call is not fully supported in the M1 release.
From spec : "If a type I includes a method named call(), and the type of call() is the function type F, then I is considered to be a subtype of F.".
I find this implicit implementation of Function a little too magic.
It is not easy to figure out that I can use a class only with a call method when I call Function.apply which requires a Function as first param.
I have one more question : is it legal to implement or extend Function ? ( https://www.dartlang.org/articles/emulating-functions/ doesn't show such example anymore and Dart Editor doesn't allow it )
> From spec : "If a type I includes a method named call(), and the type of call() is the function type F, then I is considered to be a subtype of F.".
> I find this implicit implementation of Function a little too magic. It is not easy to figure out that I can use a class only with a call method when I call Function.apply which requires a Function as first param.
If I remember correctly from yesterday's looking at the spec, it says explicitly that all function types implement Function.
So it's just two steps: you have a call method, therefore you are a subtype of a function type. And since you are a subtype of a function type, you also implement Function (or you are a subtype of Function).
LT