back

by srean·15y ago·view on hn ↗
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.
3 comments

    final 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.
exactly 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.

Enumerable.java (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.

Or 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.
F# 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.

Thanks for clearing that up (I've yet to try F# in anger). I suppose pre-generics F# did similar type wrangling to Scala's?
I 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...

Although 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

I find it frustrating that these guys can hack in "val" but JDK7 has token crap like the "diamond operator".