Haskell

bearophile bearophileHUGS at lycos.com
Wed Aug 24 19:08:05 PDT 2011


Timon Gehr:

> It is especially compact in that program,

The coding style of that program is an unreadable mess, example:

LList!T hamming(T)(){
    LList!T merge(LList!T xs, LList!T ys){
        return lz({
                auto x=xs.head, y=ys.head;
                if(x()<y()) return cons(x,merge(xs.tail,ys))();
                else if(x()>y()) return cons(y,merge(xs,ys.tail))();
                else return cons(x,merge(xs.tail,ys.tail))();
            });
    }

    return lz({
            LList!T r;
            r=cons(st(1),lz({return merge(merge(map((Lazy!T a){return lz({return 2*a();});},r),map((Lazy!T a){return lz({return 3*a();});},r)),map((Lazy!T a){return lz({return 5*a();});},r))();}));
            return r();
        });
}


This is a bit better:

LList!T hamming(T)() {
    static LList!T merge(LList!T xs, LList!T ys) {
        return lz({
                auto x = xs.head;
                auto y = ys.head;
                if (x() < y())
                    return cons(x, merge(xs.tail, ys))();
                else if (x() > y())
                    return cons(y, merge(xs, ys.tail))();
                else
                    return cons(x, merge(xs.tail, ys.tail))();
            });
    }

    return lz({
                LList!T r;
                r = cons(st(BigInt(1)), lz({
                    return merge(merge(map((Lazy!T a){ return lz({ return 2 * a(); }); }, r),
                                       map((Lazy!T a){ return lz({ return 3 * a(); }); }, r)),
                                 map((Lazy!T a){ return lz({ return 5 * a(); }); }, r))();
                }));
                return r();
            });
}


> I am starting to think this is not as intended.

I think it's a DMD bug. Fit for Bugzilla.


> I cannot seem to find it, but I'd like to vote on it. Do you have a link?

I have updated this:
http://d.puremagic.com/issues/show_bug.cgi?id=5970

Bye,
bearophile


More information about the Digitalmars-d mailing list