Skip to content

Add instances for rig categories#510

Draft
ricky136973 wants to merge 4 commits intoagda:masterfrom
ricky136973:rig-instance
Draft

Add instances for rig categories#510
ricky136973 wants to merge 4 commits intoagda:masterfrom
ricky136973:rig-instance

Conversation

@ricky136973
Copy link
Copy Markdown

Introduce Sets and PartialFunctions as rig categories.

@ricky136973 ricky136973 marked this pull request as ready for review March 11, 2026 18:20
Copy link
Copy Markdown
Collaborator

@JacquesCarette JacquesCarette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! I want to explore some potential changes. But while I say 'Request changes', what I really mean is "let's discuss the design some more". This is definitely a great contribution.

P⊗ .identity (x , y) = refl

P⊗ .homomorphism {f = f₁ , f₂} (x₁ , x₂)
with f₁ x₁ | f₂ x₂
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've used very little with in agda-categories up until now. It's fragile. I do realize that for dealing with partial functions, it is a powerful tool.

What I'm wondering is if the "pattern of reasoning" going on here could be abstracted out and used here?

Copy link
Copy Markdown
Author

@ricky136973 ricky136973 Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to pull the with-clauses out into a where-block, but Agda cannot infer the type of the helper functions if I do not provide the lengthy type signature explicitly.

}

PM⊗ .unitorˡ-commute-from {f = f} (lift tt , x)
with f x
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I definitely would like to see this kind of reasoning abstracted out!

Copy link
Copy Markdown
Author

@ricky136973 ricky136973 Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar cases happened to the previous case. The more elegant way could have been like

PM⊗ .unitorˡ-commute-from {f = f} (lift tt , x) =
  maybe {B = λ fx  ?} (erefl ∘ just) refl (f x)

but Agda cannot infer B, and the explicit form of it is just as lengthy as in the previous case.

@TOTBWF
Copy link
Copy Markdown
Collaborator

TOTBWF commented Mar 16, 2026

I'd maybe rename PartialFunctions to something else. In constructive foundations, A -> Maybe B describes partial functions whose domain of definition has decidable membership.

@ricky136973
Copy link
Copy Markdown
Author

I'd maybe rename PartialFunctions to something else. In constructive foundations, A -> Maybe B describes partial functions whose domain of definition has decidable membership.

I know the more general notion of "partial functions" is $\sum_{P:X\to\Omega}(\sum_{x:X}P(x))\to Y$, and that's also the encoding used in 1lab. I still named it as PartialFunctions only because there is already a module Categories.Category.Instance.PartialFunctions defining the maybe-functions as a category, and I believe it is better to maintain some sort of consistency of naming here.

@ricky136973 ricky136973 marked this pull request as draft March 17, 2026 06:21
@JacquesCarette
Copy link
Copy Markdown
Collaborator

I agree that consistency is very important. In the absence of other forces, I would always let consistency win.

In this case: I agree with @TOTBWF that this is a bad name. So I would like to find a better name -- and then I will change Categories.Category.Instance.PartialFunctions accordingly.

@ricky136973
Copy link
Copy Markdown
Author

I agree that consistency is very important. In the absence of other forces, I would always let consistency win.

In this case: I agree with @TOTBWF that this is a bad name. So I would like to find a better name -- and then I will change Categories.Category.Instance.PartialFunctions accordingly.

Name suggestion: MaybeFunction. DecidablePartialFunction is too long, Maybe is ambiguous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants