You're reading the public-facing archive of the Category Theory Zulip server.
To join the server you need an invite. Anybody can get an invite by contacting Matteo Capucci at name dot surname at gmail dot com.
For all things related to this archive refer to the same person.
In Functional Programming, I've see tree structures defined as the following:
data Tree a t = Leaf a | Empty | Compose (Tree t a) (Tree t a) | Application t Tree (t a)
This structure is recursive up to the leafs, which is where every tree must end... I'm trying to understand what this structure is in Category Theory. Fixing a t
, my hypothesis was that this data structure was to be interpreted as the initial algebra for a functor
. But I'm not sure if this is the case.
How can I interpret this types of "expression" constructions within Category Theory?
Do you mean for the order of t
and a
to switch between the data
definition and the clauses?
And do you want your last clause to be Application t (Tree t a)
?
In general, every generic type is an endofunctor, provided that it has some implementation of map (if it doesn't it is not anything categorically, I think). Then it can be also an applicative, monad etc.
If you do want the order of arguments to stay the same and be present at all uses:
data Tree a t = Leaf a | Empty | Compose (Tree a t) (Tree a t) | Application t (Tree a t)
then Tree a t
is the initial algebra of the endofunctor
The argument of the endofunctor corresponds to the recursive appearances of the type being defined in its own constructors; the other types are parameters that determine the functor.
Thanks, @Mike Shulman . I've been digging through this, and I got to this conclusion. Good to see that what I was thinking was correct.
I'm trying to implement the catamorphism for this strucutre. If I understood correctly, in the $$F_{a,t}$, the is actually a constant functor. I mean, . Right?
I mean, if a catamorphism is:
cata alg = alg . fmap (cata alg) . unFix
Then I need a base case for cata alg
where fmap (cata alg) Leaf 10
is the fixed point... Hence, fmap (cata alg) Leaf 10
should return Leaf 10
... Makes sense?
I don't quite understand your notation, but there is no recursion in the case for Leaf
if that's what you mean.