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.
Hello, friends. In my PhD I'm trying to formalize some of my code using Category Theory. I've then stumbled on the following construction, which I'm trying to understand. The question requires me to explain my construction, so it will have to take some time to explain the idea. But my main question is to try to understand two things: first, if this type of construction has a name (if people use it and have done work on it); secondly, how I can understand the "morphism" (is it a natural transformation, a functor,...?).
Consider I'm working in the category , and that I have a monad and a fixed object .
I state that belongs to a category if it has a unique function . Informally, what I want to say is that a type is an object of the category if and only if it has a unique way to turn elements of into elements of .
In this construction, the 's are morphisms in . Thus, is the terminal object in this category, since each is unique and has as codomain.
Note that belongs to by considering as the identity function.
Moreover, we can also use the fat that is a monad to say that is in , by making .
After one has populated with some objects and morphisms, one can devise a new method for constructing objects of . Let be an object of . Then, if we define a function , we can obtain a function
Finally, my question is what is this that appears in ? Note that it does not have an index as the rest, but one can understand it as a polymorphic function. Still, how can we understand it categorically?
Someone else can probably give you a more complete answer. But here's my best guess!
You are considering a collection of certain morphisms from various objects to a fixed object . This sounds like a sink to me. The book "Abstract and Concrete Categories" talks about sources and sinks starting in section III.
For example, here's the definition of a sink from that book:
sink
So maybe is a certain kind of sink? I'm not totally following how you formed , but I know that one can compose sinks with morphisms (or other sinks) to get new sinks.
Thanks, @David Egolf . I'll take a look in the book. The sink does seems similar.
About , the idea is that if I know how to turn into and I know how to turn into , then I know how to turn into . Which is true due to the monadic nature of .
Thanks for clarifying!
I drew a picture to try and illustrate the situation, as I understand it:
getting theta B
Yes!
The idea in this construction is the following.
The monad constructs tree expression over a type. The type is a primitive, and consists of objects that I can represent in the screen, and I can evaluate a tree of type and produce an image in the screen by rendering each . The is a way to say that an element of has a representation since I can express it as an .
But the thing is that, if I can define a new type and express it as an expression of 's, than I should still be able to get an element of .
You may already be aware of this, but the composition you described I believe corresponds to composition in the Kleisli category for :
Kleisli composition
(The screenshot is from p. 138 of this book by Perrone).
I dont't think it's exactly the composition in Kleisli due to the construction... The idea is that goes from to any expression of type .
Where is the category itself...
Consider that is the collection of simple geometric shapes (circle, square,...).
Then, is a way to combine these shapes, and an expression is a tree of geometric shapes that produces a drawing in the screen.
We then specify a type which has a function that says how to draw a person, e.g. given the size of the person and the head shape, it returns an expression of . Similarly, define a type called .
Now I want to define a City, which is just a collection of persons and buildings... Since I know how to draw a person and a building, I want to define a function . Note that what this means is that a city is drawn by combining persons and buildings, which I know how to draw.
Therefore, the function I've used to defined the city is indeed enough to induce the , which actually turns the city representation into the primitive geometric shapes, which are the thing I know how to draw.
Thanks for explaining! (I need to go do some other stuff now, but I'll plan to read over and try to understand what you just said.)
Hopefully someone else can chime in with some thoughts as well!
Thanks a lot
Davi Sales Barreira said:
Hello, friends. In my PhD I'm trying to formalize some of my code using Category Theory. I've then stumbled on the following construction, which I'm trying to understand. The question requires me to explain my construction, so it will have to take some time to explain the idea. But my main question is to try to understand two things: first, if this type of construction has a name (if people use it and have done work on it); secondly, how I can understand the "morphism" (is it a natural transformation, a functor,...?).
Consider I'm working in the category , and that I have a monad and a fixed object .
I state that belongs to a category if it has a unique function . Informally, what I want to say is that a type is an object of the category if and only if it has a unique way to turn elements of into elements of .
I'm sorry, I'm skimming along the surface and really am not following.
So this is a monad on the category of sets? If has more than one element, then for any set , the only way that there can be a unique function is when is the empty set. So in all cases, according to this reading, the category winds up looking pretty trivial.
I think you must mean something different from what I am reading.
To clarify, I'm using Bartosz idea of interpreting programming types as sets in the category of Sets. With that said, the type is like a union type which are basic geometric shapes.
What I want to do is to construct . In this case, is working like a type class.
For example, a priori a type is not in , since I haven't defined a function .
One I define such function, than is now part of my type class (category?)
Does this makes things a bit clear?
No, it does not make things any clearer for me. Let me start with: is a monad on sets? You said, "consider I'm working in the category ".
Yes
is a monad over the category of Sets.
And is a set satisfying a certain property?
No. is any type (set).
Sorry if this is all over the place. My knowledge in Category Theory is not very robust.
Okay, for people who don't know the Milewski (I presume Milewski) background you mention, like me, I'm not sure your meaning will be clear. When you give notation , it is usually presumed that and belong to the same category, in this case the category of sets.
Yes, the framework is that types in programming are sets, and functions are morphisms.
means a function that takes a value of type and returns a type .
So if and are any two sets, and if there is exactly one function , then there is a very limited number of possibilities on and .
(A type B? Or a value of type ?)
(I'm going to bow out very quickly unless my basic confusion gets sorted out in the next few minutes.)
Take to be Int, take to be strings. A function takes a value of type Int and returns a value of type String. The monad .
Now, for the hom-set of functions from to one select one function . Now, belongs to the category .
If is a set with more than one element (let's say has two distinct elements ), and if has at least one element, then there will be at least two functions,
where those two parallel arrows name the elements and .
Ultimately this must be me quibbling with your use of language, and I hate to be that guy, but I am that guy.
Okay, this confirms me that the issue is one of language use. You don't really mean there is literally a unique function, you must mean a uniquely specified choice of function.
(I'm pretty picky about language use, and for that I must beg your pardon.)
I understand the pickness. Bad language can mess things up. I'm actually coming to the problem trying to interpret the messy program I have into a categorical framework.
Yes, I do mean that one specifies a unique function, which I called .
So an object is a set equipped with a function ?
Yes.
Okay, thank you. I can reread now.
Davi Sales Barreira said:
After one has populated with some objects and morphisms, one can devise a new method for constructing objects of . Let be an object of . Then, if we define a function , we can obtain a function
Should that in be an (that is the underlying set of an assumed to be an object of the category )?
I'm complaining that you're overloading the letter , which was originally the category, not an object of the category. I'm guessing you mean a composite
No?
I actually understood the question, and it made me think of a theoretical issue with what I was trying to come up with.
The idea is that where is any other type that belongs to .
(I'm also using to mean )
And that's what I said, except that I used the letter , not . So anyway, you seem to be confirming the point of my complaint (no?).
Anyway, the construction I mentioned (and what I thought you meant) is part and parcel of what is called the Kleisli category of , which you may know about already.
Yes, indeed I understood your point, and I'm confirming your objection.
So I think it would fall under Kleisli.
Thanks for the interjections.
So it looks like you're considering a slice category .
Yes, thanks again. This will help me clarify what is going on in the code.
Just so there's no miscommunication: is the category whose objects are sets, and whose morphisms are functions ; these morphisms are composed in the way we're discussing. The identity morphism on is the monad unit as a function. (I'm sure you're familiar with this; I'm just trying to be careful.)
Yes, it's clear.
In my case though, I guess I'm actually working on a subcategory of .
Since I'm considering only a single function for every set .
Davi Sales Barreira said:
The idea is that where is any other type that belongs to .
(I'm also using to mean )
So there you rather have a family of arrows in , and maybe one for any set B? Don’t you?
Davi Sales Barreira said:
In my case though, I guess I'm actually working on a subcategory of .
Since I'm considering only a single function for every set .
I hope you don't mind my saying, but this seems a bit strange to me, from a category theorist's perspective. It seems to require that the underlying functor from your category to , taking to , be injective on objects. But this is against the spirit of the principle of equivalence.
@Vincent R.B. Blazy , I'm sorry, I didn't understand your point.
@Todd Trimble , I actually appreciate the criticism. I didn't know about the principle of equivalence. I'm reading on it, but I'm still trying to understand how it relates to the problem at hand.
The way I'm constructing is somewhat ad hoc, because it actually stems from the application I'm trying to code.
I'm trying to use Category Theory as a way to inform the way I'm coding my application. But the process sort of runs in both directions.
Perhaps there is a categorical way of expressing what I'm trying to do that actually has a better theoretical ground.
Davi Sales Barreira said:
Vincent R.B. Blazy , I'm sorry, I didn't understand your point.
I’m starting from you having said that your was meant to target BX for any X. Maybe I misunderstood you first, but I thought that this meant a family of morphisms rather than only one, for some fixed random X :smile:
At first the idea was that, but I realized that there was an issue with this definition.
The main property is that has to take to where is of .
Now this could be any object of , hence why I first wrote .
But this is problematic, specially since would not be valid.
This whole discussion actually lies in a very practical problem, which is the one I was trying to describe. The ideia that is a special type and that is an expression composed of elements of , which is a description of how to represent a scene as a combination of geometric objects.
One then want to define things like "a house". A house would be a combination of a roof, the walls, the door and the windows. Thus, instead of defining , one defines a function , which means that instead of defining how to draw a house directly, we actually specify how to combine a roof, walls and windows... IF we know how to draw a roof, a wall and a window, then we should be able to draw the house. And to be able to draw the roof, windows and walls is the same as having , , .
The idea that the is unique is not inspired in the categorical definition, but in the practical idea that each type should have a single "canonical" drawing representation.
Possibly to save you some time, Davi, let me describe a scenario meant to illustrate this business of the principle of equivalence (aka, "the problem of evil") .
Say Janice has a particular liking for the set and dreams up plans for a . After carefully considering exactly what should look like, she has her plans written up and notarized, and takes her materials over to the government office in charge of approving these things. The official looks in his records, and sorrowfully answers, "I'm sorry, but that set has already been considered, and the rules are: only one per set".
Crestfallen, Janice walks away. After a while, she thinks to herself: why don't I simply create a clone of the set ? It would be exactly alike in every single detail (we'll call it for the sake of discussion), so much so that if you placed the two sets side by side, you could not tell which is the original and which is the copy. (Is it live, or is it Memorex? went the old 70's commercial.) But, it's a new set, and so it hasn't been assigned a yet. And so she reasons the government official now can have no grounds for complaint, can he?
She brings in her clone into the office. The fellow looks up at her and says, "Weren't you here last week? As I already explained, only one per set." She says, "I know, but this isn't the same set as the one from last week." "It's not?! It looks exactly the same!" "I know! But this one is mine, and I've called it ." "Listen, lady -- don't get smart with me. Admit it: it's the same set."
Later, the government official checks up on the old set , but is now suddenly unsure whether that's the true original, or a clone matching it to perfection, or whether someone swapped out its for another in the dead of night.
In category theory, it's generally better to arrange definitions so that any issue of having to distinguish between two indiscernably different things doesn't have to be faced, or in other words, the concept doesn't change if you replace the original category with an equivalent one (like the category of sets). Having a rule that a functor be injective on objects would fly in the face of that principle.
Wow, thanks for the explanation!
Davi Sales Barreira said:
One then want to define things like "a house". A house would be a combination of a roof, the walls, the door and the windows. Thus, instead of defining $\theta_{House}: House \to DP$, one defines a function $\zeta_{House}: House \to D(Roof + Wall + Window + Door)$, which means that instead of defining how to draw a house directly, we actually specify how to combine a roof, walls and windows... IF we know how to draw a roof, a wall and a window, then we should be able to draw the house. And to be able to draw the roof, windows and walls is the same as having $\theta_{Roof}:Roof \to DP$, $\theta_{Window}:Window \to DP$, $\theta_{Wall}: Wall \to DP$.
Ookay then you want a specific object X of M for each B! You should perhaps use a dedicated functor giving it for each B, then (in addition of the evilness issue)?
It seems that indeed the is the category I'm working on. But now I have objects such as and .
Given , the is a morphism of iff .
This would mean that also belongs to .
I now have to figure out how this can be implemented as code.
I'm actually writing code in Julia, so it is not straight-forward. Also, I haven't seen much how slice categories are used in programming. The Kleisli category and monads are more common.
@Vincent R.B. Blazy, your suggestion would be to create a functor ?
Davi Sales Barreira said:
Given $(B, \theta_B)$, the $\zeta_B:(B,\theta_B) \to A$ belongs to $\mathcal M$ iff $\theta_B = \mu \circ D\theta_A \circ\zeta_B $.
You mean «belongs to » as an arrow then? Because satisfying this equation by definition what being an arrow in amounts to!
Davi Sales Barreira said:
This would mean that $(DB, \mu D\theta_B)$ also belongs to $\mathcal M$.
Why so?
I meant that it is a morphism.
Isn't this the definition in a slice category?
That a function in the original category generates a morphism between to in the slice category if
Davi Sales Barreira said:
Isn't this the definition in a slice category?
Yes that’s what I say, arrow is synonym of morphism in cat theory :big_smile: (I prefer to reserve the latter only to functions preserving structure)
About , it is an object of because , no?
Davi Sales Barreira said:
Vincent R.B. Blazy, your suggestion would be to create a functor $M:Set \to \text{Kleisli}(D)/P$ ?
Yes, but that was independently of the implementation, in order to map each «B» to the desired combination of characters you need to define it, following your house-building example!
Davi Sales Barreira said:
About $(DB, \mu D\theta_B)$, it is an object of $\mathcal M$ because $\mu D\theta_B: DB \to DP$, no?
Ah this time as an object! Yes ok indeed; sorry
BTW, is there any references on ? I mean, slice category over the Kleisli category.
Another caveat, the monad is the free monad over a functor .