While writing the following
Void process(|Int -> Void |[] functions) { functions.each | |Int -> Void| fun, Int index|
I realized that having to type the type of the first parameter of the closure was a bit annoying since the compiler already knows it.
Would it be possible to extend type inference to apply to this kind of scenario?
-- Cedric
See http://www.fandev.org/doc/docIntro/Roadmap.html#closureTypeInference
Glad to hear it's on the roadmap.
On a related topic, I was wondering if I could alias this type so I could minimize the repetition. Something like:
Void process(Worker[] workers) { workers.each | Worker worker, Int index | { worker() } }
Now the question is: how could I define Worker to be a closure or a function?
My Java inclined mind started with:
class Worker : | -> Void | { }
but I was greeted with:
Class 'Worker' cannot extend parameterized type '|->sys::Void|'
I also tried a more manual approach:
class Worker {
Void call() { }
}
but no luck here either.
Is there a way to alias a closure signature to something more readable?
No way to do that today, but it would nice. Maybe a special using statement such as:
using |->Void| as Worker
Login or Signup to reply.
cbeust Tue 24 Jun 2008
While writing the following
I realized that having to type the type of the first parameter of the closure was a bit annoying since the compiler already knows it.
Would it be possible to extend type inference to apply to this kind of scenario?
-- Cedric
brian Tue 24 Jun 2008
See http://www.fandev.org/doc/docIntro/Roadmap.html#closureTypeInference
cbeust Tue 24 Jun 2008
Glad to hear it's on the roadmap.
On a related topic, I was wondering if I could alias this type so I could minimize the repetition. Something like:
Now the question is: how could I define Worker to be a closure or a function?
My Java inclined mind started with:
but I was greeted with:
I also tried a more manual approach:
class Worker {
}
but no luck here either.
Is there a way to alias a closure signature to something more readable?
-- Cedric
brian Tue 24 Jun 2008
No way to do that today, but it would nice. Maybe a special using statement such as: