Anamorphism is the opposite of catamorphism. Since catamorphism is folding, then anamorphism can be considered unfolding. So let's first look at the mechanics for unfolding.

To unfold, we return a sequence of data. This sequence does not need to be finite. The amount returned can be dynamic or static or infinite. Things like list comprehension and generators are some quick examples of unfolding. In Python, xrange and range are anamorphic in a way.

The usefulness of unfolding is that we can get a series of data about some information without even needing to know anything about it before hand. Some useful math you can do with this would be things like getting all the divisors of a number. I have used anamorphism for generating Fibonacci numbers in sequence as well.

The divisors function returns a finite sequence of data whereas the fibgen returns an infinite amount. Also note that divisors is using list comprehension whereas fibgen is a normal function.

That is about all there is to anamorphism, an unfolding of data. Even replicating data can be an anamorphism. Oh, and an anamorphism can even take lists of data or multiple lists of data and return a list of data, like zipping two lists together.

To unfold, we return a sequence of data. This sequence does not need to be finite. The amount returned can be dynamic or static or infinite. Things like list comprehension and generators are some quick examples of unfolding. In Python, xrange and range are anamorphic in a way.

The usefulness of unfolding is that we can get a series of data about some information without even needing to know anything about it before hand. Some useful math you can do with this would be things like getting all the divisors of a number. I have used anamorphism for generating Fibonacci numbers in sequence as well.

divisors :: Integral a => a -> [a] divisors n = [i | i <- [1..(n `div` 2)], rem n i == 0] fibgen :: Num a => a -> a -> [a] fibgen a b = a : (fibgen b (a + b))

The divisors function returns a finite sequence of data whereas the fibgen returns an infinite amount. Also note that divisors is using list comprehension whereas fibgen is a normal function.

That is about all there is to anamorphism, an unfolding of data. Even replicating data can be an anamorphism. Oh, and an anamorphism can even take lists of data or multiple lists of data and return a list of data, like zipping two lists together.