10 ms·
> It shouldn't be a language builtin if we can achieve the same thing with a plain old library function. That is an aesthetic preference, and this is why: some
by pron 9y ago
> It shouldn't be a language builtin if we can achieve the same thing with a plain old library function.
That is an aesthetic preference, and this is why: sometimes you don't want a general abstraction that allows you to express certain constructs because that same general abstraction may be used to express constructs that you don't want your programmers to create. In that case, you want an ad hoc builtin construct instead of a more general abstraction.
The things that you want or don't want in order to maximize some value function are exactly what aesthetics is. There is no mathematical theorem, or no natural law, determining which value function I aim to optimize, and therefore no objective rule for deciding which language features are "correct", and no absolute measure for what constitutes good design. The only measure for good design is whether or not the product optimizes the value function that you've chosen on aesthetic grounds.
> What and how would you translate?
Think of writing a factorial function recursively and one using some looping monad. The two have isomorphic operational semantics, but completely different denotations. Monads basically let you express any kind of computation, including those that you can express with plain lambda terms. In addition -- and this is important -- some computations can _only_ be expressed with monads (assuming you don't have linear types). This means that lambda calculus contains two different, and incompatible, ways of expressing computation. This makes program analysis unnecessarily complicated (unless your program is just a sequential computation, in which case lambda calculus is a nice formalism because that's the usage it's been invented for). Formalisms invented for general (i.e., not necessarily sequential) computation, including sequential, concurrent and interactive, don't have this problem, and have just a single, simple and uniform way to express any kind of computation. This makes them amenable to mathematical analysis, something the pure-FP model has difficulty with (you'll note that when analyzing pure FP, various ad-hoc frameworks need to be invented, e.g., a message-passing model for concurrency etc.).
- pron 9y agoP.S. This quote explains the crucial aesthetics component of formal systems: We do not attach any character of uniqueness or absolute truth to any particular system of logic. The entities of formal logic are abstractions, invented because of their use in describing and systematizing facts of experience or observation, and their properties, determined in rough outline by this intended use, depend for their exact character on the arbitrary choice of the inventor... [T]here exist, undoubtedly, more than one formal system whose use as a logic is feasible, and of these systems one may be more pleasing or more convenient than another, but it cannot be said that one is right and the other wrong. The quote is from a 1932 paper called A Set of Postulates for the Foundation of Logic, in which Alonzo Church first introduced the formal system that would become his lambda calculus. "Pleasing or convenient" is aesthetics, and the thing Church tried to make pleasing or convenient when he later turned his (inconsistent) logic into a universal computation calculus was how people in the 1920s and '30s thought of computation in the context of mathematics. In more modern, computer science terms, that thing was sequential, batch computation, namely something that takes a value and produces a value. I think that most programs written today are not sequential; if not concurrent or distributed, they are at least interactive, and while they may contain a great number of sequential computation bits, those bits are not the tricky, subtle or complex things about them, and therefore form the part of least concern (even if they form the majority of lines of code). On the other hand, in the '70s and '80s, more modern formal systems were invented that incorporate cleanly, elegantly and simply all (or, most importantly, the trick) parts of computation into a mathematical framework. Part of the reason why so much emphasis is placed on lambda calculi by contemporary logicians (AKA programming language theorists) is precisely that this calculus is so well studied because it so old. But programmers aren't logicians, and so they do not require the oldest and best understood formal system, designed to optimize concerns that they may not share. It's true that many paradigms can be embedded as DSLs in functional languages, but that's not helpful. That a language achieves its goals doesn't mean its host is equally appropriate.
- lmm 9y ago> The things that you want or don't want in order to maximize some value function are exactly what aesthetics is. There is no mathematical theorem, or no natural law, determining which value function I aim to optimize, and therefore no objective rule for deciding which language features are "correct", and no absolute measure for what constitutes good design. The only measure for good design is whether or not the product optimizes the value function that you've chosen on aesthetic grounds. If that were true there would be no point talking about language design at all. I don't believe that; the programming community does manage to eventually achieve rough consensus about which language designs are good and which are bad, and ultimately there is a fact of the matter when it comes to productivity, however difficult we find it to actually measure. > Think of writing a factorial function recursively and one using some looping monad. The two have isomorphic operational semantics, but completely different denotations. Monads basically let you express any kind of computation, including those that you can express with plain lambda terms. In addition -- and this is important -- some computations can _only_ be expressed with monads (assuming you don't have linear types). This means that lambda calculus contains two different, and incompatible, ways of expressing computation. I don't think I've ever seen this "looping monad"; certainly what you're describing doesn't sound at all like the usual state monad. Could you point towards an implementation of the kind of monad you're talking about? That aside, the normal representation of recursion in the lambda calculus is already that you form a structure that represents the recursion to happen and then pass it to an operator that actually does the recursion (a Y combinator or similar), so I don't see this notion that any monad-like representation would be substantially different. > Formalisms invented for general (i.e., not necessarily sequential) computation, including sequential, concurrent and interactive, don't have this problem, and have just a single, simple and uniform way to express any kind of computation. This makes them amenable to mathematical analysis, something the pure-FP model has difficulty with (you'll note that when analyzing pure FP, various ad-hoc frameworks need to be invented, e.g., a message-passing model for concurrency etc.) Your own talks have covered the theme that doing formal reasoning about the full operational state space of any nontrivial program is impractical because that state space is so large. If we're to hope to be able to do practical analysis of programs we have to have a representation that collapses that space hugely. Identifying expressions with their reductions (i.e. their evaluation) does not come cheap, but it pays a huge dividend in terms of how much it simplifies the space that we need to reason about - and my experience is that this does not just benefit the formal model, it helps the human programmer's reasoning in the same way. Even back when I worked in Java, those things that don't fit neatly into the FP framework - concurrency, exceptions - were the biggest sources of bugs. And now that I've used FP-compatible abstractions for these things - however ad-hoc those abstractions were at first - I've found that bug incidence has gone way down.