Functional programming: Difference between revisions

Content deleted Content added
m Changed "it's" to the correct possessive form "its"
GreenC bot (talk | contribs)
Reformat 7 archive links. Wayback Medic 2.5 per WP:URLREQ#iaboterr
Line 8:
Functional programming is sometimes treated as synonymous with [[purely functional programming]], a subset of functional programming which treats all functions as [[Deterministic system|deterministic]] mathematical [[Function (mathematics)|functions]], or [[pure function]]s. When a pure function is called with some given arguments, it will always return the same result, and cannot be affected by any mutable [[State (computer science)|state]] or other [[Side effect (computer science)|side effects]]. This is in contrast with impure [[Procedure (computer science)|procedures]], common in [[imperative programming]], which can have side effects (such as modifying the program's state or taking input from a user). Proponents of purely functional programming claim that by restricting side effects, programs can have fewer [[Software bug|bugs]], be easier to [[Debugging|debug]] and [[Software testing|test]], and be more suited to [[formal verification]].<ref name="hudak1989">{{cite journal |last=Hudak |first=Paul |author-link=Paul Hudak |title=Conception, evolution, and application of functional programming languages |journal=ACM Computing Surveys |volume=21 |issue=3 |pages=359–411 |date=September 1989 |url=http://www.dbnet.ece.ntua.gr/~adamo/languages/books/p359-hudak.pdf |doi=10.1145/72551.72554 |s2cid=207637854 |accessdate=2013-08-10 |archivedate=2016-01-31 |archiveurl=https://web.archive.org/web/20160131083528/http://www.dbnet.ece.ntua.gr/~adamo/languages/books/p359-hudak.pdf |url-status=deviated }}</ref><ref name="hughesWhyFPMatters"/>
 
Functional programming has its roots in [[academia]], evolving from the [[lambda calculus]], a formal system of computation based only on functions. Functional programming has historically been less popular than imperative programming, but many functional languages are seeing use today in industry and education, including [[Common Lisp]], [[Scheme (programming language)|Scheme]],<ref name="clinger1987"/><ref name="hartheimer1987"/><ref name="kidd2007"/><ref name="cleis2006"/> [[Clojure]], [[Wolfram Language]],<ref name="reference.wolfram.com">{{cite web |title=Wolfram Language Guide: Functional Programming |url=http://reference.wolfram.com/language/guide/FunctionalProgramming.html |year=2015 |access-date=2015-08-24}}</ref><ref name="Amath-CO"/> [[Racket (programming language)|Racket]],<ref name="racket-video-games"/> [[Erlang (programming language)|Erlang]],<ref name="erlang-faq"/><ref name="armstrong2007"/><ref name="larson2009"/> [[Elixir (programming language)|Elixir]],<ref>{{Cite web|title=The Elixir Programming Language|url=https://elixir-lang.org/|access-date=2021-02-14}}</ref> [[OCaml]],<ref name="minksy2008"/><ref name="leroy2007"/> [[Haskell]],<ref name="haskell-industry"/><ref name="hudak2007"/> and [[F Sharp (programming language)|F#]].<ref name="quantFSharp">{{cite conference |last=Mansell |first=Howard |title=Quantitative Finance in F# |url=http://cufp.galois.com/2008/abstracts.html#MansellHoward |year=2008 |conference=CUFP 2008 |access-date=2009-08-29 |accessdate=2009-08-29 |archivedate=2015-07-08 |archiveurl=https://web.archive.org/web/20150708125937/http://cufp.galois.com/2008/abstracts.html#MansellHoward |url-status=deviated }}</ref><ref name="businessAppsFSharp">{{cite conference |last=Peake |first=Alex |title=The First Substantial Line of Business Application in F# |url=http://cufp.galois.com/2009/abstracts.html#AlexPeakeAdamGranicz |year=2009 |conference=CUFP 2009 |access-date=2009-08-29 |archive-url=https://web.archive.org/web/20091017070140/http://cufp.galois.com/2009/abstracts.html#AlexPeakeAdamGranicz |archive-date=2009-10-17 |url-status=deviateddead |accessdate=2009-08-29 |archivedate=2009-10-17 |archiveurl=https://web.archive.org/web/20091017070140/http://cufp.galois.com/2009/abstracts.html#AlexPeakeAdamGranicz }}</ref> [[Lean (proof assistant)|Lean]] is a functional programming language commonly used for verifying mathematical theorems.<ref>https://pp.ipd.kit.edu/uploads/publikationen/demoura21lean4.pdf</ref> Functional programming is also key to some languages that have found success in specific domains, like [[JavaScript]] in the Web,<ref>{{Cite web|last=comments|first=27 Jun 2017 Matt Banz Feed 603up 2|title=An introduction to functional programming in JavaScript|url=https://opensource.com/article/17/6/functional-javascript|access-date=2021-01-09|website=Opensource.com|language=en}}</ref> [[R (programming language)|R]] in statistics,<ref name="useR"/><ref name="Chambers"/> [[J (programming language)|J]], [[K (programming language)|K]] and [[Q (programming language from Kx Systems)|Q]] in financial analysis, and [[XQuery]]/[[XSLT]] for [[XML]].<ref name="Novatchev"/><ref name="Mertz"/> Domain-specific declarative languages like [[SQL]] and [[Lex (software)|Lex]]/[[Yacc]] use some elements of functional programming, such as not allowing [[mutable object|mutable values]].<ref name="Chamberlin_Boyce"/> In addition, many other programming languages support programming in a functional style or have implemented features from functional programming, such as [[C++11]], [[C Sharp (programming language)|C#]],<ref>{{Citation|title=Functional Programming with C# - Simon Painter - NDC Oslo 2020|url=https://www.youtube.com/watch?v=gvyTB4aMI4o| archive-url=https://ghostarchive.org/varchive/youtube/20211030/gvyTB4aMI4o| archive-date=2021-10-30|language=en|access-date=2021-10-23}}{{cbignore}}</ref> [[Kotlin (programming language)|Kotlin]],<ref name=":0">{{Cite web|url=https://kotlinlang.org/docs/tutorials/kotlin-for-py/functional-programming.html|title=Functional programming - Kotlin Programming Language|website=Kotlin|access-date=2019-05-01}}</ref> [[Perl]],<ref>{{cite book |last=Dominus |first=Mark J. |author-link=Mark Jason Dominus |title=Higher-Order Perl |publisher=[[Morgan Kaufmann]] |year=2005 |isbn=978-1-55860-701-9 |title-link=Higher-Order Perl}}</ref> [[PHP]],<ref>{{cite book |last=Holywell |first=Simon |title=Functional Programming in PHP |publisher=php[architect] |year=2014 |isbn=9781940111056}}</ref> [[Python (programming language)|Python]],<ref name="AutoNT-13">{{cite web |url=https://www.python.org/community/pycon/dc2004/papers/24/metaclasses-pycon.pdf |archive-url=https://web.archive.org/web/20090530030205/http://www.python.org/community/pycon/dc2004/papers/24/metaclasses-pycon.pdf |archive-date=30 May 2009 |title=Python Metaclasses: Who? Why? When? |last=The Cain Gang Ltd. |access-date=27 June 2009 |url-status=deviateddead |df=dmy-all |archivedate=30 May 2009 |archiveurl=https://web.archive.org/web/20090530030205/http://www.python.org/community/pycon/dc2004/papers/24/metaclasses-pycon.pdf }}</ref> [[Go (programming language)|Go]],<ref>{{Cite web|last=|first=|date=|title=GopherCon 2020: Dylan Meeus - Functional Programming with Go|url=https://www.youtube.com/watch?v=wqs8n5Uk5OM|access-date=|website=YouTube}}</ref> [[Rust (programming language)|Rust]],<ref>{{Cite web|title=Functional Language Features: Iterators and Closures - The Rust Programming Language|url=https://doc.rust-lang.org/book/ch13-00-functional-features.html|access-date=2021-01-09|website=doc.rust-lang.org}}</ref> [[Raku (programming language)|Raku]],<ref>{{cite web|last=Vanderbauwhede |first=Wim |url=https://wimvanderbauwhede.github.io/articles/decluttering-with-functional-programming/|archive-url=https://web.archive.org/web/20200728013926/https://wimvanderbauwhede.github.io/articles/decluttering-with-functional-programming/|archive-date=28 July 2020|title=Cleaner code with functional programming |date=18 July 2020 |access-date=6 October 2020}}</ref> [[Scala (programming language)|Scala]],<ref name="effective-scala"/> and [[Java (programming language)|Java (since Java 8)]].<ref name="java-8-javadoc"/>
 
== History ==
Line 89:
 
== Concepts ==
A number of concepts<ref>Sean Tull - Monoidal Categories for Formal Concept Analysis.</ref> and paradigms are specific to functional programming, and generally foreign to [[imperative programming]] (including [[object-oriented programming]]). However, programming languages often cater to several programming paradigms, so programmers using "mostly imperative" languages may have utilized some of these concepts.<ref>{{cite web |url=http://byte.com/art/9408/sec11/art1.htm |archive-url=https://web.archive.org/web/20060827094123/http://byte.com/art/9408/sec11/art1.htm |archive-date=2006-08-27 |title=Functional Programming Comes of Age |first=Dick |last=Pountain |work=[[Byte (magazine)|Byte]] (August 1994) |access-date=August 31, 2006 |archivedate=2006-08-27 |archiveurl=https://web.archive.org/web/20060827094123/http://byte.com/art/9408/sec11/art1.htm |url-status=deviateddead }}</ref>
 
=== First-class and higher-order functions ===
Line 325:
 
=== Industry ===
Functional programming has been employed in a wide range of industrial applications. For example, [[Erlang (programming language)|Erlang]], which was developed by the [[Sweden|Swedish]] company [[Ericsson]] in the late 1980s, was originally used to implement [[Fault tolerance|fault-tolerant]] [[telecommunication]]s systems,<ref name="armstrong2007"/> but has since become popular for building a range of applications at companies such as [[Nortel]], [[Facebook]], [[Électricité de France]] and [[WhatsApp]].<ref name="erlang-faq"/><ref name="larson2009"/><ref>{{cite conference |last=Piro |first=Christopher |title=Functional Programming at Facebook |url=http://cufp.galois.com/2009/abstracts.html#ChristopherPiroEugeneLetuchy |year=2009 |conference=CUFP 2009 |access-date=2009-08-29 |archive-url=https://web.archive.org/web/20091017070140/http://cufp.galois.com/2009/abstracts.html#ChristopherPiroEugeneLetuchy |archive-date=2009-10-17 |url-status=deviateddead |accessdate=2009-08-29 |archivedate=2009-10-17 |archiveurl=https://web.archive.org/web/20091017070140/http://cufp.galois.com/2009/abstracts.html#ChristopherPiroEugeneLetuchy }}</ref><ref name="Sim-Diasca"/><ref name="whatsapp.blog.2012">[http://blog.whatsapp.com/index.php/2012/01/1-million-is-so-2011/ 1 million is so 2011] {{Webarchive|url=https://web.archive.org/web/20140219234031/http://blog.whatsapp.com/index.php/2012/01/1-million-is-so-2011/ |date=2014-02-19}} // WhatsApp blog, 2012-01-06: "the last important piece of our infrastracture is Erlang"</ref> [[Scheme (programming language)|Scheme]], a dialect of [[Lisp (programming language)|Lisp]], was used as the basis for several applications on early [[Apple Macintosh]] computers<ref name="clinger1987"/><ref name="hartheimer1987"/> and has been applied to problems such as training-[[Computer simulation|simulation software]]<ref name="kidd2007"/> and [[telescope]] control.<ref name="cleis2006"/> [[OCaml]], which was introduced in the mid-1990s, has seen commercial use in areas such as financial analysis,<ref name="minksy2008"/> [[software driver|driver]] verification, industrial [[robot]] programming and static analysis of [[embedded software]].<ref name="leroy2007"/> [[Haskell]], though initially intended as a research language,<ref name="hudak2007"/> has also been applied in areas such as aerospace systems, hardware design and web programming.<ref name="haskell-industry"/><ref name="hudak2007"/>
 
Other functional programming languages that have seen use in industry include [[Scala (programming language)|Scala]],<ref>{{cite conference |last=Momtahan |first=Lee |title=Scala at EDF Trading: Implementing a Domain-Specific Language for Derivative Pricing with Scala |url=http://cufp.galois.com/2009/abstracts.html#LeeMomtahan |year=2009 |conference=CUFP 2009 |access-date=2009-08-29 |archive-url=https://web.archive.org/web/20091017070140/http://cufp.galois.com/2009/abstracts.html#LeeMomtahan |archive-date=2009-10-17 |url-status=deviateddead |accessdate=2009-08-29 |archivedate=2009-10-17 |archiveurl=https://web.archive.org/web/20091017070140/http://cufp.galois.com/2009/abstracts.html#LeeMomtahan }}</ref> [[F Sharp (programming language)|F#]],<ref name='quantFSharp'/><ref name='businessAppsFSharp'/> [[Wolfram Language]],<ref name="reference.wolfram.com"/> [[Lisp (programming language)|Lisp]],<ref>{{cite web |last=Graham |first=Paul |title=Beating the Averages |url=http://www.paulgraham.com/avg.html |year=2003 |access-date=2009-08-29}}</ref> [[Standard ML]]<ref>{{cite conference |last=Sims |first=Steve |title=Building a Startup with Standard ML |url=http://cufp.galois.com/2006/slides/SteveSims.pdf |year=2006 |conference=CUFP 2006 |access-date=2009-08-29}}</ref><ref>{{cite conference |last=Laurikari |first=Ville |title=Functional Programming in Communications Security. |url=http://cufp.galois.com/2007/abstracts.html#VilleLaurikari |year=2007 |conference=CUFP 2007 |access-date=2009-08-29 |accessdate=2009-08-29 |archivedate=2010-12-21 |archiveurl=https://web.archive.org/web/20101221110947/http://cufp.galois.com/2007/abstracts.html#VilleLaurikari |url-status=deviated }}</ref> and Clojure.<ref>{{cite web |url=http://www.infoq.com/news/2009/01/clojure_production |last=Lorimer |first=R. J. |title=Live Production Clojure Application Announced |date=19 January 2009|work=InfoQ}}</ref> Scala has been widely used in [[Data science]],<ref>{{Cite book |last=Bugnion |first=Pascal |title=Scala for Data Science |publisher=[[Packt]] |year=2016 |isbn=9781785281372 |edition=1st |language=en-US}}</ref> while [[ClojureScript]],<ref>{{Cite web |title=Why developers like ClojureScript |url=https://stackshare.io/clojurescript |access-date=2024-04-29 |website=StackShare |language=en}}</ref> [[Elm (programming language)|Elm]]<ref>{{Citation |last=Herrick |first=Justin |title=jah2488/elm-companies |date=2024-04-29 |url=https://github.com/jah2488/elm-companies |access-date=2024-04-29}}</ref> or [[PureScript]]<ref>{{Cite web |title=Why developers like PureScript |url=https://stackshare.io/purescript |access-date=2024-04-29 |website=StackShare |language=en}}</ref> are some of the functional frontend programming languages used in production. [[Elixir (programming language)|Elixir]]'s Phoenix framework is also used by some relatively popular commercial projects, such as [[Font Awesome]] or [[Allegro Platform|Allegro]] (one of the biggest e-commerce platforms in Poland)<ref>{{Cite web |last=Team |first=Editorial |date=2019-01-08 |title=ALLEGRO - all you need to know about the best Polish online marketplace |url=https://ecommercegermany.com/blog/allegro-all-you-need-to-know-about-the-best-polish-online-marketplace |access-date=2024-04-29 |website=E-commerce Germany News |language=en-US}}</ref>'s classified ads platform ''Allegro Lokalnie.''<ref>{{Cite web |title=Websites using Phoenix Framework - Wappalyzer |url=https://www.wappalyzer.com/technologies/web-frameworks/phoenix-framework/ |access-date=2024-04-29 |website=www.wappalyzer.com}}</ref>
 
Functional "platforms" have been popular in finance for risk analytics (particularly with large investment banks). Risk factors are coded as functions that form interdependent graphs (categories) to measure correlations in market shifts, similar in manner to [[Gröbner basis]] optimizations but also for regulatory frameworks such as [[Comprehensive Capital Analysis and Review]]. Given the use of OCaml and [[Caml]] variations in finance, these systems are sometimes considered related to a [[categorical abstract machine]]. Functional programming is heavily influenced by [[category theory]].{{Citation needed|date=August 2022}}
Line 375:
<ref name="java-8-javadoc">{{cite web |title=Documentation for package java.util.function since Java 8 (also known as Java 1.8) |url=https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html |access-date=2021-06-16}}</ref>
 
<ref name="racket-video-games">{{cite web |title=State-Based Scripting in Uncharted 2 |url=http://www.gameenginebook.com/gdc09-statescripting-uncharted2.pdf |archive-url=https://web.archive.org/web/20121215014637/http://www.gameenginebook.com/gdc09-statescripting-uncharted2.pdf |archive-date=2012-12-15 |access-date=2011-08-08 |archivedate=2012-12-15 |archiveurl=https://web.archive.org/web/20121215014637/http://www.gameenginebook.com/gdc09-statescripting-uncharted2.pdf |url-status=deviateddead }}</ref>
 
<ref name="hudak2007">{{cite conference |last1=Hudak |first1=Paul |last2=Hughes |first2=J. |last3=Jones |first3=S. P. |last4=Wadler |first4=P. |author-link1=Paul Hudak |title=A history of Haskell: being lazy with class |url=http://dl.acm.org/citation.cfm?doid=1238844.1238856 |conference=Third ACM SIGPLAN Conference on History of Programming Languages |___location=San Diego, California| date=June 2007 |doi=10.1145/1238844.1238856 |access-date=2013-09-26}}</ref>
Line 381:
<ref name="useR">{{cite web |url=http://www.r-project.org/useR-2006/program.html |title=The useR! 2006 conference schedule includes papers on the commercial use of R |publisher=R-project.org |date=2006-06-08 |access-date=2011-06-20}}</ref><ref name="Chambers">{{cite book |last=Chambers |first=John M. |author-link=John Chambers (programmer) |title=Programming with Data: A Guide to the S Language |publisher=Springer Verlag |year=1998 |pages=67–70 |isbn=978-0-387-98503-9}}</ref>
 
<ref name="Amath-CO">{{cite web |website=Department of Applied Math |publisher=University of Colorado |title=Functional vs. Procedural Programming Language |url=http://amath.colorado.edu/computing/mmm/funcproc.html |archive-url=https://web.archive.org/web/20071113175801/http://amath.colorado.edu/computing/mmm/funcproc.html |archive-date=2007-11-13 |access-date=2006-08-28 |archivedate=2007-11-13 |archiveurl=https://web.archive.org/web/20071113175801/http://amath.colorado.edu/computing/mmm/funcproc.html |url-status=deviateddead }}</ref>
 
<ref name="Novatchev">{{cite web |url=http://fxsl.sourceforge.net/articles/FuncProg/Functional%20Programming.html |first=Dimitre |last=Novatchev |title=The Functional Programming Language XSLT — A proof through examples |access-date=May 27, 2006}}</ref><ref name="Mertz">{{cite web |url=http://gnosis.cx/publish/programming/xml_models_fp.html |first=David |last=Mertz |title=XML Programming Paradigms (part four): Functional Programming approached to XML processing |access-date=May 27, 2006 |work=IBM developerWorks}}</ref>