ผลต่างระหว่างรุ่นของ "การเขียนโปรแกรมเชิงฟังก์ชัน"
ล วรรค |
แปลเพิ่ม |
||
บรรทัด 7: | บรรทัด 7: | ||
ภาษาโปรแกรมเชิงฟังก์ชันโดยเฉพาะ[[ภาษาโปรแกรมเชิงฟังก์ชันบริสุทธิ]] เช่น [[ภาษาโฮป]]ถูกในความสำคัญใน[[วงการวิชาการ]]มากกว่าในการพัฒนาซอฟต์แวร์เชิงพาณิชย์ อย่างไรก็ตามภาษาโปรแกรมที่มีชื่อเสียงซึ่งสนับสนุนการเขียนโปรแกรมเชิงฟังก์ชัน เช่น [[ภาษาคอมมอนลิสป์]] [[ภาษา Scheme]]<ref name="clinger1987"/><ref name="hartheimer1987"/><ref name="kidd2007"/><ref name="cleis2006"/> [[ภาษา Clojure]]<ref name="useR"/><ref name="Chambers"/> [[ภาษา Wolfram]]<ref name="reference.wolfram.com">{{cite web | title = Wolfram Language Guide: Functional Programming | url = http://reference.wolfram.com/language/guide/FunctionalProgramming.html | year = 2015 | accessdate = 2015-08-24 }}</ref> (หรือ [[ภาษา Mathematica]]) [[ภาษา Racket]]<ref name="racket-video-games"/> [[ภาษาเออร์แลง]]<ref name="erlang-faq"/><ref name="armstrong2007"/><ref name="larson2009"/> [[ภาษา OCaml]]<ref name="minksy2008"/><ref name="leroy2007"/> [[ภาษา Haskell]]<ref name="haskell-industry"/><ref name="hudak2007"/> และ[[ภาษาเอฟชาร์ป]]<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 | accessdate = 2009-08-29 }}</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 | accessdate = 2009-08-29 }}</ref> ใช้ในโปรแกรมประยุกต์เชิงอุตสาหกรรมและเชิงพาณิชย์โดยองค์กรอย่างกว้างขวาง การเขียนโปรแกรมเชิงฟังก์ชันยังได้รับการรองรับใน[[ภาษาเขียนโปรแกรมเฉพาะทาง]]บางภาษา เช่น [[ภาษาอาร์]] (สถิติ)<ref name="Amath-CO"/> [[ภาษาเจ]] [[ภาษาเค]] และ[[ภาษาคิวจาก Kx Systems]] (การวิเคราะห์ทางการคลัง) [[XQuery]]/[[XSLT]] ([[เอกซ์เอ็มแอล]])<ref name="Novatchev"/><ref name="Mertz"/> และ[[ภาษาโอปอล]]<ref name="Opal (programming language)"/> ภาษาเชิงประกาศเฉพาะทางที่ใช้งานอย่างกว้างขวางเช่น [[ภาษาสอบถามเชิงโครงสร้าง]] และ [[Lex]]/[[Yacc]] ใช้บางส่วนประกอบของการเขียนโปรแกรมเชิงฟังก์ชันโดยเฉพาะใน eschewing [[วัตถุที่เปลี่ยนแปลงได้]].<ref name="Chamberlin_Boyce"/> |
ภาษาโปรแกรมเชิงฟังก์ชันโดยเฉพาะ[[ภาษาโปรแกรมเชิงฟังก์ชันบริสุทธิ]] เช่น [[ภาษาโฮป]]ถูกในความสำคัญใน[[วงการวิชาการ]]มากกว่าในการพัฒนาซอฟต์แวร์เชิงพาณิชย์ อย่างไรก็ตามภาษาโปรแกรมที่มีชื่อเสียงซึ่งสนับสนุนการเขียนโปรแกรมเชิงฟังก์ชัน เช่น [[ภาษาคอมมอนลิสป์]] [[ภาษา Scheme]]<ref name="clinger1987"/><ref name="hartheimer1987"/><ref name="kidd2007"/><ref name="cleis2006"/> [[ภาษา Clojure]]<ref name="useR"/><ref name="Chambers"/> [[ภาษา Wolfram]]<ref name="reference.wolfram.com">{{cite web | title = Wolfram Language Guide: Functional Programming | url = http://reference.wolfram.com/language/guide/FunctionalProgramming.html | year = 2015 | accessdate = 2015-08-24 }}</ref> (หรือ [[ภาษา Mathematica]]) [[ภาษา Racket]]<ref name="racket-video-games"/> [[ภาษาเออร์แลง]]<ref name="erlang-faq"/><ref name="armstrong2007"/><ref name="larson2009"/> [[ภาษา OCaml]]<ref name="minksy2008"/><ref name="leroy2007"/> [[ภาษา Haskell]]<ref name="haskell-industry"/><ref name="hudak2007"/> และ[[ภาษาเอฟชาร์ป]]<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 | accessdate = 2009-08-29 }}</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 | accessdate = 2009-08-29 }}</ref> ใช้ในโปรแกรมประยุกต์เชิงอุตสาหกรรมและเชิงพาณิชย์โดยองค์กรอย่างกว้างขวาง การเขียนโปรแกรมเชิงฟังก์ชันยังได้รับการรองรับใน[[ภาษาเขียนโปรแกรมเฉพาะทาง]]บางภาษา เช่น [[ภาษาอาร์]] (สถิติ)<ref name="Amath-CO"/> [[ภาษาเจ]] [[ภาษาเค]] และ[[ภาษาคิวจาก Kx Systems]] (การวิเคราะห์ทางการคลัง) [[XQuery]]/[[XSLT]] ([[เอกซ์เอ็มแอล]])<ref name="Novatchev"/><ref name="Mertz"/> และ[[ภาษาโอปอล]]<ref name="Opal (programming language)"/> ภาษาเชิงประกาศเฉพาะทางที่ใช้งานอย่างกว้างขวางเช่น [[ภาษาสอบถามเชิงโครงสร้าง]] และ [[Lex]]/[[Yacc]] ใช้บางส่วนประกอบของการเขียนโปรแกรมเชิงฟังก์ชันโดยเฉพาะใน eschewing [[วัตถุที่เปลี่ยนแปลงได้]].<ref name="Chamberlin_Boyce"/> |
||
การเขียนโปรแกรมเชิงฟังก์ชันสามารถทำได้ในภาษาที่ไม่ได้ออกมาเฉพาะสำหรับการเขียนโปรแกรมเชิงฟังก์ชัน ตัวอย่างเช่น [[ภาษาเพิร์ล]]ซึ่งเป็นภาษาโปรแกรมเชิงคำสั่งมีบทหนึ่งของหนังสือที่อธิบายว่าประยุกต์แนวคิดการเขียนโปรแกรมเชิงฟังก์ชันอย่างไร<ref>{{cite book | last = Dominus | first = Mark J. | authorlink = Mark Jason Dominus | title = [[Higher-Order Perl]] |publisher=[[Morgan Kaufmann]] | year = 2005 |isbn = 1-55860-701-3 }}</ref> นี้ยังเป็นจริงสำหรับ[[ภาษาพีเอชพี]]<ref>{{cite book | last = Holywell | first = Simon | title = Functional Programming in PHP | publisher = php[architect] | year = 2014 | isbn = 9781940111056}}</ref> [[C++11]], [[ภาษาจาวา]] 8 และ[[ภาษาซีชาร์ป]] 3.0 [[ภาษาจูเลีย]]ก็เสนอความสามารถการเขียนโปรแกรมเชิงฟังก์ชันเช่นกัน กรณีที่น่าสนใจคือ[[ภาษาสกาลา]]<ref name="effective-scala"/> – มักเขียนในเชิงฟังก์ชัน แต่ก็มีการแสดงตนของผลข้างเคียงและสถานะที่เปลี่ยนแปลงได้ ซึ่งทำให้จัดอยู่ในบริเวณสีเทาระหว่างภาษาเชิงคำสั่งและเชิงฟังก์ชัน |
|||
== อ้างอิง == |
== อ้างอิง == |
||
บรรทัด 42: | บรรทัด 44: | ||
<ref name="Opal (programming language)">[[Opal (programming language)|OPtimized Applicative Language]]</ref> |
<ref name="Opal (programming language)">[[Opal (programming language)|OPtimized Applicative Language]]</ref> |
||
<ref name="effective-scala">{{cite web | title = Effective Scala | work = Scala Wiki | url = http://twitter.github.com/effectivescala/?sd | accessdate = 2012-02-21 | quote=Effective Scala. }}</ref><ref name="racket-video-games">{{cite web | title = State-Based Scripting in Uncharted 2 | url = http://www.gameenginebook.com/gdc09-statescripting-uncharted2.pdf | archiveurl = https://web.archive.org/web/20121215014637/http://www.gameenginebook.com/gdc09-statescripting-uncharted2.pdf | archivedate = 2012-12-15 | accessdate = 2011-08-08 }}</ref> |
|||
<ref name="Chamberlin_Boyce">{{cite journal | title = SEQUEL: A structured English query language | author = [[Donald D. Chamberlin]] and [[Raymond F. Boyce]] | journal = Proceedings of the 1974 ACM SIGFIDET | pages = 249–264 | year = 1974 }}</ref> |
<ref name="Chamberlin_Boyce">{{cite journal | title = SEQUEL: A structured English query language | author = [[Donald D. Chamberlin]] and [[Raymond F. Boyce]] | journal = Proceedings of the 1974 ACM SIGFIDET | pages = 249–264 | year = 1974 }}</ref> |
รุ่นแก้ไขเมื่อ 18:39, 23 มกราคม 2560
ในวิทยาการคอมพิวเตอร์ การเขียนโปรแกรมเชิงฟังก์ชันเป็นกระบวนทัศน์การเขียนโปรแกรมที่รูปแบบการสร้างโครงสร้างและส่วนประกอบของโปรแกรมคอมพิวเตอร์ซึ่งปฏิบัติต่อการคำนวณว่าเป็นการประเมินผลฟังก์ชันทางคณิตศาสตร์และหลีกเลี่ยงการเปลี่ยนแปลงสถานะและข้อมูลที่เปลี่ยนแปลงได้ โดยเป็นกระบวนทัศน์การเขียนโปรแกรมเชิงประกาศซึ่งหมายความว่าการเขียนโปรแกรมทำได้โดยนิพจน์[1]หรือการประกาศ[2]แทนข้อความสั่ง ในโปรแกรมเชิงฟังก์ชัน ค่าผลลัพธ์ของฟังก์ชันขึ้นอยู่กับ[ อาร์กิวเมนต์]ที่นำเข้าสู่ฟังก์ชันเท่านั้น ดังนั้นการเรียกฟังก์ชัน f สองครั้งด้วยค่าอาร์กิวเมนต์ x เดียวกันจะให้ค่าผลลัพธ์ f(x) เท่ากันทุกครั้ง การกำจัดผลข้างเคียง ได้แก่ การเปลี่ยนแปลงสถานะที่ไม่ขึ้นกับสิ่งที่นำเข้าฟังก์ชัน สามารถทำให้ง่ายขึ้นที่จะทำความเข้าใจและพยากรณ์พฤฒิกรรมของโปรแกรมซึ่งเป็นหนึ่งในแรงจูงใจของการพัฒนาของการเขียนโปรแกรมเชิงฟังก์ชัน
การเขียนโปรแกรมเชิงฟังก์ชันมีรากฐานมาจากแคลคูลัสแลมบ์ดาซึ่งเป็นระบบรูปนัยที่พัฒนาในคริสต์ทศวรรษ 1930 เพื่อค้นหาความจริงเกี่ยวกับความคำนวณได้ Entscheidungsproblem นิยามของฟังก์ชัน การประยุกต์ฟังก์ชัน และการเรียกซ้ำ ภาษาเขียนโปรแกรมเชิงฟังก์ชันหลายภาษาสามารถมองว่าเป็นการใส่รายละเอียดเพิ่มจากแคลคูลัสแลมบ์ดา กระบวนทัศน์การเขียนโปรแกรมเชิงประกาศที่เป็นที่รู้จักอื่น ๆ การเขียนโปรแกรมเชิงตรรกะ มีพื้นฐานอยู่บนความสัมพันธ์เชิงตรรกะ[3]
ในกลับกันการเขียนโปรแกรมเชิงคำสั่งเปลี่ยนสถานะด้วยคำสั่งในภาษาต้นทาง ตัวอย่างที่ง่ายที่สุดคือการกำหนดค่า การเขียนโปรแกรมเชิงคำสั่งไม่มีฟังก์ชันในความหมายแบบคณิตศาสตร์แต่มีในความหมายแบบซับรูทีน ซึ่งมีผลข้างเคียงที่อาจะเปลี่ยนค่าของสถานะของโปรแกรมได้ ฟังก์ชันที่ไม่คืนค่าจึงสมเหตุสมผลเพราะขาดความโปร่งใสในการอ้างอิง ได้แก่นิพจน์เดียวกันทางภาษาสามารถให้ผลลัพธ์ที่มีค่าต่างกันได้ในเวลาที่ต่างกันขึ้นกับสถานะของโปรแกรมที่กำลังกระทำการ[3]
ภาษาโปรแกรมเชิงฟังก์ชันโดยเฉพาะภาษาโปรแกรมเชิงฟังก์ชันบริสุทธิ เช่น ภาษาโฮปถูกในความสำคัญในวงการวิชาการมากกว่าในการพัฒนาซอฟต์แวร์เชิงพาณิชย์ อย่างไรก็ตามภาษาโปรแกรมที่มีชื่อเสียงซึ่งสนับสนุนการเขียนโปรแกรมเชิงฟังก์ชัน เช่น ภาษาคอมมอนลิสป์ ภาษา Scheme[4][5][6][7] ภาษา Clojure[8][9] ภาษา Wolfram[10] (หรือ ภาษา Mathematica) ภาษา Racket[11] ภาษาเออร์แลง[12][13][14] ภาษา OCaml[15][16] ภาษา Haskell[17][18] และภาษาเอฟชาร์ป[19][20] ใช้ในโปรแกรมประยุกต์เชิงอุตสาหกรรมและเชิงพาณิชย์โดยองค์กรอย่างกว้างขวาง การเขียนโปรแกรมเชิงฟังก์ชันยังได้รับการรองรับในภาษาเขียนโปรแกรมเฉพาะทางบางภาษา เช่น ภาษาอาร์ (สถิติ)[21] ภาษาเจ ภาษาเค และภาษาคิวจาก Kx Systems (การวิเคราะห์ทางการคลัง) XQuery/XSLT (เอกซ์เอ็มแอล)[22][23] และภาษาโอปอล[24] ภาษาเชิงประกาศเฉพาะทางที่ใช้งานอย่างกว้างขวางเช่น ภาษาสอบถามเชิงโครงสร้าง และ Lex/Yacc ใช้บางส่วนประกอบของการเขียนโปรแกรมเชิงฟังก์ชันโดยเฉพาะใน eschewing วัตถุที่เปลี่ยนแปลงได้.[25]
การเขียนโปรแกรมเชิงฟังก์ชันสามารถทำได้ในภาษาที่ไม่ได้ออกมาเฉพาะสำหรับการเขียนโปรแกรมเชิงฟังก์ชัน ตัวอย่างเช่น ภาษาเพิร์ลซึ่งเป็นภาษาโปรแกรมเชิงคำสั่งมีบทหนึ่งของหนังสือที่อธิบายว่าประยุกต์แนวคิดการเขียนโปรแกรมเชิงฟังก์ชันอย่างไร[26] นี้ยังเป็นจริงสำหรับภาษาพีเอชพี[27] C++11, ภาษาจาวา 8 และภาษาซีชาร์ป 3.0 ภาษาจูเลียก็เสนอความสามารถการเขียนโปรแกรมเชิงฟังก์ชันเช่นกัน กรณีที่น่าสนใจคือภาษาสกาลา[28] – มักเขียนในเชิงฟังก์ชัน แต่ก็มีการแสดงตนของผลข้างเคียงและสถานะที่เปลี่ยนแปลงได้ ซึ่งทำให้จัดอยู่ในบริเวณสีเทาระหว่างภาษาเชิงคำสั่งและเชิงฟังก์ชัน
อ้างอิง
- ↑ "Declaration vs. expression style - HaskellWiki".
- ↑ "Declaration vs. expression style - HaskellWiki".
- ↑ 3.0 3.1 Hudak, Paul (September 1989). "Conception, evolution, and application of functional programming languages" (PDF). ACM Computing Surveys. 21 (3): 359–411. doi:10.1145/72551.72554.
- ↑ Clinger, Will (1987). "MultiTasking and MacScheme". MacTech. 3 (12). สืบค้นเมื่อ 2008-08-28.
- ↑ Hartheimer, Anne (1987). "Programming a Text Editor in MacScheme+Toolsmith". MacTech. 3 (1). สืบค้นเมื่อ 2008-08-28.
- ↑ Kidd, Eric. Terrorism Response Training in Scheme. CUFP 2007. สืบค้นเมื่อ 2009-08-26.
- ↑ Cleis, Richard. Scheme in Space. CUFP 2006. สืบค้นเมื่อ 2009-08-26.
- ↑ "The useR! 2006 conference schedule includes papers on the commercial use of R". R-project.org. 2006-06-08. สืบค้นเมื่อ 2011-06-20.
- ↑ Chambers, John M. (1998). Programming with Data: A Guide to the S Language. Springer Verlag. pp. 67–70. ISBN 978-0-387-98503-9.
- ↑ "Wolfram Language Guide: Functional Programming". 2015. สืบค้นเมื่อ 2015-08-24.
- ↑ "State-Based Scripting in Uncharted 2" (PDF). คลังข้อมูลเก่าเก็บจากแหล่งเดิม (PDF)เมื่อ 2012-12-15. สืบค้นเมื่อ 2011-08-08.
- ↑ "Who uses Erlang for product development?". Frequently asked questions about Erlang. สืบค้นเมื่อ 2007-08-05.
- ↑ Armstrong, Joe (June 2007). A history of Erlang. Third ACM SIGPLAN Conference on History of Programming Languages. San Diego, California. สืบค้นเมื่อ 2009-08-29.
- ↑ Larson, Jim (March 2009). "Erlang for concurrent programming". Communications of the ACM. 52 (3): 48. doi:10.1145/1467247.1467263.
- ↑ Minsky, Yaron; Weeks, Stephen (July 2008). "Caml Trading — experiences with functional programming on Wall Street". Journal of Functional Programming. Cambridge University Press. 18 (4): 553–564. doi:10.1017/S095679680800676X. สืบค้นเมื่อ 2008-08-27.
- ↑ Leroy, Xavier. Some uses of Caml in Industry (PDF). CUFP 2007. สืบค้นเมื่อ 2009-08-26.
- ↑ "Haskell in industry". Haskell Wiki. สืบค้นเมื่อ 2009-08-26.
Haskell has a diverse range of use commercially, from aerospace and defense, to finance, to web startups, hardware design firms and lawnmower manufacturers.
- ↑ Hudak, Paul; Hughes, J.; Jones, S. P.; Wadler, P. (June 2007). A history of Haskell: being lazy with class. Third ACM SIGPLAN Conference on History of Programming Languages. San Diego, California. doi:10.1145/1238844.1238856. สืบค้นเมื่อ 2013-09-26.
- ↑ Mansell, Howard (2008). Quantitative Finance in F#. CUFP 2008. สืบค้นเมื่อ 2009-08-29.
- ↑ Peake, Alex (2009). The First Substantial Line of Business Application in F#. CUFP 2009. สืบค้นเมื่อ 2009-08-29.
- ↑ Department of Applied Math, University of Colorado. "Functional vs. Procedural Programming Language". คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2007-11-13. สืบค้นเมื่อ 2006-08-28.
- ↑ Dimitre Novatchev. "The Functional Programming Language XSLT — A proof through examples". TopXML. สืบค้นเมื่อ May 27, 2006.
- ↑ David Mertz. "XML Programming Paradigms (part four): Functional Programming approached to XML processing". IBM developerWorks. สืบค้นเมื่อ May 27, 2006.
- ↑ OPtimized Applicative Language
- ↑ Donald D. Chamberlin and Raymond F. Boyce (1974). "SEQUEL: A structured English query language". Proceedings of the 1974 ACM SIGFIDET: 249–264.
- ↑ Dominus, Mark J. (2005). Higher-Order Perl. Morgan Kaufmann. ISBN 1-55860-701-3.
- ↑ Holywell, Simon (2014). Functional Programming in PHP. php[architect]. ISBN 9781940111056.
- ↑ "Effective Scala". Scala Wiki. สืบค้นเมื่อ 2012-02-21.
Effective Scala.