dranges.morphism

To Be Documented.

An attempts to code generalization of folding/unfolding algorithms on branching structures, also known under the delightful names of catamorphisms, anamorphisms, paramorphisms and hylomorphisms.

License:
Boost License 1.0.

Authors:
Philippe Sigaud

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

ReturnType!(fun) cata (alias fun, T)(T tr);
Catamorphism.

The equivalent of reduce, on recursive ranges: it collapses an entire recursive range into one value. Or, if you will and if the propagated value is complex, recursively builds a value from a tree.

fun takes as arguments the front value of the recursive range and the range of results coming from applying the catamorphism on the successors. That is, one step in the building is that you already applied fun to the successors. From this range of temporary results and the current node's value, you build the current result, which you return 'upward', to the preceding level of recursion.

So, if the node is a sink/leaf (no successors or the only successor is empty), the range of result is also empty.

This version take a standard function. It's the equivalent of reduce(range).

class Ana (alias gen,alias pred,T);
Anamorphism.

The equivalent of unfold for recursive ranges: creates a entire tree from a generative function gen, a seed value, and a predicate (on the current value) as the stopping condition.

Ana!(gen,pred,T) ana (alias gen, alias pred, T)(T t);


typeof(ifEmpty) para (alias ifEmpty, alias constructor, R)(R range);
Paramorphism

The equivalent of reduce, but with a ternary function constructor(front of the range, tail of the range, paramorphism on the tail)

typeof(ifTrue) hylo (alias ifTrue, alias constructor, alias predicate, alias next, T)(T t);
Hylomorphism, the composition of a catamorphism (which collapse a recursive range) with an anamorphism (which builds a recursive range).

Examples?

Page was generated with on Fri Nov 12 11:55:10 2010