ผลต่างระหว่างรุ่นของ "การเขียนโปรแกรมเชิงฟังก์ชัน"

จากวิกิพีเดีย สารานุกรมเสรี
เนื้อหาที่ลบ เนื้อหาที่เพิ่ม
Vee (คุย | ส่วนร่วม)
แปลจากภาษาอังกฤษ
Vee (คุย | ส่วนร่วม)
แปลจากภาษาอังกฤษ
บรรทัด 5: บรรทัด 5:


ในกลับกัน[[การเขียนโปรแกรมเชิงคำสั่ง]]เปลี่ยนสถานะด้วยคำสั่งในภาษาต้นทาง ตัวอย่างที่ง่ายที่สุดคือการกำหนดค่า [[การเขียนโปรแกรมเชิงคำสั่ง]]ไม่มีฟังก์ชันในความหมายแบบคณิตศาสตร์แต่มีในความหมายแบบ[[ซับรูทีน]] ซึ่งมี[[ผลข้างเคียง (วิทยาการคอมพิวเตอร์)|ผลข้างเคียง]]ที่อาจะเปลี่ยนค่าของสถานะของโปรแกรมได้ ฟังก์ชันที่ไม่คืนค่าจึงสมเหตุสมผลเพราะขาด[[ความโปร่งใสในการอ้างอิง]] ได้แก่นิพจน์เดียวกันทางภาษาสามารถให้ผลลัพธ์ที่มีค่าต่างกันได้ในเวลาที่ต่างกันขึ้นกับสถานะของโปรแกรมที่กำลังกระทำการ<ref name="hudak1989"/>
ในกลับกัน[[การเขียนโปรแกรมเชิงคำสั่ง]]เปลี่ยนสถานะด้วยคำสั่งในภาษาต้นทาง ตัวอย่างที่ง่ายที่สุดคือการกำหนดค่า [[การเขียนโปรแกรมเชิงคำสั่ง]]ไม่มีฟังก์ชันในความหมายแบบคณิตศาสตร์แต่มีในความหมายแบบ[[ซับรูทีน]] ซึ่งมี[[ผลข้างเคียง (วิทยาการคอมพิวเตอร์)|ผลข้างเคียง]]ที่อาจะเปลี่ยนค่าของสถานะของโปรแกรมได้ ฟังก์ชันที่ไม่คืนค่าจึงสมเหตุสมผลเพราะขาด[[ความโปร่งใสในการอ้างอิง]] ได้แก่นิพจน์เดียวกันทางภาษาสามารถให้ผลลัพธ์ที่มีค่าต่างกันได้ในเวลาที่ต่างกันขึ้นกับสถานะของโปรแกรมที่กำลังกระทำการ<ref name="hudak1989"/>

ภาษาโปรแกรมเชิงฟังก์ชันโดยเฉพาะ[[ภาษาโปรแกรมเชิงฟังก์ชันบริสุทธิ]] เช่น [[ภาษาโฮป]]ถูกในความสำคัญใน[[วงการวิชาการ]]มากกว่าในการพัฒนาซอฟต์แวร์เชิงพาณิชย์ อย่างไรก็ตามภาษาโปรแกรมที่มีชื่อเสียงซึ่งสนับสนุนการเขียนโปรแกรมเชิงฟังก์ชัน เช่น [[ภาษาคอมมอนลิสป์]] [[ภาษา 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> ใช้ในโปรแกรมประยุกต์เชิงอุตสาหกรรมและเชิงพาณิชย์โดยองค์กรอย่างกว้างขวาง




== อ้างอิง ==
== อ้างอิง ==
บรรทัด 10: บรรทัด 14:


<ref name="declaration style">{{cite web|url=https://wiki.haskell.org/Declaration_vs._expression_style#Declaration_style|title=Declaration vs. expression style - HaskellWiki|publisher=}}</ref>
<ref name="declaration style">{{cite web|url=https://wiki.haskell.org/Declaration_vs._expression_style#Declaration_style|title=Declaration vs. expression style - HaskellWiki|publisher=}}</ref>

<ref name="clinger1987">{{cite journal | last = Clinger | first = Will | title = MultiTasking and MacScheme | magazine = MacTech | volume = 3 | issue = 12 | year = 1987 | url = http://www.mactech.com/articles/mactech/Vol.03/03.12/Multitasking/index.html | accessdate = 2008-08-28 }}</ref>

<ref name="hartheimer1987">{{cite journal | last = Hartheimer | first = Anne | title = Programming a Text Editor in MacScheme+Toolsmith | magazine = MacTech | volume = 3 | issue = 1 | year = 1987 | url = http://www.mactech.com/articles/mactech/Vol.03/03.1/SchemeWindows/index.html | accessdate = 2008-08-28 }}</ref>

<ref name="kidd2007">{{cite conference | last = Kidd | first = Eric | url = http://cufp.galois.com/2007/abstracts.html#EricKidd | title = Terrorism Response Training in Scheme | conference = CUFP 2007 | accessdate = 2009-08-26 }}</ref>

<ref name="cleis2006">{{cite conference | last = Cleis | first = Richard | url = http://cufp.galois.com/2006/abstracts.html#RichardCleis | title = Scheme in Space | conference = CUFP 2006 | accessdate = 2009-08-26 }}</ref>

<ref name="erlang-faq">{{cite web | title = Who uses Erlang for product development? | work=Frequently asked questions about Erlang | url = http://www.erlang.org/faq/faq.html#AEN50 | accessdate = 2007-08-05 }}</ref>

<ref name="armstrong2007">{{cite conference | last = Armstrong | first = Joe | title = A history of Erlang | conference = Third ACM SIGPLAN Conference on History of Programming Languages | location = San Diego, California | date = June 2007 | url = http://doi.acm.org/10.1145/1238844.1238850 | accessdate = 2009-08-29 }}</ref>

<ref name="larson2009">{{cite journal | last = Larson | first = Jim | title = Erlang for concurrent programming | journal = Communications of the ACM | volume= 52 | issue= 3 | date = March 2009 | doi=10.1145/1467247.1467263 | page=48 }}</ref>

<ref name="minksy2008">{{cite journal | last = Minsky | first = Yaron | last2 = Weeks | first2 = Stephen | title = Caml Trading&nbsp;— experiences with functional programming on Wall Street | journal = Journal of Functional Programming | volume = 18 | issue = 4 | pages = 553–564 | publisher = Cambridge University Press | location = |date=July 2008 | url = http://journals.cambridge.org/action/displayAbstract?aid=1899164 | doi = 10.1017/S095679680800676X | accessdate = 2008-08-27 }}</ref>

<ref name="leroy2007">{{cite conference | last = Leroy | first = Xavier | title = Some uses of Caml in Industry | url = http://cufp.galois.com/2007/slides/XavierLeroy.pdf | conference = CUFP 2007 | accessdate = 2009-08-26 }}</ref><ref name="haskell-industry">{{cite web | title = Haskell in industry | work = Haskell Wiki | url = http://www.haskell.org/haskellwiki/Haskell_in_industry | accessdate = 2009-08-26 | quote=Haskell has a diverse range of use commercially, from aerospace and defense, to finance, to web startups, hardware design firms and lawnmower manufacturers. }}</ref>

<ref name="hudak2007">{{cite conference | last = Hudak | first = Paul |author2=Hughes, J. |author3=Jones, S. P. |author4=Wadler, P. | authorlink=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 | accessdate = 2013-09-26 }}</ref>

<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 | accessdate = 2011-06-20 }}</ref><ref name="Chambers">{{cite book | last = Chambers | first = John M. | authorlink=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="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>


}}
}}
[[หมวดหมู่:กระบวนทัศน์การเขียนโปรแกรม]]
[[หมวดหมู่:กระบวนทัศน์การเขียนโปรแกรม]]

รุ่นแก้ไขเมื่อ 19:26, 1 มกราคม 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] ใช้ในโปรแกรมประยุกต์เชิงอุตสาหกรรมและเชิงพาณิชย์โดยองค์กรอย่างกว้างขวาง


อ้างอิง

  1. "Declaration vs. expression style - HaskellWiki".
  2. "Declaration vs. expression style - HaskellWiki".
  3. 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.
  4. Clinger, Will (1987). "MultiTasking and MacScheme". MacTech. 3 (12). สืบค้นเมื่อ 2008-08-28.
  5. Hartheimer, Anne (1987). "Programming a Text Editor in MacScheme+Toolsmith". MacTech. 3 (1). สืบค้นเมื่อ 2008-08-28.
  6. Kidd, Eric. Terrorism Response Training in Scheme. CUFP 2007. สืบค้นเมื่อ 2009-08-26.
  7. Cleis, Richard. Scheme in Space. CUFP 2006. สืบค้นเมื่อ 2009-08-26.
  8. "The useR! 2006 conference schedule includes papers on the commercial use of R". R-project.org. 2006-06-08. สืบค้นเมื่อ 2011-06-20.
  9. Chambers, John M. (1998). Programming with Data: A Guide to the S Language. Springer Verlag. pp. 67–70. ISBN 978-0-387-98503-9.
  10. "Wolfram Language Guide: Functional Programming". 2015. สืบค้นเมื่อ 2015-08-24.
  11. "State-Based Scripting in Uncharted 2" (PDF). คลังข้อมูลเก่าเก็บจากแหล่งเดิม (PDF)เมื่อ 2012-12-15. สืบค้นเมื่อ 2011-08-08.
  12. "Who uses Erlang for product development?". Frequently asked questions about Erlang. สืบค้นเมื่อ 2007-08-05.
  13. Armstrong, Joe (June 2007). A history of Erlang. Third ACM SIGPLAN Conference on History of Programming Languages. San Diego, California. สืบค้นเมื่อ 2009-08-29.
  14. Larson, Jim (March 2009). "Erlang for concurrent programming". Communications of the ACM. 52 (3): 48. doi:10.1145/1467247.1467263.
  15. 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.
  16. Leroy, Xavier. Some uses of Caml in Industry (PDF). CUFP 2007. สืบค้นเมื่อ 2009-08-26.
  17. "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.
  18. 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.
  19. Mansell, Howard (2008). Quantitative Finance in F#. CUFP 2008. สืบค้นเมื่อ 2009-08-29.
  20. Peake, Alex (2009). The First Substantial Line of Business Application in F#. CUFP 2009. สืบค้นเมื่อ 2009-08-29.