Zulip Chat Archive
Stream: new members
Topic: Are these pairs equivalent?
Mr Proof (Jul 09 2024 at 19:04):
If a have a type that takes in two values I could define it either as A->B->Type
or (AxB)->Type
e.g. I have encountered this when thinking about defining vector spaces like R^2
.
Is there advantages/disadvantages to each approach?
This is similar to the problem you have in programming APIs, where a function could take coordinates as separate parameters or a tuple and you end up having to make about 6 different functions to cover all cases.
Marcus Rossel (Jul 09 2024 at 19:11):
What you're describing is called currying. Here's a whole thread on its up- and downsides: https://softwareengineering.stackexchange.com/questions/185585/what-is-the-advantage-of-currying
Mark Fischer (Jul 09 2024 at 19:11):
They're isomorphic (Prod.forall). Which is better is often an aesthetic choice.
My rule of thumb is to prefer A → B → C
over A × B → C
since you can easily partially apply the first. If I'm temped to use A × B
, then I tend to first consider creating a structure instead so that each projection has a nice name.
Last updated: May 02 2025 at 03:31 UTC