No, that was just for illustration. I think we should accept that
laziness is not achievable here. Most of the interesting functions
need at least some amount of commutation to take place and therefore
trying to make them lazy is hopeless simply because commutation can
fail.
If anything, I would re-write them in a fully tail-recursive manner,
adding as many accumulating parameters as needed. This means we can
assume that these functions are fully strict in the sense that pattern
matching on the outer-most constructor of the result will evaluate it
completely. At least this makes reasoning about performance easier.
I would then change return types so that we can remove any final
reverseFL/RL, as I have already done for some of the functions in
D.P.Permutations. This opens opportunities for client code to optimize
it away (either because we need the other direction anyway or because
we can use the mixed append operators +>>+ or +<<+).
And yes, unit tests would come in handy if we ever want to do this
systematically.
I've marked the ticket as "in-discussion".
|