6 ms·
> But that is a feature of the functional formalism, not of all formalisms. > Yes, in the functional formalism. Not in every language. I wanted to show a parti
by lmm 9y ago
> But that is a feature of the functional formalism, not of all formalisms.
> Yes, in the functional formalism. Not in every language. I wanted to show a particular property of functional languages that I find unappealing.
I would expect any practical formalism to have escape hatches, just as I expect any practical type system to allow casting - and I find it absurd to see either as a downside for the language.
> Other formalisms have no difficulty assigning simple and natural semantics in either case (and if we disallow concurrent writes but allow concurrent reads, all versions of the algorithm would have isomorphic denotations).
If another program overwrites fac.txt then the semantics you gave in your ghost variables and assertions example would be simple, natural, and wrong (and wrong in a way that's a common source of security vulnerabilities). If your formalism makes fac1 and fac5 equivalent, as you've said it does, then there's no way to then make them un-equivalent.
Really they're equivalent for the purposes of some kinds of analysis under certain constraints and they're not equivalent for other purposes. The functional formalism handles this essentially as well as possible: it allows you to do any analysis that doesn't depend on how you're modelling the filesystem interactions "ahead of time", but forces you to make an explicit choice of model when your analysis is fundamentally dependent on that model.
- pron 9y ago> I would expect any practical formalism to have escape hatches, just as I expect any practical type system to allow casting - and I find it absurd to see either as a downside for the language. Sure, but not every formalism needs the escape hatch to do IO. I don't see it as a downside. FP is beautifully adapted to sequential programs, perhaps more so than other formalisms. It's not the best fit for interactive/concurrent. Also, an unappealing property to one may not be a problem at all to another. You may not be bothered by this, but I am, and that's OK. I like Java, and I assume you like it less, and that's OK, too. > If another program overwrites fac.txt then the semantics you gave in your ghost variables and assertions example would be simple, natural, and wrong If another program overwrites fac.txt, I cannot assume `readFile` to return anything other than a string, if that. I.e., I have nondeterminism about the next state. That's fine, because the next-state relation need not be a function, but you're right that in that case the semantics would be different from the other programs. > Really they're equivalent for the purposes of some kinds of analysis under certain constraints and they're not equivalent for other purposes. No. A specific denotational semantics is either equivalent for those programs or not. I can either guarantee that the next state is deterministic, or I can't. However, you are right that using this kind of semantics can create a situation where one program is a refinement of another. For example, one program can say that the current and next values of the variable x are even integers. Another can say that they're always 2 or 4. This makes program 2 an instance of program 1. Just as in FP you have the notion of a cartesian-closed category (sort of) on types, where every program is an object in that category, in this other kind of formalism you have a lattice that relates all programs. It's just a different theory. > The functional formalism handles this essentially as well as possible Not really, because IO is essentially nondeterministic, and functions don't model nondeterminism well (but relations do!). That's exactly why you need to stuff IO, or anything else that doesn't quite fit the concept of a function, in a monad (which can express all forms of nondeterminism). It's a neat trick, but, like you say, it's sort of an escape hatch. That doesn't mean that all formalisms need to do this for IO, concurrency or other forms of nondeterminism. Functions aren't a great fit for nondeterminism, but other mathematical objects really have no problem with it.
- lmm 9y ago> not every formalism needs the escape hatch to do IO It sounds like that's only achieved by weakening the formalism so far that its guarantees are no stronger than what you have when using the "escape hatch" in the functional world. If the assertions in your Java fac5 are not necessarily true then it seems like analysis in your formalism told us nothing at all about fac5 - and if the assertions don't tell us anything about fac5 then a reader couldn't trust that they tell us anything about fac1 either. > No. A specific denotational semantics is either equivalent for those programs or not. I don't think that contradicts what I said at all. Certainly when analysing these programs we would want to be able to talk about whether they are equivalent, and we would want to consider them as equivalent in certain senses and as inequivalent in other senses. A formalism that can't accommodate that would be less useful (other things being equal) than one that can.
- pron 9y ago> It sounds like that's only achieved by weakening the formalism so far that its guarantees are no stronger than what you have when using the "escape hatch" in the functional world. This is where the aesthetics and pragmatics come into play. In terms of program analysis, the language doesn't really matter (there are actual theorems that prove that no language structure can be exploited to make proving things easier), so in a sense you are right (but this also means that proving general propositions about Haskell is no easier than proving them about assembly code -- which is, unfortunately, true). However, there are questions of convenience. Just as Haskell is easier to analyze than C for sequential code, those other formalisms are easier to analyze and work with than Haskell for interactive and/or concurrent programs. > I don't think that contradicts what I said at all. Certainly when analysing these programs we would want to be able to talk about whether they are equivalent, and we would want to consider them as equivalent in certain senses and as inequivalent in other senses. A formalism that can't accommodate that would be less useful (other things being equal) than one that can. If you read part 4 of my post series on TLA+[1], you'll see that a formalism like TLA allows you to rigorously, mathematically and formally define the "sense" of equivalence that you're interested in. This is not quite possible in functional formalisms. The reason is as follows: computations simply cannot be fully described by functions (unless you describe them essentially as state machines using a monad). Bubble-sort and mergesort compute the same function, but they use different computation. A formalism that allows you to describe arbitrary computations precisely can then allow you to pick your "level of detail". TLA places all computations in a nice Boolean algebra, where all algorithms are neatly organized in a Boolean lattice. You can then define (in two lines) a operator, `ExtensionallyEquivalent(_, _)`, that captures the functional equivalence, but also define other forms of equivalence, down to the most detailed ones. It is completely flexible in the forms of equivalence it can describe. Nevertheless, you won't hear me say that TLA is "better" than functional formalisms, because that extreme flexibility comes at a cost. Simple sequential compositions are more cumbersome in TLA, and since most of the time, when writing sequential programs like compilers, we're not interested in reasoning about interaction or concurrency, functional programming is more convenient. It was mostly designed to write compilers and similarly sequential programs, and I think it is hard to beat in that domain. Because of that it also excels at symbol manipulation (e.g., it is so convenient to define expression types using algebraic data types) -- that is what it was invented for. [1]: https://pron.github.io/posts/tlaplus_part4 https://pron.github.io/posts/tlaplus_part4 it probably requires reading at least part 3 first.