functional

James Iry jamesiry at gmail.com
Wed Mar 10 13:29:44 PST 2010


No, C does not support functional programming.  It is pretty much impossible to write an interesting C program that does not mutate things.  That's not a condemnation of C, I still have a soft spot in my heart for it, but it is a recognition of how C is deeply tied to an imperative model of computation.

Still, I notice you haven't addressed the core of my argument: functional programming languages and purely functional programming existed before there were languages that could enforce the purity.  So insisting that language X is not functional because it does not enforce purity is to redefine the phrase "functional programming language" away from its historical roots in the Lisps and the MLs.

There's a reason that Haskell is called a "purely functional programming language" rather than just a "functional programming language" and that is precisely to clarify one important dimension of difference from the ML family.  (It's actually called a "non-strict purely functional programming language" to talk about another important dimension of difference, but that's not what we're talking about here.)

I don't disagree that it is possible, and even easy to write imperative code in the (impure) functional languages in the Lisp and ML families.  But I do disagree with the contention that that makes them anything but functional languages since the phrase "functional programming language" was invented precisely to talk about their ability to express purely functional code even if there was no automated static proof of that purity.

Walter Bright Wrote:

> James Iry wrote:
> > I'm going to assume you meant "enforce" rather than "support" because
> > both languages support immutability and purity precisely to the
> > extent that the programmers want to use them (although, of the two,
> > Scala's standard library has far more support).
> 
> So does C. The problem is, without compiler support, you have a very 
> difficult time telling by visual inspection if code is functional or not.
> 
> It's like turning off type checking in your C compiler. It still works, 
> but it's really bug prone.




More information about the Digitalmars-d mailing list