The notations we use for (1) function composition; and (2) function types, “go in opposite directions”.
For example, take functions f:A→B and g:B→C that you want to compose into a function h:A→C (or h:A→B→C), which, starting at some element a∈A, uses f to obtain some b∈B, and then uses g to obtain some c∈C. The notation goes from left to right, which works well for the minds that are used to the left-to-right direction of English writing (and of writing of all extant European languages, and many non-European languages).
One might then naively expect that a function that works like ”f, then g”, would be denoted fg or maybe with some symbol combining f on the left and g on the right, like f⋆g or f⟹g.
But, no. It’s g∘f or sometimes gf, especially in the category theory land.
The reason for this is simple: function application. For some historical reasons (that are plausibly well-documented somewhere in the annals of history of mathematics), when mathematicians were still developing a symbolic way of doing math (rather than mostly relying on geometry and natural language) (and also the concept of a function, which I hear has undergone some substantial revisions/reconceptualizations), the common way to denote an application of a function f to a number x became f(x). So, now that we’re stuck with this notation, to be consistent with it, we need to write the function ”f, then g” applied to x as g(f(x)). Hence, we write this function abstractly as g∘f and read ”g after f”.
To make the weirdness of this notation fully explicit, let’s add types to the symbols (which I unconventionally write in square brackets to distinguish typing from function applicatoin.
[g:B→C]([f:A→B]([x:A]))
You can see the logic to this madness, but it feels unnatural. Like, of course, you could just as well write the function signature the other way around (like f:B←A or Bf←A) or introduce a notation for function composition that respects our intuition that a composition of ”f, then g”, should have f on the left and g on the right (again, assuming that we’re used to reading left-to-right).
Regarding the first option, I recall Bartosz Milewski saying in his lectures that “we draw string diagrams” right-to-left, so that the direction of “flow” in the diagram is consistent with the g∘f (”g after f”) notation. But now looking up some random string diagrams, this doesn’t seem to be the standard practice (even when they’re drawn horizontally, whereas it seems like they might be more often drawn vertically).
Regarding the second option, some category theory materials use the funky semicolon notation, e.g., this, from Seven Sketches in Compositionality (Definition 3.24). I recall encountering it in places other than that textbook, but I don’t think it’s standard practice.
I like it better, but it still leaves something to be desired, because the explicitized signature of all the atoms of the expression on the left is something like ([f:A→B];[g:B→C])([s:A]). Why not have a notation that respects the obvious and natural order of [A][A→B][B→C]?
Well, many programming languages actually support pipe notation that does just that.[1]
Which makes me think of an alternative timeline where we developed a notation for function application where we first write the arguments and then the functions to be applied to them.
And, honestly, I find this idea very appealing. Elegant. Natural. Maybe it’s because I don’t need to switch my reading mode from LtR to RtL when I’m encountering an expression involving function application, and instead I can just, you know, keep reading. It’s a marginal improvement in fluent interoperability between mathematical formalisms and natural language text.
In a sense, our current style is a sort of boustrophedon, although admittedly a less unruly sort, as the “direction” of the function depends on the context, rather than cycling through LtR and RtL.
(Sidenote: I recently learned about head-directionality, a proposed parameter of languages. Head-initial languages put the head of the phrase before its complements, e.g., “dog black”. Head-final put it after the complements, e.g., “black dog”. Many languages are a mix. So our mathematical notation is a mix in this regard, and I am gesturing that it would be nicer for it to be argument-initial.)
[This is a simple thing that seems evident and obvious to me, but I’ve never heard anyone comment on it, and for some reason, it didn’t occur to me to elaborate on this thought until now.]
I think they are less friendly if you want to do something more complicated with functions accepting more than 1 argument, but this seems solvable.
Indeed, this is called reverse Polish / postfix notation. For example, f(x, g(y, z)) becomes x (y z g) f, which is written without parentheses as x y z g f. That is, if you know the arity of all the letters beforehand, parentheses are unnecessary.
Lol, right! Only after I published this did I recall that there was something vaguely in this spirit called “Polish notation”, and it turns out it’s exactly that.
The notations we use for (1) function composition; and (2) function types, “go in opposite directions”.
For example, take functions f:A→B and g:B→C that you want to compose into a function h:A→C (or h:A→B→C), which, starting at some element a∈A, uses f to obtain some b∈B, and then uses g to obtain some c∈C. The notation goes from left to right, which works well for the minds that are used to the left-to-right direction of English writing (and of writing of all extant European languages, and many non-European languages).
One might then naively expect that a function that works like ”f, then g”, would be denoted fg or maybe with some symbol combining f on the left and g on the right, like f⋆g or f⟹g.
But, no. It’s g∘f or sometimes gf, especially in the category theory land.
The reason for this is simple: function application. For some historical reasons (that are plausibly well-documented somewhere in the annals of history of mathematics), when mathematicians were still developing a symbolic way of doing math (rather than mostly relying on geometry and natural language) (and also the concept of a function, which I hear has undergone some substantial revisions/reconceptualizations), the common way to denote an application of a function f to a number x became f(x). So, now that we’re stuck with this notation, to be consistent with it, we need to write the function ”f, then g” applied to x as g(f(x)). Hence, we write this function abstractly as g∘f and read ”g after f”.
To make the weirdness of this notation fully explicit, let’s add types to the symbols (which I unconventionally write in square brackets to distinguish typing from function applicatoin.
[g:B→C]([f:A→B]([x:A]))
You can see the logic to this madness, but it feels unnatural. Like, of course, you could just as well write the function signature the other way around (like f:B←A or Bf←A) or introduce a notation for function composition that respects our intuition that a composition of ”f, then g”, should have f on the left and g on the right (again, assuming that we’re used to reading left-to-right).
Regarding the first option, I recall Bartosz Milewski saying in his lectures that “we draw string diagrams” right-to-left, so that the direction of “flow” in the diagram is consistent with the g∘f (”g after f”) notation. But now looking up some random string diagrams, this doesn’t seem to be the standard practice (even when they’re drawn horizontally, whereas it seems like they might be more often drawn vertically).
Regarding the second option, some category theory materials use the funky semicolon notation, e.g., this, from Seven Sketches in Compositionality (Definition 3.24). I recall encountering it in places other than that textbook, but I don’t think it’s standard practice.
I like it better, but it still leaves something to be desired, because the explicitized signature of all the atoms of the expression on the left is something like ([f:A→B];[g:B→C])([s:A]). Why not have a notation that respects the obvious and natural order of [A][A→B][B→C]?
Well, many programming languages actually support pipe notation that does just that.[1]
Julia:
Haskell:
Nushell:
Which makes me think of an alternative timeline where we developed a notation for function application where we first write the arguments and then the functions to be applied to them.
And, honestly, I find this idea very appealing. Elegant. Natural. Maybe it’s because I don’t need to switch my reading mode from LtR to RtL when I’m encountering an expression involving function application, and instead I can just, you know, keep reading. It’s a marginal improvement in fluent interoperability between mathematical formalisms and natural language text.
In a sense, our current style is a sort of boustrophedon, although admittedly a less unruly sort, as the “direction” of the function depends on the context, rather than cycling through LtR and RtL.
(Sidenote: I recently learned about head-directionality, a proposed parameter of languages. Head-initial languages put the head of the phrase before its complements, e.g., “dog black”. Head-final put it after the complements, e.g., “black dog”. Many languages are a mix. So our mathematical notation is a mix in this regard, and I am gesturing that it would be nicer for it to be argument-initial.)
[This is a simple thing that seems evident and obvious to me, but I’ve never heard anyone comment on it, and for some reason, it didn’t occur to me to elaborate on this thought until now.]
I think they are less friendly if you want to do something more complicated with functions accepting more than 1 argument, but this seems solvable.
Indeed, this is called reverse Polish / postfix notation. For example, f(x, g(y, z)) becomes x (y z g) f, which is written without parentheses as x y z g f. That is, if you know the arity of all the letters beforehand, parentheses are unnecessary.
Lol, right! Only after I published this did I recall that there was something vaguely in this spirit called “Polish notation”, and it turns out it’s exactly that.