<s>
In	O
computer	O
programming	O
,	O
an	O
anamorphism	B-Application
is	O
a	O
function	O
that	O
generates	O
a	O
sequence	O
by	O
repeated	O
application	O
of	O
the	O
function	O
to	O
its	O
previous	O
result	O
.	O
</s>
<s>
The	O
anamorphism	B-Application
is	O
the	O
function	O
that	O
generates	O
the	O
list	O
of	O
A	O
,	O
B	O
,	O
C	O
,	O
etc	O
.	O
</s>
<s>
You	O
can	O
think	O
of	O
the	O
anamorphism	B-Application
as	O
unfolding	O
the	O
initial	O
value	O
into	O
a	O
sequence	O
.	O
</s>
<s>
The	O
above	O
layman	O
's	O
description	O
can	O
be	O
stated	O
more	O
formally	O
in	O
category	O
theory	O
:	O
the	O
anamorphism	B-Application
of	O
a	O
coinductive	B-Application
type	I-Application
denotes	O
the	O
assignment	O
of	O
a	O
coalgebra	O
to	O
its	O
unique	O
morphism	O
to	O
the	O
final	O
coalgebra	O
of	O
an	O
endofunctor	O
.	O
</s>
<s>
These	O
objects	O
are	O
used	O
in	O
functional	B-Language
programming	I-Language
as	O
unfolds	B-Application
.	O
</s>
<s>
The	O
categorical	O
dual	O
(	O
aka	O
opposite	O
)	O
of	O
the	O
anamorphism	B-Application
is	O
the	O
catamorphism	B-Application
.	O
</s>
<s>
In	O
functional	B-Language
programming	I-Language
,	O
an	O
anamorphism	B-Application
is	O
a	O
generalization	O
of	O
the	O
concept	O
of	O
unfolds	B-Application
on	O
coinductive	B-Application
lists	O
.	O
</s>
<s>
Formally	O
,	O
anamorphisms	B-Application
are	O
generic	O
functions	O
that	O
can	O
corecursively	B-Application
construct	O
a	O
result	O
of	O
a	O
certain	O
type	O
and	O
which	O
is	O
parameterized	O
by	O
functions	O
that	O
determine	O
the	O
next	O
single	O
step	O
of	O
the	O
construction	O
.	O
</s>
<s>
Thus	O
,	O
one	O
can	O
define	O
functions	O
from	O
a	O
type	O
A	O
_into_	O
a	O
coinductive	B-Application
datatype	O
by	O
specifying	O
a	O
coalgebra	O
structure	O
a	O
on	O
A	O
.	O
</s>
<s>
A	O
(	O
pseudo	O
-	O
)	O
Haskell-Definition	O
might	O
look	O
like	O
this	O
:	O
</s>
<s>
(	O
Also	O
note	O
that	O
in	O
Haskell	B-Language
,	O
least	O
and	O
greatest	O
fixed	O
points	O
of	O
functors	O
coincide	O
,	O
therefore	O
inductive	O
lists	O
are	O
the	O
same	O
as	O
coinductive	B-Application
,	O
potentially	O
infinite	O
lists	O
.	O
)	O
</s>
<s>
The	O
anamorphism	B-Application
for	O
lists	O
(	O
then	O
usually	O
known	O
as	O
unfold	B-Application
)	O
would	O
build	O
a	O
(	O
potentially	O
infinite	O
)	O
list	O
from	O
a	O
state	O
value	O
.	O
</s>
<s>
Typically	O
,	O
the	O
unfold	B-Application
takes	O
a	O
state	O
value	O
x	O
and	O
a	O
function	O
f	O
that	O
yields	O
either	O
a	O
pair	O
of	O
a	O
value	O
and	O
a	O
new	O
state	O
,	O
or	O
a	O
singleton	O
to	O
mark	O
the	O
end	O
of	O
the	O
list	O
.	O
</s>
<s>
The	O
anamorphism	B-Application
would	O
then	O
begin	O
with	O
a	O
first	O
seed	O
,	O
compute	O
whether	O
the	O
list	O
continues	O
or	O
ends	O
,	O
and	O
in	O
case	O
of	O
a	O
nonempty	O
list	O
,	O
prepend	O
the	O
computed	O
value	O
to	O
the	O
recursive	O
call	O
to	O
the	O
anamorphism	B-Application
.	O
</s>
<s>
A	O
Haskell	B-Language
definition	O
of	O
an	O
unfold	B-Application
,	O
or	O
anamorphism	B-Application
for	O
lists	O
,	O
called	O
ana	O
,	O
is	O
as	O
follows	O
:	O
</s>
<s>
An	O
anamorphism	B-Application
can	O
be	O
defined	O
for	O
any	O
recursive	O
type	O
,	O
according	O
to	O
a	O
generic	O
pattern	O
,	O
generalizing	O
the	O
second	O
version	O
of	O
ana	O
for	O
lists	O
.	O
</s>
<s>
To	O
better	O
see	O
the	O
relationship	O
between	O
the	O
recursive	O
type	O
and	O
its	O
anamorphism	B-Application
,	O
note	O
that	O
Tree	O
and	O
List	O
can	O
be	O
defined	O
thus	O
:	O
</s>
<s>
One	O
of	O
the	O
first	O
publications	O
to	O
introduce	O
the	O
notion	O
of	O
an	O
anamorphism	B-Application
in	O
the	O
context	O
of	O
programming	O
was	O
the	O
paper	O
Functional	B-Language
Programming	I-Language
with	O
Bananas	B-Application
,	O
Lenses	O
,	O
Envelopes	O
and	O
Barbed	O
Wire	O
,	O
by	O
Erik	O
Meijer	O
et	O
al.	O
,	O
which	O
was	O
in	O
the	O
context	O
of	O
the	O
Squiggol	B-Application
programming	O
language	O
.	O
</s>
<s>
Functions	O
like	O
zip	B-Language
and	O
iterate	O
are	O
examples	O
of	O
anamorphisms	B-Application
.	O
</s>
<s>
zip	B-Language
takes	O
a	O
pair	O
of	O
lists	O
,	O
say	O
 [ 'a' , 'b' , 'c' ] 	O
and	O
 [ 1 , 2 , 3 ] 	O
and	O
returns	O
a	O
list	O
of	O
pairs	O
[( 	O
 '	O
a	O
 '	O
,	O
1	O
)	O
,	O
( 	O
 '	O
b	O
 '	O
,	O
2	O
)	O
,	O
( 	O
 '	O
c	O
 '	O
,	O
3	O
)	O
]	O
.	O
</s>
<s>
To	O
prove	O
this	O
,	O
we	O
can	O
implement	O
both	O
using	O
our	O
generic	O
unfold	B-Application
,	O
ana	O
,	O
using	O
a	O
simple	O
recursive	O
routine	O
:	O
</s>
<s>
In	O
a	O
language	O
like	O
Haskell	B-Language
,	O
even	O
the	O
abstract	O
functions	O
fold	O
,	O
unfold	B-Application
and	O
ana	O
are	O
merely	O
defined	O
terms	O
,	O
as	O
we	O
have	O
seen	O
from	O
the	O
definitions	O
given	O
above	O
.	O
</s>
<s>
In	O
category	O
theory	O
,	O
anamorphisms	B-Application
are	O
the	O
categorical	O
dual	O
of	O
catamorphisms	B-Application
(	O
and	O
catamorphisms	B-Application
are	O
the	O
categorical	O
dual	O
of	O
anamorphisms	B-Application
)	O
.	O
</s>
<s>
The	O
brackets	O
used	O
are	O
known	O
as	O
lens	O
brackets	O
,	O
after	O
which	O
anamorphisms	B-Application
are	O
sometimes	O
referred	O
to	O
as	O
lenses	O
.	O
</s>
