|
7:15:22 AM |
 |
Continuing on the thread about adding blocks to Java/C#, two additions:
Ross Judson replies,
Joe knocked one line out of my example that I think is somewhat important...you need to be able to declare higher-order functional types. That's just a function that takes a function that takes a function etc...these are pretty handy for solving certain types of problems. The point is, a function is defined in terms of its inputs and its output. Compatibility is pretty important -- the compiler can verify that two functional types are compatible quite easily.
...
There are plenty of smart people in the functional world. There are plenty of extra cool languages out there (OCaml is one of the most interesting ones, as is Haskell). With Java I think we are in a kind of 90/10 situation -- what key functional features might we add to the language and VM specification that will really help us write better code?
Whatever we choose must have as minimal an impact on the language as possible. Strong typing is a considerable virtue, in my opinion. So are exceptions, so whatever functional notation we choose we will want to support exceptions fully.
class Example { public function double ComputeThis(String p1, double p2) throws SomeException; public function double SecondOrder(ComputeThis computerThis, double outer) throws SomeException; } ;
In that example I'm declaring a first and second order function, both of which are declared to throw an exception. We can now call these functions at will and have them participate fully in the exception mechanism. If a function is defined to take another function, it must declare in its throws clause a superset of the exceptions that are thrown by the parameter function (I think).
And Don Box from the .NET team points us to the addition of iterators to C#.
Iterators are pretty cool. They're basically much more convenient ways of defining how the foreach statement should work on an object without having to resort to additional enumerator classes (which are fiddly to write).
public class People { public Person foreach() { yield(new Person("John")); yield(new Person("Fred")); yield(new Person("Bill")); } }
To use:
foreach (Person p in people) { ... }
All this stuff makes the language easier and easier to use. And it's obvious that the next logical step from iterators a more generic support for blocks.
Meanwhile, Java gets assert()...
|