if it can form one you can fold without providing ...
# arrow
r
if it can form one you can fold without providing an accumulator or empty value because you can use the monoid empty identity as the empty value and the associative operation as the accumulator
c
So fold acts on a Functor which contains data, and a Monoid which is the morphism applied to it? So in
listOf(2, 3, 4).fold(sum)
List<Int>
is a Functor that contains Ints, and
sum
is a Monoid which admits a function
Int -> Int -> Int
and an identity value (0) ?
r
yep
but fold itself requires an empty start value, that is the Monoid empty identity
c
Thanks, that explains a lot 👍
r
I suppose there
sum
provides it
same notion as map reduce
and all these techniques. They are all catamorphisms, and there are other recursion schemes
What helps clarify all this is learning recursion schemes with Algebras and Coalgebras
Data, Co-data, Fold, un-fold… it’s all conceptually the same
c
How would you write
sum
in Arrow? I guess it's some type of typeclass that holds a function
r
a kind of recursion scheme and their duals
Sum is currently the default monoid for Int
so you just use the int monoid
c
I'll try to go deeper in the theory so I can read the Wikipedia pages
r
There may be a Mult somewhere you’d have to pass by hand
Check out this if you are interested
Thanks I'll watch them 😊
r
yes, that is the int monoid
Also this talk is gold

https://www.youtube.com/watch?v=XZ9nPZbaYfE

c
Thanks ^^
👍 1
r
You can also put them to practice if you feel like it with one of the incubating modules in Arrow https://arrow-kt.io/docs/recursion/intro/