I have this lovely fixana
function here that performs about 5 times faster than her sister ana
. (i have a criterion
report to back me on this)
ana alg = Fix . fmap (ana alg) . alg
fixana alg = fix $ \f -> Fix . fmap f . alg
Can I express their cousin cata
in the same fashion?
cata f = f . fmap (cata f) . unFix
It seems to me that I cannot, but I have been humbled by my S.O. fellows quite a few times in the past.
Actually, this has nothing to do with catamorphisms.
Whenever a function is defined as
one can rewrite it using
fix
asIn the posted code we have a slight variant
We can regard the above as
f
being defined recursively. However, it's simpler if we regardf x
(rather thanf
) being defined recursively.This should be more efficient than the plain translation
since we don't need to call
g
over and over again with the same argumentx
.