6 ms·
> 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 natura
by 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.
- pron 9y ago> If that were true there would be no point talking about language design at all. Why not? People talk about music, art and, well, design, all the time. > the programming community does manage to eventually achieve rough consensus about which language designs are good and which are bad That still doesn't mean there's no large aesthetic component. > ultimately there is a fact of the matter when it comes to productivity, however difficult we find it to actually measure. I agree, except that very large differences in just about anything are pretty easy to measure. I think it is almost an established fact at this point that no great differences in productivity exist between modern languages. > 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 All formalisms have expressions and reductions. Their denotation is just different. For FP it's so-called "partial functions" (which resemble computable functions); for classical imperative languages it's Hoare triplets (or some other mathematical object). It's just that the denotation offered by lambda calculus is inconvenient when it comes to interactive/concurrent/distributed programs, precisely because the lambda calculus itself cannot directly represent any of them in its reductions, rather delegating them to externally defined mechanisms (IO types, message passing etc.). > and my experience is that this does not just benefit the formal model, it helps the human programmer's reasoning in the same way. I agree, but lambda calculus is quite bad at this compared to alternatives. Where it's good -- sequential programs -- not much help is needed. You can have immutability and the thing FP advocates mistakenly call "referential transparency" (when they really mean a simple denotation) in formalisms that are much better suited to modern programming than lambda calculus. And I really wouldn't mind saying, well, LC doesn't help with the hard stuff, but it does help with the easy stuff, so we should all adopt if there had been any evidence that pure FP yields a large benefit, but there isn't. > I've found that bug incidence has gone way down. I believe you, but think that your experience isn't at all universal. Others may find employing better discipline (including precise and even formal analysis of programs/algorithms) in the languages they like to yield more of an impact, while adopting a very different programming style to be a distraction that just hurts overall productivity. > 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? Ugh, you made me look up Haskell syntax :) So, you can have: fac1 :: Int -> Int fac1 0 = 1 fac1 n = n * fac1 (n-1) fac2 :: Int -> Int fac2 n = go n 1 1 where go n i x = if i <= n then (go n (i+1) (i*x)) else x fac3 :: Int -> Cont r Int fac3 0 = return 1 fac3 n = do a <- fac3 (n-1) cont $ \k -> k (a * n) fac4 :: (Int, Int, Int) -> State (Int,Int,Int) () fac4 (n, i, accum) = put (if i < n then (n, i+1, i * accum) else (n, i, accum)) (fac4 doesn't really express the full computation, but I wanted to make clear what's going on; fac3 is a better, though less clear example) All really express the same computation -- the operational semantics are isomorphic (I could have gotten some of the details a bit wrong, but in general) -- but the functional denotation does not express that. Even in classical imperative languages the denotation (say, using Hoare triplets) is isomorphic. The reason is that the functional denotation, is, well, a function and not a computation. This is a great simplification in sequential programs, but becomes very problematic when interaction/concurrency is involved. > 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) 1. FP programming languages are not really Church’s lambda calculus, and the Y combinator in them is implicit. You cannot define a Y combinator in a typed LC. (scratch that -- this is wrong; see comment below) 2. The problem exists even in “proper” LC, as passing the “step function” to a Y combinator or in a monad still yields isomorphic operational semantics that are incomparable types.