Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think the dialogue is starting to see functional as a positive thing but now that the distinction between "purely functional" and "has first order functions" is becoming increasingly important, the effort previously put in place to blur it is backfiring.


We should probably start calling "purely functional" code "referentially transparent" code to help avoid confusion.

Also, I think you mean "first class functions" rather than "first order".


Well it is true that ("sequential") Erlang is a functional language. It was built as a functional language and has pretty much all the features usually associated with functional languages. It does not just "have first-class functions".

But it is important to understand what "pure" is and is not, that almost no language is pure (because it's hard to produce useful pure software, or even to define how it would work precisely) and that very few strongly encourage purity (at the language level, many do as a social level but offer no help or support for actually doing it when writing code)


"functional" should never have meant "has first-class functions" to anyone.


And yet it has among experts and textbook authors for nigh-on 60 years. It's even sometimes presented (quite credibly, imo) as the feature which makes all the other aspects of functional languages worthwhile.

I didn't notice purity become quite the deal it's become until recently, when boosters started talking it up as a concurrency panacea. Sure it's always been ubiquitous, and mutability was seen as a tricky tool that's best used sparingly, but that was seen as a matter of culture as much as it was a matter of definition. Valuing immutability definitely wasn't presented as functional 'territory' - a somewhat difficult position to hold given things like the PURE keyword in Fortran, or the variable and constant keywords in Ada.


It's pleasant to think of how far we've come, that now most people can just take it for granted that they can pass around functions, that functions can be anonymous, and that closures work more or less the way they ought to. The only languages I can think of that don't support this stuff are ones that are old (like C), or low-level on purpose (again, like C), or defined by a community that is chronically hidebound (like Java). There seems to be a loose consensus among successful programming language makers that higher-order functions and closures are reasonable and expected.

In the future, I expect the next things to become mainstream from the Weird FP Languages will be more type inference, and side-effect annotations. I've often wished that I could declare a few types in a language where you normally omit them, and have the compiler infer as much from those declarations as it reasonably can. I know it's possible, because the SBCL compiler for Common Lisp already does it. This gives many of the same benefits as stricter typing, but in a very lightweight way. And the idea of side-effect annotation is that you can declare whether or not functions have side-effects, and then have the compiler warn you if your code breaks that assumption -- like the PURE functions in Fortran you mentioned. Considering the dangers of mutable state, anything easy you can do to help keep it straight is probably a win.

(Note that in a sufficiently extensible language, e.g. Arc, these things can easily exist outside the language core. I hope that this kind of extensibility becomes mainstream, but wouldn't get my hopes up.)


> It's even sometimes presented (quite credibly, imo) as the feature which makes all the other aspects of functional languages worthwhile.

In other words it doesn't matter how we define "function" as long as they are first class? that's nonsense.

Regardless of historical (ab)usage "functional programming" should be re-appropriated to mean (from wikipedia): "a programming paradigm based on mathematical functions rather than changes in variable states".

Functions are from math, and mathematical functions are first of all pure (f(x) = x + 1 shouldn't also give your dog a bath).


That's exactly what functional means. You're conflating functional and pure. They happen to be (essentially) the same thing in Haskell, but that's not always the case. A functional language can get you really close to pure (but good luck doing anything interesting without monads or mutable state), but even the purest languages cheat. Putting your side-effect code in a main function might help you catch bugs and limit potential side-effects, but it's still not completely pure (and for good reason, at the end of the day you actually want to do stuff).


"Pure" is an adjective applied to "functional" so I don't see the conflation as odd. A language like JavaScript has first class functions, so it's a little bit functional. But no more than that, because most expressions aren't (mathematical) functions. Haskell is purely functional because everything's a function. (I/O primitives like getChar excepted, etc., etc.)

Meanwhile, languages like Haskell don't cheat quite as much as you suggest. Monads are functions, and even in the IO Monad you're doing purely functional manipulation of IO primitives. Think of it as a purely functional funnel through which the dirty data of reality is poured.


He knows what it means. That's why there is a 'should' in that sentence. GP indicates that using functional in this manner is a poor choice.


That's actually what "functional programming" means. https://en.wikipedia.org/wiki/Functional_programming


Read your article. That's not at all what it's supposed to mean. A functional programming language is one which uses the λ-calculus as its base model of computation. PHP has first-class functions. PHP is not a functional language.


From the first paragraph: Many functional programming languages can be viewed as elaborations on the lambda calculus. Most functional languages happen to be variations on λ-calculus, but it's not part of the definition.

Also, it's possible to write PHP in functional style, it's just not common. http://www.michielovertoom.com/software/functional-php/


Ah, selective quoting:

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state.

All programming languages can be written in a functional style. I can create new function types in C++ with templates and function pointers to simulate the action of closures. A functional programming languages is one which has the λ-calculus as its base model of computation as idiomatic in the language. Note that the description above is exactly what is meant by "λ-calculus as the base model of computation." What the article is trying to say is that some languages can be described almost entirely as syntactic sugar on λ-calculus (or System Fω in certain cases).

You do understand that I can simulate first-class functions in any mainstream language? This is not what PL researchers mean when they say "functional programming." Functional programming languages are those which are also predominantly used in a functional style.


I agree, but it was often marketed that way.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: