tag:blogger.com,1999:blog-1777990983847811806.post446837723524958645..comments2024-06-16T22:32:41.218-07:00Comments on Haskell for all: Folds are constructor substitutionGabriella Gonzalezhttp://www.blogger.com/profile/01917800488530923694noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1777990983847811806.post-23788357645772361392022-05-21T11:43:09.556-07:002022-05-21T11:43:09.556-07:00This comment has been removed by the author.Steven Leivahttps://www.blogger.com/profile/17785457711595605166noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-49354732484145641112021-02-15T03:49:38.712-08:002021-02-15T03:49:38.712-08:00There's also a nice explanation of folds in te...There's also a nice explanation of folds in term of F-Algebras (https://bit.ly/3jQi0eF), e.g. the recursive `Tree a` is seen as the initial algebra (fixpoint) of the functor <br /><br />data FTree a b = Node a b b | Leaf<br /><br />and where the fold (catamorphism) is obtained from the initiality diagram of FTree a.Yassine Elouafihttps://www.blogger.com/profile/12292013032070726083noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-35544044712654922362021-02-12T04:47:39.955-08:002021-02-12T04:47:39.955-08:00To add a little, which I think is helpful:
You ca...To add a little, which I think is helpful:<br /><br />You can write a data type as a fold e.g.<br /><br />data List a = List (forall b. (a -> b -> b) -> b -> b)<br /><br />This is the same data type as [] and in fact, you can go right ahead and implement all the same library.<br /><br />The key difference for List is: you will get destruction (pattern-matching) for free (that's what fold does), but not construction (you'll have to write them) and for [], it will be the other way around.Tony Morrishttps://www.blogger.com/profile/17206456907461293947noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-39427186421792202462021-02-07T12:50:37.119-08:002021-02-07T12:50:37.119-08:00You're correct. I just fixed itYou're correct. I just fixed itGabriella Gonzalezhttps://www.blogger.com/profile/01917800488530923694noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-60357988941484056162021-02-07T11:11:22.079-08:002021-02-07T11:11:22.079-08:00In the last line of the "reverse the tree&quo...In the last line of the "reverse the tree" example, you have:<br /><br />= Node 1 (Node 3 Leaf Leaf) (Node 3 Leaf Leaf)<br /><br />Should one of those 3s be a 2?Edhttps://www.blogger.com/profile/15019313922153311358noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-78903478197844293022021-02-06T10:56:22.405-08:002021-02-06T10:56:22.405-08:00For those interested, the technical term is *banan...For those interested, the technical term is *bananas*: https://en.wikipedia.org/wiki/Catamorphism#Terminology_and_historyjtojnarhttps://www.blogger.com/profile/12216350506816928952noreply@blogger.com