Functional Functions

Let's define a function decorator called functional that, while compiling, checks if the function body adheres to functional programming rules.

    functional int add(int a, int b)
    {
        return a + b;
    }

Rules may be:

    1. Can't use global variables.
    2. Can't call non-functional functions.
    3. Can't modify parameters.


How are you going to implement functional, and what language are you assuming, CeePlusPlus?

If you are speaking abstractly and not assuming a target language, and not worrying about whether functional is implementable, then what does this gain over just assuming that you're programming in a pure functional language to start with?

It may be implemented in existing languages like CeeLanguage, CeePlusPlusLanguage?, JavaLanguage, CeeSharp etc. It must be implemented in compilation phase. I think it can leverage testability and optimizations.

In other words, you're proposing that it be a new language, or rather, a new dialect of some AlgolFamily language. That's why I asked; it would be close to impossible to achieve all of those objectives purely within any of those languages, as opposed to modifying a compiler.

BTW purely functional AlgolFamily languages have been created in the past.

It's still confusing as to whether you are actually proposing something, or just thinking out loud, since you don't seem to care very much which particular language is used, nor do you sound like you're planning to implement such a thing, nor do you sound like you're asking anyone else to.

Yes, I'm just thinking out loud.


GnuCompilerCollection allows you to do this sort of thing (in GnuCpp) as a nonstandard extension. [all of the above? How?]

It seems GnuCee const modifier makes this, recalling the rules:

    1. Can't use global variables. ...since function is not allowed to read global memory.
    2. Can't call non-functional functions. ...Likewise, a function that calls a non-const function usually must not be const.
    3. Can't modify parameters. ...Note that a function that has pointer arguments and examines the data pointed to must not be declared const.

See also FunctionalProgrammingInCpp


CategoryFunctionalProgramming


EditText of this page (last edited January 20, 2011) or FindPage with title or text search