The answer to this suggests that the fold method in Option in Scala is catastrophic. From Wikipedia, catamophism is βthe only homomorphism from the original algebra to some other algebra. This concept applies to functional programming as folds,β so this is true, but it leads me to the original algebra as the source object in the F-algebra category.
So, if addition to Option is really Catamanism, then there must be some F functor to create a category of F-algebras, where Option will be the original object. I canβt understand what this functor will be like.
For lists of type A functor F is F[X] = 1 + A * X This makes sense because List is a recursive data type, so if X is List[A] , then the above means that a list of type A is either an empty list ( 1 ) or ( + ) a pair ( * ) A and a List[A] . But the option is not recursive. Option[A] will be just 1 + A (Nothing or A ). So I donβt see where the functor works.
Just to be clear, I understand that Option is already a functor, since it takes from A to Option[A] , but what is done for lists is different, A fixed, and the functor is used to describe how to construct a data type recursively.
In the corresponding note, if it is not a catamorphism, it probably should not be called a fold, as this leads to some confusion .
scala scala-option category-theory catamorphism recursion-schemes
Patrick
source share