Talk:Functional programming: Difference between revisions

Content deleted Content added
m Archiving 3 discussion(s) to Talk:Functional programming/Archive 3) (bot
 
(39 intermediate revisions by 21 users not shown)
Line 1:
{{Article history
{{ArticleHistory
|action1=FAC
|action1date=22:12, 21 June 2006
Line 26:
|topic=Engtech
}}
{{WikiProject banner shell|class=B|vital=yes|1=
{{Vital article|level=4|topic=Technology|class=C}}
{{WikiProject Spoken Wikipedia}}
{{WikiProjectBannerShell |1=
{{WikiProject Computing|importance=Top |software=y |software-importance=Top |science=y |science-importance=Top}}
{{WikiProject Spoken Wikipedia |En-Functional_programming.ogg |446744874}}
{{WikiProject Computing|class=CComputer science|importance=Top}}
{{WikiProject Computer science|class=C|importance=Top}}
}}
{{User:MiszaBot/config
Line 40 ⟶ 39:
|archive = Talk:Functional programming/Archive %(counter)d
}}
{{Archives |bot=MiszaBotLowercase Isigmabot III |age=3 |units=months |search=yes |index=/Archive index }}
{{User:HBC Archive Indexerbot/OptIn
|target=/Archive index |mask=/Archive <#> |leading_zeros=0 |indexhere=yes
}}
 
== Letters between Beckus and Dijkstra ==
== Fixing the lede ==
The section about Beckus delivering a Turing Award lecture about FP should also include the letters surrounding that period between Dijkstra & Beckus. https://medium.com/@acidflask/this-guys-arrogance-takes-your-breath-away-5b903624ca5f <!-- Template:Unsigned IP --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/144.6.170.230|144.6.170.230]] ([[User talk:144.6.170.230#top|talk]]) 09:35, 30 March 2025 (UTC)</small> <!--Autosigned by SineBot-->
 
== Coding Styles section mostly detracts ==
I've reverted Ruud Koot's lede, as it's against [[WP:JARGON]] and [[WP:TECHNICAL]], which requires us to provide a description that can be understood by anyone. If the current English intro contains bad English grammar, then let's work in fixing the grammar, but the article still should start with a description that uses layman terms. The more technical description can also be provided right afterwards, for increased precision.
 
Coding styles are different opinionated approaches to the same problem. For example, the Haskell section of Coding Styles effectively illustrates different coding styles. Implementing the same code in different languages is not an example of different coding styles, as the different languages may use the same coding style.
Can you please exactly identify what are the problems with the current wording? [[User:Diego Moya|Diego Moya]] ([[User talk:Diego Moya|talk]]) 19:52, 11 August 2013 (UTC)
 
Languages that only feature one coding style should be removed from this section (or have another coding style added), as they have nothing to compare/contrast and therefore only confuse and detract from the actually beneficial sections. <!-- Template:Unsigned IP --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/64.141.80.20|64.141.80.20]] ([[User talk:64.141.80.20#top|talk]]) 05:45, 3 June 2019 (UTC)</small> <!--Autosigned by SineBot-->
: "a style of building the structure and elements computer programs" isn't grammatically correct English, nor is "not in the program's state". It is not possible to begin discussing the semantics of a piece of writing if it doesn't even begin to be syntactically correct. Exactingly what do you think is wrong with the original lede? —''[[User:Ruud Koot|Ruud]]'' 21:41, 11 August 2013 (UTC)
::It requires the reader to already understand the concepts of "programming paradigm", "computaton", "evaluation" and "application of functions", "state", "mutable data" and "lambda calculus" in order to begin making sense of the definition. The new definition states earlier the main practical aspect of FP, that functions always return the same value given the same input; this follows the advice to [[Wikipedia:TECHNICAL#Write_one_level_down|write one level down]], providing a definition based on concrete and simple concepts instead of complex abstractions. [[User:Diego Moya|Diego Moya]] ([[User talk:Diego Moya|talk]]) 06:27, 12 August 2013 (UTC)
:::I very much prefer Ruud Koot's lede to the current one. It's much more clearly written, and gives a more informative overview of the topic. Functional programming ''is'' a [[programming paradigm]], so I don't understand the aversion to mentioning that in the lead sentence (and I don't see the need for a definition like "''a style of building the structure and elements of computer programs''" which is so vague that it is useless). If a user can't understand what [[computation]] or [[evaluation of a function]] is, they are not going to be able to understand what functional programming is, no matter how much you dumb down or oversimplify the lead. It's good to avoid ''unnecessary'' jargon, but some subjects simply require the reader to have some prerequisite knowledge. For instance, the article [[manifold]] doesn't try to target itself towards users who have no idea what a [[topological space]] or [[neighborhood (mathematics)|neighborhood]] is -- you just can't talk about the subject without bringing these up. Likewise, you cannot accurately talk about functional programming without discussing [[evaluation]], [[program state]], or the [[lambda calculus]]. Anyhow, I support reverting back to Ruud Koot's version, and making whatever improvements you want to that, rather than trying to fix the current one. -- [[User:Mesoderm|Mesoderm]] ([[User talk:Mesoderm|talk]]) 08:14, 12 August 2013 (UTC)
::::It's a matter of style (and the current lede includes the term "programming paradigm", so I don't understand where you see any aversion to mentioning it). Nobody is suggesting removing those terms for precision, it's just that there's no need to have them in the first sentence. Other topics that are not functional programming deal with computation, lambda calculus and evaluation, so those are not definitory of FP; but using functions that always return the same result to build programs is unique to this paradigm, so it's a good definition. (And no, I don't think that FP is an essentially complex subject nor that it requires understanding lambda calculus to grasp it). [[User:Diego Moya|Diego Moya]] ([[User talk:Diego Moya|talk]]) 13:17, 12 August 2013 (UTC)
:::::I'm sorry, I misspoke -- I didn't intend to say that you had an aversion to including [[programming paradigm]] in the first sentence - I meant an aversion to including it with just a wikilink without the (oversimplified/incorrect) definition. Anyhow, I don't want to argue about this either, but I don't think it's just "a matter of style". I think in this case, it's also a matter of being incorrect, oversimplified, and less readable. But now that I've made my view clear on this, I'll let other editors decide what to do about it. -- [[User:Mesoderm|Mesoderm]] ([[User talk:Mesoderm|talk]]) 18:55, 12 August 2013 (UTC)
::: My holiday is over and I'm not planning to spent much time on pointless arguing over over lede sections the comming months, so I'll keep it brief:
:::# "building the structure and elements of computer programs" is a vague and confusingly worded synonym for "computer programming". Saying that "functional programming is a style of computer programming" carries the exact same information, except that is can be understood instead of misunderstood.
:::# "based on pure functions that produce results that depend only on their inputs and not on the program state":
:::#* "based on" is one of those ambiguous phrases that should be avoided. As not ''all'' functional programming is done purely, "emphasizes" would probably be a more appropriate choice. A verbal noun is missing in this sentence, it should probably be "evaluation".
:::#* I would say that "pure function" is unnecessary jargon here, one should only have to be thinking about functions in the mathematical sense of the word.
:::#* "and not on the program state": Depending on how you define program state, this is not even correct. It is mutable state that is avoided in functional programming. But talking about mutable state only makes sense when you are thinking about imperative languages (which wouldn't be an unreasonable assumption to make for most readers, however): an explicit contrast with imperative languages needs to be made, like the previous lede did.
:::# "It is a declarative programming paradigm, which means programming is done with expressions and uses no implicit state.": "Done with" is, again, too vague. This is, as currently phrased, not even an accepted definition of declarative programming. "Used no implicit state" duplicates the previous sentence.
:::# "In functional code," More duplication of what has already been said (although, arguably, this time it is stated more clearly.)
:::# "Eliminating side effects..." Where do these "side effects" suddenly come from? As an expert I know that having functions depend on mutable state is a from of side effect, but we haven't even introduced mutable side effects yet. Any poor PHP programming is going to be hopelessly lost by now.
:::It would be more effective to improve the previous lede&mdash;there certain is much room for improvement there as well&mdash;than to continue with this trainwreck: it is even less accessible to layman than the previous lede. —''[[User:Ruud Koot|Ruud]]'' 17:35, 12 August 2013 (UTC)
 
: Agree. This section should be cleaned-up. No point in listing non-functional languages. Sure, any imperative language can have `fib(n) = fib(n-1) + fib(n-2)` defined, but that's not the point, or else this list will grow indefinitely. [[User:Ybungalobill|bungalo]] ([[User talk:Ybungalobill|talk]]) 22:19, 27 November 2019 (UTC)
=== Functional versus pure functional in lede ===
 
I agree. I do not think that including these examples provide much value at all; there is already an example of imperative vs. functional programming at the top of the section. I don't even think the Haskell part should remain: I don't think that showing different coding styles is particularly relevant to an understanding of FP, and something like that would be better suited for a Haskell tutorial rather than an encyclopaedia article. I would like to remove the entire "Coding Styles" subsection if there are no objections. [[User:Quuxbazbarfoo|Quuxbazbarfoo]] ([[User talk:Quuxbazbarfoo|talk]]) 21:43, 28 April 2020 (UTC)
The first sentence is
:: Agreed. It provides no value at all. As it currently exists, it simply encourages people to add their own favorite languages to the list. I will remove the section. --[[User:Nullzero|Nullzero]] ([[User talk:Nullzero|talk]]) 21:57, 28 April 2020 (UTC)
<blockquote>In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as '''the evaluation of mathematical functions and avoids changing-state and mutable data'''.</blockquote>
 
== Criticism section ==
This sounds like "pure functional programming" to me, rather than just "functional". I would say functional programming is a style where you compose functions to get results, as opposed to getting results via a step-by-step process. I would consider the following functional, though not pure functional (or a good idea).
 
> Functional programming is also key to some languages that have found success in specific domains, like JavaScript in the Web.
def get_five_ints():
return list(map(lambda _: int(input("Enter an integer: ")), range(5)))
 
This is rather opinionated and poorly reflected in the current state of the art in Javscript. Javascript tends to be massively used as OOP and not functional despite some trends going on. \\ <!-- Template:Unsigned IP --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/2A01:E0A:5D3:2650:51F0:F3D2:7D33:13D8|2A01:E0A:5D3:2650:51F0:F3D2:7D33:13D8]] ([[User talk:2A01:E0A:5D3:2650:51F0:F3D2:7D33:13D8#top|talk]]) 11:19, 21 November 2021 (UTC)</small> <!--Autosigned by SineBot-->
"Functional" is a manner of abstraction, but "pure functional" gives the nice guarantees like referential transparency and lazy evaluation. --[[Special:Contributions/72.226.86.106|72.226.86.106]] ([[User talk:72.226.86.106|talk]]) 02:37, 11 July 2015 (UTC)
 
I've reverted the criticism section for now. I think a criticism section certainly is a good idea, but I don't really understand any of the points in the current one, and it doesn't have any references. If anyone can provide clarification or references for these points that would be much appreciated ({{ping|35.137.225.220}}).
== Functional programming in non-functional languages ==
The elephant in the room is javascript. Readers of this article are most likely using a client with an embedded javascript engine... Javascript/ECMAScript should be at the top of the list of non-functional languages having "functional features". <small><span class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:Kwagmire|Kwagmire]] ([[User talk:Kwagmire|talk]] • [[Special:Contributions/Kwagmire|contribs]]) 23:02, 27 July 2014 (UTC)</span></small><!-- Template:Unsigned --> <!--Autosigned by SineBot-->
 
> it does not really allow the developer to build and manipulate "categories" as first class objects.
== author bias ==
 
Is this really a bad thing? I don't think FP is advertised as a setting for *doing* category theory, it merely uses concepts from category theory.
this article is written with a clear bias by the author. <span style="font-size: smaller;" class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/38.88.190.138|38.88.190.138]] ([[User talk:38.88.190.138|talk]]) 20:34, 20 August 2014 (UTC)</span><!-- Template:Unsigned IP --> <!--Autosigned by SineBot-->
 
>Note that a "category" is just a computation graph (not unlike TensorFlow).
===Functional Programming not mathematical functions===
 
Not sure what this means; categories are very general and abstract, they don't encode any specific form of computation. I don't know much about TensorFlow and have just done a very brief search on computation graphs, but I don't see the connection here. If there's a source I'd be interested in reading it.
It is a style of simply building a program using functions. The functions are complete of them selves. Not having side effects or creating them. Functional programming is present in early languages as described about lisp. We can say every computer action is mathematical. And that is correct. However puting everything in the same class does not help. Computers work with characters that are encoded as numbers. That being said means the leadin should express the concepts in layman terms.
 
> "internal" computation graph called the Kleisli category
Functional programming languages should not be part of the definition. Functional programming has been utilized almost from the beginning of computer development. Functions waere utilized before programming language devalopment. Early computing utilizing subroutines were common on the first stored memory computers. Many programs were nearly all calls to Subroutines that implemented higher level operations. Multiply and divide were subroutines on early machines having only add and subtract. Having care memory subroutines remained in memory when the computer was shut down.
 
Also not sure what this means. Kleisli categories are another abstract concept, not tied to computation graphs.
As a programmer we think of functions as being typed. Therefore a mathematical function is one that is of numeric type.
 
> Developers insert their code into the Kleisli category via monads
Functional programming is more a concept of functions being defined such that they always operate consistantly. But a useful program has to operate on something external. A function that reads data is not consistant in what it returns. A pure functional language is of little use as it has no input abilities.
 
Monads have lots of uses in FP, but they're definitely not required, even for pure FP (AFAIK before monads were used in FP, Haskell programs were basically pure functions with inputs/outputs being lists of strings/events). Is this referring to doing impure computation in something like the IO monad?
An example of a pure functional language would be early Mathcad versions. Before I/O was added. Like a spread sheet all input data is coded in the source. Pure functional languages would have input data coded into the program. And that is workable for some applications like mathcad. Design (engineering) active documents are a good example of usable (practical) functional programming languages.
 
> (basically 'proxies')
VisSim is another graphical (functional) programming language. In actuality some functions are dependent on their current state. Integration for example. But sense integration is a mathematically defined function having long history I think such functions built into the language may be exceptions. Aftor all it is a time dependent simulation language.
 
What kind of proxies are these?
Anyway functional programming is a hard thing to explain.
 
> notoriously arcane math terminology.
An example of a functional language having input is Treemeta. The input stream is the input to the function and its output an abstract syntax tree representation of of its input.
 
Complex terminology is certainly a common criticism of FP (especially Haskell), but I think this can be said in a more neutral way.
A syntax rule describes a language phrase to be recognized and returns success or failure. A rule always does the same thing with the same input character sequence. It is consistent as the same input always produces the same output.
 
[[User:Quuxbazbarfoo|Quuxbazbarfoo]] ([[User talk:Quuxbazbarfoo|talk]]) 19:26, 25 May 2020 (UTC)
Every syntax rule is compiled into a function. Because all rules take the same input argument (the position in the input stream) there is no need of a syntax rule having an argument list. The outputs are to language defined stacks.
 
:: I feel like FP terminology is not complex when you use it to ''compute''. It only becomes complex when, ironically, you use it to do category theory, with all complexity coming from category theory. Just my 2 cents. --[[User:Nullzero|Nullzero]] ([[User talk:Nullzero|talk]]) 03:28, 26 May 2020 (UTC)
For example a mathematical expression is a sequence of terms that are added or subtracted. Or could be a single term. Likewise a term is a sequence of factors (or divisors)...
 
== Lead section ==
An expression rule describes the mathematical form and it's transformation:
<pre>expr = term $(('+':ADD|'-':SUB)term!2)</pre> It is assumed that term will transform it's input in the same manor.
 
The last paragraph of the lead section is way too heavy on citations. Do we really need a citation from 1987 on how to program a text editor? What is that doing there anyway (ref name="hartheimer1987")? Honestly, there should be no citations in a lead section, unless something is so controversial it causes a knee-jerk reaction from newbies to add a citation needed tag without first checking the body of the article. See [[WP:LEAD]]. Please get rid of most of them, the article will be easier to deal with. -- [[User:GreenC|<span style="color: #006A4E;">'''Green'''</span>]][[User talk:GreenC|<span style="color: #093;">'''C'''</span>]] 18:24, 16 May 2024 (UTC)
The language has three stacks. The call stack(containing function returns), node stack(contains nodes created by the : operator), and parse stack that contains tokens and abstract tree structures created from nodes and parsed elements by the ! operator. The result of the expr would be a single term or an ADD or SUB tree on the parse stack. i.e. ADD[term,term] an ADD tree.
 
I== wouldRemain arguefocused that these languages are uniqueon functional programming languages having input.==
[[User:Steamerandy|Steamerandy]] ([[User talk:Steamerandy|talk]]) 21:06, 16 January 2015 (UTC)
 
If no one objects I'm going to clean up sections that discuss points unrelated to function vs. other paradigms. For example, the start of Abstraction compared the time it takes to execute an even() call vs calling the mod operator directly. On one compiler. For a language which compiles to java bytecode and was then tested on one jre/jvm. Even if this comparison was more thorough, I don't see how this in any way relates to a definition of functional programming or a comparison to other paradigms. [[User:Dontfunkintellme|Dontfunkintellme]] ([[User talk:Dontfunkintellme|talk]]) 15:14, 29 March 2025 (UTC)
===Functional design programming===
 
Functional design was practiced on large scale programming project. Reservation systems are an example. Designed top down define all subsystems and functions before puting any code down. All functions were defined in detail as to their input, output and function. Layers of detail before coding. The allowed many programmers to work on the project. Forty plus programmers simultaneously worked on the Ramada Inn reservation systeam. The TWA flight reservation system was done the same way as many large scale projects are done. Very few of these functions have side effects. All side effect functions dealing with I/O or transaction messagong. The Ramada reservation system was a 40 man year project implemented in less then a year.
 
Top down functional design is closely related to functional programming.
[[User:Steamerandy|Steamerandy]] ([[User talk:Steamerandy|talk]]) 21:52, 16 January 2015 (UTC)
 
== D language? ==
 
http://en.wikipedia.org/wiki/Functional_programming#D <- Why is D chosen as an example of an imperative language that also does functional programming? This trend of filling all Wikipedia pages with advertisements of D makes me vomit. I don't see any reason why D should be considered in this context. It's an unpopular language without formal semantics.. The language author didn't even know what higher order functions are some years ago (see [https://groups.google.com/forum/#!topic/comp.lang.misc/gOZWUGWVmCw Jon Harrop vs Walter Bright]). [[Special:Contributions/84.250.47.87|84.250.47.87]] ([[User talk:84.250.47.87|talk]]) 03:00, 17 February 2015 (UTC)
:D is pretty similar to C. I found the example helpful in its familiarity. Even if it is unpopular (currently [http://langpop.com/ ranked 15th on langpop], over the other example languages) and despite any faults it may have for functional programming ({{citeneeded}}?), it is useful for examples just by being familiar to C-family programmers. --[[Special:Contributions/72.226.86.106|72.226.86.106]] ([[User talk:72.226.86.106|talk]]) 18:54, 10 July 2015 (UTC)
 
== The section on non-functional languages ==
 
<blockquote>First-class functions have slowly been added to mainstream languages. For example, in early 1994, support for lambda, filter, map, and reduce was added to Python. Then during the development of Python 3000, Guido van Rossum called for the removal of these features.[44] However, he later changed his mind, and only reduce was removed,[45] though it remains accessible via the functools standard library module.[46]</blockquote>
 
This seems to equate first-class functions with lambda, map, filter, and reduce. Python had first-class functions from the beginning (Guido: "... I had made functions first-class objects..."[http://python-history.blogspot.de/2009/04/origins-of-pythons-functional-features.html]). Python shouldn't be listed as a language that ''added'' first-class functions.
 
C/C++ has passing of function pointers, and C++ templating allow them to be used without fully specifying type. The C++ standard [http://www.cplusplus.com/reference/algorithm/ <code><algorithm></code> header] has many functions which take functions as parameters, and the [http://www.cplusplus.com/reference/functional/ <code><functional></code> header] helps make and use function objects. C++11 added ''anonymous'' function support, and those lambdas can have closures. Functions are no more and no less first-class than before.
 
Javascript deserves a mention. [[Douglas Crockford]] calls it a "Lisp in C's clothing".[http://www.crockford.com/javascript/javascript.html] It has first-class functions, closures, and anonymous functions, and it's common to pass functions as arguments.
--[[Special:Contributions/72.226.86.106|72.226.86.106]] ([[User talk:72.226.86.106|talk]]) 00:53, 11 July 2015 (UTC)
 
== The lede - as opposed to? ==
 
"so calling a function f twice with the same value for an argument x will produce the same result f(x) each time"
 
As opposed to all those other computer languages where calling f(x) produces different results each time for the same x? Perhaps there is an important idea there but if so it is pretty fucking badly expressed. Is it just that there are no global variables? If so, yawn. [[User:Greglocock|Greglocock]] ([[User talk:Greglocock|talk]]) 06:41, 24 April 2017 (UTC)