Live data from Hacker News

Hey, C Is a Functional Language Too

spin.atomicobject.com

61–70 of 78 posts

Re: Hey, C Is a Functional Language Too

#61
post #17
post #10

I would say the aspect that defines a functional programming language is the support of higher order functions. I.e. functions that can take functions as arguments and more importantly can return functions as return value.

Rather than saying that higher-order functions is the defining feature of functional programming, I would say that it's an essential feature to support its object of defining programs in terms of (mathematical) function application rather than procedural state changes.

Does any higher order function application require state changes to implement as a specific lower order instance.

For example, an instance map is just a cons and a recursive call. No state change needed. You can say something about exposing unwanted details in the cons, but that is a hairier point of contention.

Re: Hey, C Is a Functional Language Too

#62
I disagree completely that this is a 'functional subset' of C. I also don't know a lot about this stuff, so tear me up.

A functional language isn't just one that doesn't use malloc/only uses the stack. It must actually not have state, and instead evaluate a single function down to the result. Here, after calling make_lists, the input and the result still both exist as state variables (immutable, yes, but that's not enough)! At the same time, I haven't looked at code for a lisp interpreter, but I feel safe assuming that it allocates some memory somewhere. Functional programming doesn't have anything to do with the underlying implementation. The trick here, if any, is that the "underlying implementation" and the code are in the same language/program.

Re: Hey, C Is a Functional Language Too

#63
post #10

I would say the aspect that defines a functional programming language is the support of higher order functions. I.e. functions that can take functions as arguments and more importantly can return functions as return value.

I'm not that old but I remember that, back in the days, functional meant just that you are able to use plain functions (without objects) and pass them around. By that definition, C is functional language, as scheme or lisp or javascript and many others. I don't know why, but some years ago, "functional programmers" started to change and twist the definition of functional language step by step, until all those languag…

I think you at mixing words that look similar. It is a large problem in this sort of discussion:

Pure functions. (Only Haskell and friends are strictly pure, as is SQL if you squint.)

Higher order functions. (Java 7 doesn't allow you to pass around a callable function without embedding a link language with reflection or using one-method Runnable.)

First class functions. (Basic, SQL do not have this.)

Generic functions. (C does not have this. C++ does. Java does.)

These are three orthogonal properties a Lang age may have some or all of.

Re: Hey, C Is a Functional Language Too

#64
post #57

Earlier quoted context omitted.

I'm not sure this is even Turing complete considering the limitation he mentions: >The main limitation is that you need to know the size of the return value.

That is a purely theoretical concern, not a practical blocker against any program anyone would ever run.

A program that determines the number of items it needs to store in a list only at runtime doesn't seem that theoretical to me.

Re: Hey, C Is a Functional Language Too

#65

Earlier quoted context omitted.

I'm not that old but I remember that, back in the days, functional meant just that you are able to use plain functions (without objects) and pass them around. By that definition, C is functional language, as scheme or lisp or javascript and many others. I don't know why, but some years ago, "functional programmers" started to change and twist the definition of functional language step by step, until all those languag…

I don't see much use in a definition of "functional language" that includes nearly every computer language. We already have a term for that.

I agree that "nearly every computer language" can be considered functional, as "nearly every computer language" can be considered imperative.

What I do not agree is when "functional programmers" claim that language is not "functional" just because it is not "pure functional" or Haskel alike.

Re: Hey, C Is a Functional Language Too

#66
post #59

Earlier quoted context omitted.

As jeremyjh already pointed out, this results in a pretty weak definition. You end up with JavaScript, Ruby, Python, and Objective-C all being lumped as "functional languages", and if you squint a little bit, you can put Java in there too (anonymous inner classes). I think C, C++ and C# could be as well, but I don't know them well enough. So I don't think it's very productive to use a definition like this, but not be…

Or we could be more precise and acknowledge there are several related features in the realm of "functional" and a language may have some but not all of them, and not make it into a fan club battle. Same goes for OO, which has something like 9 well-known defining features.

I don't think my comment was making anything into a "fan club battle". I was specifically advocating the kind of precision you describe, because I think calling any language with higher-order functions a "functional programming language" results in very muddy waters.

The scenario I described wasn't hypothetical. When a colleague asked our whole office "what's functional programming?" I listened while someone told him that it was just map, filter, and fold. He'd used these in JavaScript already, and was prepared to accept that as an answer. I didn't think that was sufficient, so chimed in and offered some alternative features from other languages that I think are as important as higher order functions, mostly related to minimizing mutable state with managed references and persistent data structures. I think he appreciated my contribution, but I honestly don't know for sure. Maybe it just created more questions.

Re: Hey, C Is a Functional Language Too

#67

Earlier quoted context omitted.

I don't see much use in a definition of "functional language" that includes nearly every computer language. We already have a term for that.

well it's primary use seems to be providing a moving goal post for the functional side during the occasional OO vs Functional skirmishes.

That is required for parity with the OO side. Cf. Alan Kay on OO.

Re: Hey, C Is a Functional Language Too

#68
post #9
post #2

No it's not. What makes a language functional is its ability to eliminate tail recursion.

That's a very weird definition. Eliminating tail calls is fun, and useful. But not all that essential in, say, a lazy language. Having first-class function values in the first place strikes me as way more important. Purity helps, too.

How do you write a function to sum a list of a billion elements in Haskell?

What would happen without tail call elimination?

Re: Hey, C Is a Functional Language Too

#69
post #21

...and pigs can fly, if you throw them fast enough. This is just an encoding of a Turing-complete language into another, I don't see what's been demonstrated here.

http://news.ycombinator.com/item?id=4693920

"everything is turing complete" is a perfect example of the kind of middle-brow dismissal i understood pg to be talking about.

Re: Hey, C Is a Functional Language Too

#70
post #67

Earlier quoted context omitted.

well it's primary use seems to be providing a moving goal post for the functional side during the occasional OO vs Functional skirmishes.

That is required for parity with the OO side. Cf. Alan Kay on OO.

quite. Smalltalk is OO and Haskell is Functional are about the only (currently) accepted facts about the definitions of OO and Functional.
Post reply on HN