3 ms·
What's particularly interesting is that folds are not limited to processing lists. For any recursive data structure, you can create a corresponding fold. What's
by tmoertel 2y ago
What's particularly interesting is that folds are not limited to processing lists. For any recursive data structure, you can create a corresponding fold. What's even more interesting is that you can organize your code to automatically create the corresponding fold from a given recursive data structure!
Here's one example I wrote up using trees as the data structure:
https://github.com/tmoertel/practice/blob/master/EPI/09/soln_09_002_find_unbalanced_node.lhs https://github.com/tmoertel/practice/blob/master/EPI/09/soln...
Here's another example, this one in Python:
https://github.com/tmoertel/practice/blob/master/dailycodingproblem_com/count_unival_subtrees.py https://github.com/tmoertel/practice/blob/master/dailycoding...
- satvikpendem 2y agoYes, that is because folds work on catamorphisms in category theory.
- tmoertel 2y agoIndeed! The first example I linked to explains this connection in detail.