catamorphism

What's the relation of fold on Option, Either etc and fold on Traversable?

会有一股神秘感。 提交于 2019-11-29 14:05:49
问题 Scalaz provides a method named fold for various ADTs such as Boolean , Option[_] , Validation[_, _] , Either[_, _] etc. This method basically takes functions corresponding to all possible cases for that given ADT. In other words, a pattern match shown below: x match { case Case1(a, b, c) => f(a, b, c) case Case2(a, b) => g(a, b) . . case CaseN => z } is equivalent to: x.fold(f, g, ..., z) Some examples: scala> (9 == 8).fold("foo", "bar") res0: java.lang.String = bar scala> 5.some.fold(2 *, 2)

Catamorphism and tree-traversing in Haskell

心已入冬 提交于 2019-11-28 18:24:51
I am impatient, looking forward to understanding catamorphism related to this SO question :) I have only practiced the beginning of Real World Haskell tutorial. So, Maybe I'm gonna ask for way too much right now, if it was the case, just tell me the concepts I should learn. Below, I quote the wikipedia code sample for catamorphism . I would like to know your opinion about foldTree below, a way of traversing a Tree, compared to this other SO question and answer, also dealing with traversing a Tree n-ary tree traversal . (independantly from being binary or not, I think the catamorphism below can

What is a catamorphism and can it be implemented in C# 3.0?

梦想与她 提交于 2019-11-27 17:44:13
I'm trying to learn about catamorphisms and I've read the Wikipedia article and the first couple posts in the series of the topic for F# on the Inside F# blog. I understand that it's a generalization of folds (i.e., mapping a structure of many values to one value, including a list of values to another list). And I gather that the fold-list and fold-tree is a canonical example. Can this be shown to be done in C#, using LINQ's Aggregate operator or some other higher-order method? Brian LINQ's Aggregate() is just for IEnumerables . Catamorphisms in general refer to the pattern of folding for an

Catamorphism and tree-traversing in Haskell

梦想的初衷 提交于 2019-11-27 11:19:29
问题 I am impatient, looking forward to understanding catamorphism related to this SO question :) I have only practiced the beginning of Real World Haskell tutorial. So, Maybe I'm gonna ask for way too much right now, if it was the case, just tell me the concepts I should learn. Below, I quote the wikipedia code sample for catamorphism. I would like to know your opinion about foldTree below, a way of traversing a Tree, compared to this other SO question and answer, also dealing with traversing a

What is a catamorphism and can it be implemented in C# 3.0?

断了今生、忘了曾经 提交于 2019-11-27 04:15:12
问题 I'm trying to learn about catamorphisms and I've read the Wikipedia article and the first couple posts in the series of the topic for F# on the Inside F# blog. I understand that it's a generalization of folds (i.e., mapping a structure of many values to one value, including a list of values to another list). And I gather that the fold-list and fold-tree is a canonical example. Can this be shown to be done in C#, using LINQ's Aggregate operator or some other higher-order method? 回答1: LINQ's