3 ms·
Taken from one of the examples : final HAppend<HCons<Boolean, HNil>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>, HCons<Boolean, HCons<Double,
by srean 16y ago
Taken from one of the examples :
final HAppend<HCons<Boolean, HNil>, HCons<Double,
HCons<String, HCons<Integer[], HNil>>>, HCons<Boolean,
HCons<Double, HCons<String, HCons<Integer[], HNil>>>>> one = append(zero);
It's here that I miss the repurposed auto keyword of C++ to do some rudimentary type inference.
- timrobinson 16y agofinal boolean b = a.exists(new F<String, Boolean>() { public Boolean f(final String s) { return fromString(s).forall(isLowerCase); } }); It's here that I miss lambdas to make functional code at all readable.
- ndunn2 16y agoexactly the example I was going to cite. In Scala this would be val b = a.exists(str=>str.forall(_.isLowerCase)) or val b = a.exists(x=>x.toLowerCase() == x) There's no way I'd start using functional programming in Java if it's this clunky. Just stick with Scala.
- hraberg 16y agoEnumerable.java (http://enumerable.org http://enumerable.org) is not really a functional library, but it does support limited closures: boolean b = a.any(λ(s, s.equals(s.toLowerCase())); s and λ are statically imported.
- pmjordan 16y agoOr C#'s var keyword, for that matter. Unfortunately, both will only work for local variables. I suspect this is one of the reasons there aren't any popular persistent data structure libraries around for these languages. At least the .NET/C# type system supports covariance/contravariance for functions ("delegates"). Plus, they managed to build F# on it.
- timrobinson 16y agoF# doesn't in fact make use of {co|contra}variance: it only needed generics. (Although F# used to run on .NET 1.x using its own implementation of generics - Don Syme designed both .NET generics and the F# language.) For type inference, you just need a sufficiently smart compiler, although it's much more useful if your language knows about generic types.
- pmjordan 16y agoThanks for clearing that up (I've yet to try F# in anger). I suppose pre-generics F# did similar type wrangling to Scala's?
- timrobinson 16y agoI don't know about Scala, but yes, wrangling describes well what F# used to do. I never used F# before .NET 2.0, but the techniques it used on 1.x could be interesting -- I'll see if I can find some old documentation... Edit: There used to be a paper describing the technique. I can't find it now, but here's an old Don Syme announcement related to it: http://www.mail-archive.com/dotnet-rotor@discuss.develop.com/msg00424.html http://www.mail-archive.com/dotnet-rotor@discuss.develop.com...
- stephen 16y agoAlthough I was initially skeptical about lombok's "let's hack the private compiler APIs", I must admit that their recent val hack is awesome: http://projectlombok.org/features/val.html http://projectlombok.org/features/val.html I find it frustrating that these guys can hack in "val" but JDK7 has token crap like the "diamond operator".