4 ms·
Mathematics is usually written in something like Haskell syntax (or typically more extreme on the C-Haskell axis). It would not be surprising to use some random
by dan-robertson 6y ago
Mathematics is usually written in something like Haskell syntax (or typically more extreme on the C-Haskell axis). It would not be surprising to use some random symbol to represent a binary operation the author thinks is important. In Haskell, juxtaposition of non-keywords always means application (function application, or type constructor application) or alludes to it in a pattern match. In mathematics the following: f g h x might correspond to any of the following Haskell depending on context:
f (g (h x))
f . g . h . x
x . h . g . f
x . h . g $ f
(f <> g <> h <> x) -- potentially more a type-dependant operation than <>
(f <> g <> h) <%> x -- For some operation <%>
Furthermore Haskell is only indentation sensitive whereas mathematics notation depends on alignment and structure in two dimensions more generally.
Therefore I claim it is silly to talk about mathematics notation as if it were a single standard thing because the reality is that mathematics notation depends on context a lot and varies a huge amount by situation. It is not obvious that the kind of elementary algebraic notation one might encounter in high school is the best fit for programming which tends to deal with totally different things.
I actually think Haskell makes a pretty good language for a small group as it may be better moulded to the problem domain. I recall an example from a mailing list where someone defined:
(.) x f = f x -- for my poor OO brain
infixl 9 (.)
So they could write code like:
prodSize xs ys = xs.length * ys.length
Which seems silly except that the user has adapted the language to fit themselves. Some mathematicians also prefer function application/composition on the right. It makes values pass through functions from left to right the same way that their types are written.
- throwaway894345 6y agoI’m not sure I follow your point since at times it seems like you’re agreeing with the parent and other times disagreeing;L. In any case, I think we can acknowledge that math syntax isn’t one single thing or even that it is more ambiguous than Haskell and still acknowledge that many (if not all of) the math ‘dialects’ share a terseness that is similar to that of Haskell and which creates similar readability problems. I certainly feel comfortable saying that the terseness of math syntax causes me readability problems in much the same way as the terseness of Haskell syntax. Visual structure and indentation are useful for communicating with humans because we don’t parse text the same way that a parser program would. Admittedly Haskell is parser-program friendly, but it doesn’t make sense to optimize for parser programs at the expense of humans.
- jraph 6y agoWell, I would not know how to parse the mathematical formula `f g h x` without context and I would not have naturally read it as a function application. Function applications in math are usually written with parentheses and commas, except when explicitly using the lambda calculus notation or defining a specific syntax, which you don't have to do when using the usual syntax which you refer to as the one somebody encounters in high school, and which is also used in computer science and mathematics papers. You are right on the fact that it's usual to define arbitrary operators in maths. It's also usual in math to use single letters, including Greek letters, for function names and constants or parameters, and this is fine in mathematical formulas or texts, when there are not too many of them and when there are explained next to the formula, but that would be a nightmare in a code base. Ever read a program written by a physicist, who translated their formula into a program, without having the "source"? Weird operators are a feature when writing maths, but could be a code smell in a program. Unlike an academic paper, we have space, and we have auto-completion. Give me a proper, readable, easy to understand name, unless your operator is really omnipresent (it's a great thing we don't have to spell out +, ×, or - of course). > It is not obvious that the kind of elementary algebraic notation one might encounter in high school is the best fit for programming which tends to deal with totally different things. Indeed. What I am saying is that if you don't use this notation, it will probably feel less intuitive to many people because what they are used to is this algebraic notation we learn in high school. The Haskell notation might be more apt (and I definitely see its strengths). However, the opposite is also true, so this is not really an argument: I have not found any real drawback to this notation after years of using it in my programs. This syntax do not feel verbose to me so the Haskell notation does not solve any problem I have.
- jcelerier 6y ago> Mathematics is usually written in something like Haskell syntax a good way to make something readable to the general public is to make the opposite of what a mathematician would do
- dboreham 6y agoStandardized mathematical notation is one of the crowning human achievements of the last 2 millennia.
- jcelerier 6y ago"crowning human achievements" and "understandable to the general public" aren't, I believe, correlated in any way
- LolWolf 6y agoA good way to make something readable to the general public would be to not even write it in math. (But then again, that's not a very useful statement when we need things written out in math.) Snarkiness aside, I do agree that a good number of mathematicians don't know how to write, but that does not mean that mathematical writing is intrinsically bad. We don't judge a random programming language as "bad," just because a random member of the public isn't able to parse it (since a random member of the public likely has not learned any programming, much less that language's syntax), so why would we apply similar statements to math in the same way?
- dan-robertson 6y agoWell the parent comment seemed to claim that C syntax is more based on mathematics than Haskell. I don’t want to comment on what is better. Mathematicians tend to care quite a lot about notation and finding good notations but that notation typically doesn’t have to last very long or travel very far. People tend to take it for granted that having very variable situation specific notation is bad but I don’t think it’s obviously true. I certainly don’t think it’s obvious that programming language syntax should be based on the kind of high school algebra notation people are familiar with because that notation is mostly useful for manipulating sums of products of variables raised to powers, and one-argument functions thereof. I don’t think programming fits that category or that addition and multiplication are particularly important operations in programming.