6 ms·
[citation needed], because this sounds wrong: > A functional language is a procedural language this doesn’t sound authoritative: > that meets the following t
by minitech 10y ago
[citation needed], because this sounds wrong:
> A functional language is a procedural language
this doesn’t sound authoritative:
> that meets the following three additional conditions
this doesn’t sound like the right distinction:
> It encourages using values over objects
and this doesn’t sound meaningful:
> It discourages distinguishing between procedures that compute the same function.
- catnaroek 10y ago> this doesn’t sound authoritative A functional language still uses procedures, even Haskell! To see what I mean, consider the possibility of divergence (infinite loop, `undefined`, `error "foo"`, you name it). It doesn't make sense for a mathematical function to diverge. The difference between, on the one hand, Haskell, ML and Racket, and, on the other hand, JavaScript, Python and Ruby, is that the former group encourages you program with procedures that compute mathematical functions, whereas the latter group does not. > this doesn’t sound like the right distinction It doesn't suffice, but it's a precondition. For good or for bad, mathematical functions are mappings from values to values, so you can't talk about computing functions in a language without a rock-solid notion of (possibly compound) value. > and this doesn’t sound like the right example for (2) [deleted from your original post, but I'm not deleting it from here] Yes, it's the right example. Haskell and ML prevent you from accidentally distinguishing two extensionally equal functions by not letting you compare procedures in the first place. > and this doesn’t sound meaningful These functions ought to be extensionally equal in any mathematically civilized language: function foo(x,y) { return x + y; } function bar(x,y) { return x + y; } But JavaScript lets me distinguish them.
- minitech 10y agoWikipedia is far from the be-all and end-all source, but at least it is one, so here’s a quote from https://en.wikipedia.org/wiki/Functional_programming https://en.wikipedia.org/wiki/Functional_programming: “It is a declarative programming paradigm, which means programming is done with expressions[1] or declarations[2] instead of statements.” I would agree with it that the usual meanings of “procedural language” and “functional language” are not compatible.
- catnaroek 10y agoAny procedural language, not only functional ones, can be expression-oriented, rather than statement-oriented, e.g., Ruby. And Prolog programs are literally lists of declarations (of inference rules), yet Prolog isn't a functional language.
- minitech 10y agoThe quote says functional programming is a type of declarative programming, not the other way around. Prolog is irrelevant. Backing up to equality as an aside, is there any language that will let you determine whether two functions are equal? If the functions that can be compared aren’t restricted to some silly level and the language is Turing-complete, I can’t imagine any better behaviour than Haskell’s that you already mentioned, which you can bring to JavaScript pretty easily.
- catnaroek 10y ago> The quote says functional programming is a type of declarative programming, not the other way around. Well, your quote doesn't even provide a full definition, sooo... > Backing up to equality as an aside, is there any language that will let you determine whether two functions are equal? No, that's obviously undecidable. (Rice's theorem.) But read what I said more carefully. Did I ever say “A functional language lets you determine whether two functions are equal?” I didn't! What I said is “A functional language doesn't let you distinguish equal functions.” Not letting you test functions for equality is a perfectly valid (and, in fact, the only valid) approach in a higher-order language. > which you can bring to JavaScript pretty easily. Not really. I can't undefined JavaScript's existing equality operator.
- minitech 10y ago> a perfectly valid (and, in fact, the only valid) approach I thought as much and it would really help if you would just say these sorts of things outright so the comments are actually useful instead of deeply nested wording quibbles. With that out of the way: you can define a subset of JavaScript that satisfies your third condition by saying “don’t compare functions”. That’s why I didn’t consider it a meaningful condition. Functional programming works best as a paradigm and then we can just call languages where it’s standard “functional languages”. Much simpler.
- chriswarbo 10y agoThe nice thing about infinite loops, `undefined` and `error "foo"` is that nothing can use their result (i.e. nothing happens "after", although that's a tricky concept with lazy evaluation!) In other words, Haskell doesn't have try/catch for things like `undefined`, so we do have to worry about them occuring, but we don't have to worry about them causing the code to misbehave; it'll either behave or it will stop progressing (either halting or looping infinitely). On the other hand, the "IO" DSL built in to Haskell can do try/catch; but once you're in IO, all bets are off.
- catnaroek 10y agoOh, I'm not saying Haskell doesn't let you express functions. What I'm saying is that functions are expressed as procedures that compute them. The nice thing about Haskell is that it distinguishes between procedures that may only compute functions (or diverge), and procedures with arbitrary effects.
- chriswarbo 10y ago> For good or for bad, mathematical functions are mappings from values to values, so you can't talk about computing functions in a language without a rock-solid notion of (possibly compound) value. Erm, yes you can. You don't need "a rock-solid notion" of anything in order to talk about anything. It's certainly nice to have such well-defined concepts/terms, but requiring them is preposterous.
- catnaroek 10y agoJavaScript doesn't have compound values. This is a fact. When you evaluate the JavaScript expression `{ first: "hello", second: "hello" }`, what you get is a pointer (or reference if you will) to an object with two fields. The object is compound, but the pointer is a primitive, indivisible value.
- minitech 10y ago> The object is compound, but the pointer is a primitive, indivisible value. So? Is the problem here that you can’t compare objects equivalent according to this with `==`? You can make a comparison to do this properly. (This is why functional programming as a paradigm works better and functional languages are just those where it’s the obvious standard.)
- catnaroek 10y ago> You can make a comparison to do this properly. That's not the point! Even if I made a custom equality comparison that says two different objects are “equal”, it would be unsound to treat them as equal, because there exist other constructs in JavaScript that will let me distinguish them. For example, if I mutate one of the objects, the other will remain in its original state. This is exactly why a usable functional language must provide a good notion of compound value!
- deleted 10y ago[deleted]
- 10y ago
- yyhhsj0521 10y agoYes it makes sense for a mathematical function to diverge. You just need to change the domain and range to their "lifted" version. See [https://en.wikibooks.org/wiki/Haskell/Denotational_semantics https://en.wikibooks.org/wiki/Haskell/Denotational_semantics]
- catnaroek 10y agoThat gives you the <sarcasm>very pleasant</sarcasm> choice of working in a category without sums or tensor products distributing over sums! No thanks. In practice, Haskellers don't think this way about their programs. Haskell's library ecosystem attests to the fact they think of Hask as some moral analogue of the category of sets, which has both sums and tensor products. And the worst sin a semantics can commit is to not reflect how programmers actually think about their code.