Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
User:Michiexile/MATH198/Lecture 9
(section)
User page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
User contributions
Logs
View user groups
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Anamorphisms==== An ''anamorphism'' is the categorical dual to the catamorphism. It is the canonical morphism from a coalgebra to the final coalgebra for that endofunctor. Here, we start unstructured, and erect a structure, induced by the coalgebra structures involved. '''Example''': we can write a recursive function <haskell> first :: Int -> [Int] first 1 = [1] first n = n : first (n - 1) </haskell> This is an anamorphism from the coalgebra for <math>P_{\mathbb N}(X) = 1 + \mathbb N\times X</math> on <math>\mathbb N</math> generated by the two maps <haskell> c 0 = Left () c n = Right (n, n-1) </haskell> and we observe that we can chase through the diagram :[[Image:CoalgebraMorphism.png]] to conclude that therefore <haskell> f 0 = [] f n = n : f (n - 1) </haskell> which is exactly the recursion we wrote to begin with. MFP define the anamorphism by a fixpoint as well, namely: <haskell> ana :: (b -> F a b) -> b -> T a ana psi = mu (\x -> inT . fmap x . psi) </haskell> We can, again, recast our illustration above into a structural anamorphism, by: <haskell> -- Reuse mu, F, T from above inT :: F a (T a) -> T a inT Nil = [] inT (Cons a as) = a:as fpsi :: Int -> F Int Int fpsi 0 = Nil fpsi n = Cons n (n-1) </haskell> Again, we can note that the implementation of <hask>fpsi</hask> here is exactly the <hask>c</hask> above, and the resulting function will - as we can verify by compiling and running - give us the same kind of reversed list of the n first integers as the <hask>first</hask> function above would.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width