4 ms·
Apart from looking like the usual math notation, this "boilerplate" is like punctuation in natural languages: it helps recognize and scan things fast. In many l
by jraph 6y ago
Apart from looking like the usual math notation, this "boilerplate" is like punctuation in natural languages: it helps recognize and scan things fast. In many languages, you both start sentences with capital letters and end them with a dot. A bit redundant, right? But probably much easier and faster to parse.
Many people put non-necessary parentheses in their mathematical expressions to help readers (and themselves!) understand them more easily. Sure, they could be left out, but this is not an optimization for the reader.
In your example, your version looks cleaner, but I find more complicated expressions far more readable with parentheses, brackets and all that stuff present in the second version. This is between angle brackets? This is a type! I don't have to parse the whole expression to infer this.
Expressions written with this "redundant" syntax are seekable. You don't need to read the whole book to pick the one thing you need to know and get on with your life. Redundancy also helps remove doubts on whether something is an error or is intended in complicated cases (good things these languages are strongly typed though, it helps a lot).
At the end of the day, it's all a matter of taste and habits.
Would math be usually written in an Haskell-like syntax, probably almost everybody would find it easy to read and beautiful. It's not, and therefore this kind of syntax probably (almost) only pleases people who are into these languages (because they've got used to it) and represents yet another obstacle for outsiders. I'd actually bet that this plays a role in the fact these languages are not more widely adopted. They make them look unreadable at first impression and people move on. It probably even prevent people from contributing to projects written in these languages. This is bad. I've been able to fix things written in languages I didn't know, but Haskell would probably be hard just because of its syntax, which is unfortunate.
On the other hand, it's good to see and develop new / alternative ideas, including on syntax matters.
- dan-robertson 6y agoMathematics 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.
- lostcolony 6y agoGiven the response a lot of people have to Erlang's syntax (borrowed from Prolog), that has commas, periods, and yes, meaningful casing distinctions (atom vs variable), I'm going to go out on a limb that any benefit from scansion is offset by effort in writing. Further, I'll go out on a limb and say that the benefit of reading has NOTHING to do with audience reception of the syntax (whether that audience is new to the language, or extremely experienced with it), and instead has everything to do with what seems familiar. (I.e., I think I'm in agreement with you in that it's what people's habits are as to whether it's appreciated or not; I'm just disagreeing that improved readability is a factor in whether people appreciate the extra boilerplate, or the possible implication that it's a net gain)
- amw-zero 6y agoWhat math notation uses curly braces and angle brackets? All math notation is terse and focused on efficient expressions of ideas. Haskell syntax is much closer to all of math than C-families.