-
-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ∘[₁]
as aliases for compose[1]
#5115
base: master
Are you sure you want to change the base?
Conversation
I'm not sure it's worth it to add this alias to Racket given that Racket doesn't have infix operators, and |
When implementing mathematical functions in Racket, especially in algebra-related contexts, I find that using As someone currently writing documentation on category theory using Racket, I've experienced firsthand how well S-expressions work for describing these concepts. In this context, having |
That sounds like it ought to be part of a third-party library focused on category theory then. |
Actually, the Racket-based documentation on category theory I’m working on only uses features provided by From this perspective, procedures play a central role, and composition is fundamental to category theory. As a result, procedure composition—Racket's |
Does this addition cause any code on the package server to fail to compile? Does it perhaps make sense to export these from |
I searched for this symbol. The results show that four packages provide Conflicts would arise in my
I don't have an issue with moving |
Just as a data point with regards to a third-party library, Haskell has base-unicode-symbols. It even has ∘ for composition! |
In my opinion t is not worth the trouble having ∘ be an alias Also, it is not enough to check the documentation for ∘. A quick search on Github reveal that multiple projects use ∘. https://github.com/search?q=language%3Aracket+%E2%88%98&type=code |
I see lots of It's possible that adding |
In my experience, using full names for some operations can be very confusing, especially when they are used extensively in the same expression, making it hard to grasp the main idea. For example: ((⋅ (∘ T μ) (∘ λ S) (∘ S λ)) (∘)) If written with full names, it becomes: ((vertical-compose (horizontal-compose T μ) (horizontal-compose λ S) (horizontal-compose S λ)) (horizontal-compose)) This example uses just two types of composition operations. If programming in the style of Cartesian Closed Categories (CCC), more operators would be introduced (e.g., (co)pairing, (co)product, bang from/to, etc.). Insisting on full names for all of these operations would make the code cluttered and hard to read, as the screen would be filled with long names, obscuring the actual computation. In general programming, function names tend to be the longest identifiers, which usually isn't a problem because those paradigms focus on nested function calls. Proper formatting and indentation can make such code readable. However, in a composition-centered style, such as CCC-style programming, there are rarely other variable names, and expressions are almost entirely composed of functions. In this context, using full names for functions drastically reduces readability, making it difficult to understand the structure and intent of the code. On a related note, I used to avoid Unicode in programming, but I've come to appreciate its advantages. There are several reasons for this:
While Racket does not traditionally rely on Unicode, and programmers can always define their own aliases for such operations, I believe there are common functions with well-established Unicode symbols (e.g., ∘ for composition). Not using these symbols where they are appropriate feels counterintuitive and inconsistent. Adding them as built-in aliases would better reflect their mathematical origins and make such code more approachable for users familiar with these conventions. |
The ∘ (and other operators) provided in my ctp package is mainly intended to highlight example code in the documentation and provide hyperlinks to corresponding term definitions. It's not designed to encourage programmers to I'll test the mentioned libraries individually on GitHub to check whether this addition causes any issues and report back with the results. |
Personally, I also don't think it's worth adding the unicode symbol to Besides reasons that many people here have mentioned, there's another one: having a symbol for |
I searched for files containing the ∘ symbol and found 60 files on GitHub. After excluding cases where ∘ is used in strings, I identified 16 repositories where ∘ is defined as a compose alias or is related to composition:
Additionally, I found 4 repositories where I'm not sure if the use of ∘ is related to composition, and none of these would conflict with the proposed addition:
So far, I've identified two scenarios where introducing ∘ could cause issues (both involve repositories that treat ∘ as a compose alias):
> (require (rename-in racket/base [compose compose]))
> (require (rename-in racket/base [compose ∘]))
string:1:20: rename-in: identifier `∘' already in nested require spec
at: racket/base
in: (rename-in racket/base (compose ∘))
[,bt for context]
> (require (rename-in racket/base [compose c] [compose c]))
string:1:53: rename-in: duplicate identifier
at: c
in: (rename-in racket/base (compose c) (compose c))
[,bt for context] I was surprised that this raises an error. I'm not sure this is the intended behavior of Racket.
I'm still in the process of testing these repositories to identify other potential issues and will provide updates as I proceed. |
I tested the repositories and encountered failures in the following (For some repos I wasn't sure how to test, so I simply ran the files containing ∘) :
After excluding repositories that failed due to unrelated issues, the conflicts caused by introducing ∘ are easily resolvable. |
Another point of reference: Haskell provides My 2c: function composition is basic enough to warrant a symbolic operator, though unlike +, there may be diverging preferences on what this operator should be (e.g. Qi's ~> for left-to-right vs right-to-left composition, or even Haskell's |
I like ∘₁. Thank you for pointing this out. |
∘[1]
as aliases for compose[1]
∘[₁]
as aliases for compose[1]
8b8dcc0
to
332c076
Compare
Unfortunately, the question is not whether it would be easy to adjust a package, but whether we force package authors to make a change and/or just have broken packages. Our policy is to avoid adding exports that break packages. On occasion, an addition has seemed important enough that we worked with package authors to change (or commit to changing) packages in advance, and then we could proceed with an addition. I think those cases involved a smaller number of packages, though. If it seems worthwhile chasing down package authors and getting things changed in a way that will allow the addition of |
Thank you for the clarification. I've analyzed the causes of failure in the affected packages and have devised solutions for each case. For example:
I'll proceed to open PRs for the affected repositories with these changes. |
Checklist
Description of change
When implementing mathematical functions in Racket, I often define the alias manually:
(define ∘ compose)
, to represent composed functions likeg∘f
as(∘ g f)
. This repetitive task occurs so frequently that I believe it makes sense for Racket to natively support∘
.