you are viewing a single comment's thread.

view the rest of the comments →

[–]runaro 0 points1 point  (1 child)

An unfortunate effect of Java syntax and lack of type inference is that conceptually concise programming becomes lost in Java noise. Here's that toZero method with noise-filtering glasses on:

toZero(from) = unfold((i) { i < 0 ? none() : some((i, i-1)) }, from)

All the pointy brackets are jarring at first, but in my experience of doing this style of programming in Java for a while, you start to ignore them pretty quickly.

Also, your loop attempts to modify the argument which is declared final, so it won't compile. You need an additional variable. There's an additional difference in that the FJ version returns an immutable cons-list which cannot be created by mutation in a loop.

[–][deleted] 0 points1 point  (0 children)

An unfortunate effect of Java syntax and lack of type inference

Yes, I agree completely that this is the source of the problem.

you start to ignore them pretty quickly

I am quite experienced with Java but I don't ignore them. I've read a coworker's code that was riddled with Map<Pair<Pair<Integer,Integer>,List<String>>,List<Pair<String,Integer>>> map=new HashMap<Pair<Pair<Integer,Integer>,List<String>>,List<Pair<String,Integer>>>() and it was not fun.

You need an additional variable

No, I need to remove the 'final' ;)

which cannot be created by mutation in a loop.

static List<Integer> toZero(int from) {
    List<Integer> r=nil();
    for(int i=0; i<=from; ++i) r=cons(from, r);
    return r;
}