ภาษาแฮสเคิล

จากวิกิพีเดีย สารานุกรมเสรี
แฮสเคิล (Haskell)
กระบวนทัศน์Purely functional
ผู้ออกแบบLennart Augustsson, Dave Barton, Brian Boutel, Warren Burton, Joseph Fasel, Kevin Hammond, Ralf Hinze, Paul Hudak, John Hughes, Thomas Johnsson, Mark Jones, Simon Peyton Jones, John Launchbury, Erik Meijer, John Peterson, Alastair Reid, Colin Runciman, Philip Wadler
เริ่มเมื่อ1990; 34 ปีที่แล้ว (1990)[1]
รุ่นเสถียร
Haskell 2010[2] / กรกฎาคม 2010; 13 ปีที่แล้ว (2010-07)
รุ่นทดลอง
Haskell 2020 announced[3]
ระบบชนิดตัวแปรInferred, static, strong
ระบบปฏิบัติการCross-platform
นามสกุลของไฟล์.hs, .lhs
เว็บไซต์www.haskell.org
ตัวแปลภาษาหลัก
GHC, Hugs, NHC, JHC, Yhc, UHC
ภาษาย่อย
Helium, Gofer
ได้รับอิทธิพลจาก
Clean,[4] FP,[4] Gofer,[4] Hope and Hope+,[4] Id,[4] ISWIM,[4] KRC,[4] Lisp,[4] Miranda,[4] ML and Standard ML,[4] Orwell, SASL,[4] Scheme,[4] SISAL[4]
ส่งอิทธิพลต่อ
Agda,[5] Bluespec,[6] C++11/Concepts,[7] C#/LINQ,[8][9][10][11] CAL,[ต้องการอ้างอิง] Cayenne,[8] Clean,[8] Clojure,[12] CoffeeScript,[13] Curry,[8] Elm, Epigram,[ต้องการอ้างอิง] Escher,[14] F#,[15] Frege,[16] Hack,[17] Idris,[18] Isabelle,[8] Java/Generics,[8] LiveScript,[19] Mercury,[8] Ωmega,[ต้องการอ้างอิง] PureScript,[20] Python,[8][21] Raku,[22] Rust,[23] Scala,[8][24] Swift,[25] Timber,[26] Visual Basic 9.0[8][9]

ภาษาแฮสเคิล (อังกฤษ: Haskell) /ˈhæskəl/[27] เป็นภาษาโปรแกรมที่มีวัตถุประสงค์เพื่อใช้การใช้งานที่หลากหลาย (general-purpose) ที่มีการไทป์แบบคงที่ (statically typed) ภาษาแฮสเคิลเป็นภาษาโปรแกรมเชิงฟังก์ชั่นแบบบริสุทธ์ (purely functional programming language) ที่มีลักษณะพิเศษคือการคาดคะเนไทป์ (type inference) และการประเมินผลแบบขี้เกียจ (lazy evaluation).[28][29] ภาษาแฮสเคิลพัฒนาขึ้นเพื่อการเรียนการสอน การวิจัย รวมไปถึงการประยุกต์ใช้ในเชิงธุรกิจและอุตสาหกรรม ภาษาแฮสเคิลเป็นแรงบันดาลใจให้กับภาษาโปรแกรมอื่น ๆ ที่มีความซับซ้อนอีกหลายภาษาให้มีฟีเจอร์แบบไทป์คลาส (type classes) ซึ่งทำให้ป้องกันการเออเรอร์ของไทป์ ทำให้การโอเปอเรเตอร์โอเวอร์โหลดดิ้ง (operator overloading) มีความปลอดภัยในการใช้ไทป์ หรือ มีไทป์เซฟตี้ (type-safe) มากขึ้น คอมไพเลอร์หลักสำหรับภาษาแฮสเคิลคือ คอมไพเลอร์กลาสโกลว์แฮสเคิล (Glasgow Haskell Compiler หรือ GHC) ภาษาแฮสเคิลตั้งชื่อตามนักตรรกศาสตร์ชาวอเมริกัน แฮสเคิล เคอร์รี่ (Haskell Curry)[1]

อรรถศาสตร์ (semantics) หรือ คำต่าง ๆ ที่ใช้โค้ดภาษาแฮสเคิลมีต้นกำเนิดทางประวัติศาสตร์จากภาษามิแรนด้า (Miranda) ซึ่งเป็นภาษาที่กลุ่มนักวิทยาศาสตร์คอมพิวเตอร์ที่ร่วมกันสร้างภาษาแฮสเคิลใช้ในการต่อยอด[30] การกำหนดคุณลักษณะอย่างเป็นทางการสำหรับภาษาแฮสเคิลครั้งสุดท้ายมีขึ้นในเดือนกรกฎาคม ค.ศ.2010 (พ.ศ.2553) ส่วนการพัฒนาคอมไพเลอร์ GHC นั้นมีการปรับปรุงและพัฒนาอยู่เรื่อยมาและทำการขยายศักยภาพของภาษาแฮสเคิลขึ้นไปเรื่อย ๆ

โลโก้ภาษาแฮสเคิล

มีการใช้ภาษาแฮสเคิลในการวิจัยเชิงวิชาการ[31][32] และภาคธุรกิจอุตสาหกรรมต่าง ๆ[33][34] ในเดือนกันยายน ค.ศ.2020 (พ.ศ.2563) แฮสเคิลเป็นภาษาที่ได้รับความนิยมในการค้นใน Google เป็นอันดับที่ 28[35] ในส่วนของผู้ใช้ที่ยังแอคทีฟอยู่บนแพลตฟอร์ม GitHub ในส่วนของ source code repository มี source code ภาษาแฮสเคิลเพียง 1% เท่านั้น

ตัวอย่างโค้ด[แก้]

การเขียนโปรแกรม "Hello, World!" program ใน Haskell (only the last line is strictly necessary):

module Main (main) where          -- not needed in interpreter, is the default in a module file

main :: IO ()                     -- the compiler can infer this type definition
main = putStrLn "Hello, World!"

การเขียนฟังก์ชั่นแฟกทอเรียล (factorial) ในแฮสเคิลสามารถเขียนได้หลายแบบ:

-- Type annotation (optional, same for each implementation)
factorial :: (Integral a) => a -> a

-- Using recursion (with the "ifthenelse" expression)
factorial n = if n < 2
              then 1
              else n * factorial (n - 1)

-- Using recursion (with pattern matching)
factorial 0 = 1
factorial n = n * factorial (n - 1)

-- Using recursion (with guards)
factorial n
   | n < 2     = 1
   | otherwise = n * factorial (n - 1)

-- Using a list and the "product" function
factorial n = product [1..n]

-- Using fold (implements "product")
factorial n = foldl (*) 1 [1..n]

-- Point-free style
factorial = foldr (*) 1 . enumFromTo 1

อ้างอิง[แก้]

  1. 1.0 1.1 Hudak et al. 2007.
  2. Marlow, Simon (24 November 2009). "Announcing Haskell 2010". Haskell (Mailing list). สืบค้นเมื่อ 12 March 2011.
  3. Riedel, Herbert (28 April 2016). "ANN: Haskell Prime 2020 committee has formed". Haskell-prime (Mailing list). สืบค้นเมื่อ 6 May 2017.
  4. 4.00 4.01 4.02 4.03 4.04 4.05 4.06 4.07 4.08 4.09 4.10 4.11 4.12 Peyton Jones 2003, p. xi
  5. Norell, Ulf (2008). "Dependently Typed Programming in Agda" (PDF). Gothenburg: Chalmers University. สืบค้นเมื่อ 9 February 2012.
  6. Hudak et al. 2007, pp. 12–38, 43.
  7. Stroustrup, Bjarne; Sutton, Andrew (2011). "Design of Concept Libraries for C++" (PDF). คลังข้อมูลเก่าเก็บจากแหล่งเดิม (PDF)เมื่อ 10 February 2012. {{cite journal}}: Cite journal ต้องการ |journal= (help)
  8. 8.00 8.01 8.02 8.03 8.04 8.05 8.06 8.07 8.08 8.09 Hudak et al. 2007, pp. 12-45–46.
  9. 9.0 9.1 Meijer, Erik (2006). "Confessions of a Used Programming Language Salesman: Getting the Masses Hooked on Haskell". Oopsla 2007. CiteSeerX 10.1.1.72.868.
  10. Meijer, Erik (1 October 2009). "C9 Lectures: Dr. Erik Meijer – Functional Programming Fundamentals, Chapter 1 of 13". Channel 9. Microsoft. คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2012-06-16. สืบค้นเมื่อ 9 February 2012.
  11. Drobi, Sadek (4 March 2009). "Erik Meijer on LINQ". InfoQ. QCon SF 2008: C4Media Inc. สืบค้นเมื่อ 9 February 2012.{{cite news}}: CS1 maint: location (ลิงก์)
  12. Hickey, Rich. "Clojure Bookshelf". Listmania!. คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 3 October 2017. สืบค้นเมื่อ 3 October 2017.
  13. Heller, Martin (18 ตุลาคม 2011). "Turn up your nose at Dart and smell the CoffeeScript". InfoWorld. สืบค้นเมื่อ 2020-07-15.
  14. "Declarative programming in Escher" (PDF). สืบค้นเมื่อ 7 October 2015.
  15. Syme, Don; Granicz, Adam; Cisternino, Antonio (2007). Expert F#. Apress. p. 2. F# also draws from Haskell particularly with regard to two advanced language features called sequence expressions and workflows.
  16. Wechsung, Ingo. "The Frege Programming Language" (PDF). สืบค้นเมื่อ 26 February 2014.
  17. "Facebook Introduces 'Hack,' the Programming Language of the Future". WIRED. 20 March 2014.
  18. "Idris, a dependently typed language". คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2021-05-11. สืบค้นเมื่อ 26 October 2014.
  19. "LiveScript Inspiration". สืบค้นเมื่อ 4 February 2014.
  20. Freeman, Phil (2016). "PureScript by Example". Leanpub. สืบค้นเมื่อ 23 April 2017.
  21. Kuchling, A. M. "Functional Programming HOWTO". Python v2.7.2 documentation. Python Software Foundation. สืบค้นเมื่อ 9 February 2012.
  22. "Glossary of Terms and Jargon". Perl Foundation Perl 6 Wiki. The Perl Foundation. คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 21 January 2012. สืบค้นเมื่อ 9 February 2012.
  23. "The Rust Reference: Appendix: Influences". สืบค้นเมื่อ 3 February 2016.
  24. Fogus, Michael (6 August 2010). "MartinOdersky take(5) toList". Send More Paramedics. สืบค้นเมื่อ 9 February 2012.
  25. Lattner, Chris (3 June 2014). "Chris Lattner's Homepage". Chris Lattner. สืบค้นเมื่อ 3 June 2014. The Swift language is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list.
  26. "Timber/History". คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2020-10-31. สืบค้นเมื่อ 7 October 2015.
  27. Chevalier, Tim (28 January 2008). "anybody can tell me the pronunciation of "haskell"?". Haskell-cafe (Mailing list). สืบค้นเมื่อ 12 March 2011.
  28. Type inference originally using Hindley-Milner type inference
  29. Peyton Jones 2003.
  30. Edward Kmett, Edward Kmett – Type Classes vs. the World
  31. "Haskell in education". สืบค้นเมื่อ 15 February 2016.
  32. "Haskell in research". สืบค้นเมื่อ 15 February 2016.
  33. Mossberg, Erik (2020-06-08), erkmos/haskell-companies, สืบค้นเมื่อ 2020-06-22
  34. "Haskell in industry - HaskellWiki". wiki.haskell.org. สืบค้นเมื่อ 2020-06-22.
  35. "PYPL PopularitY of Programming Language index". pypl.github.io (ภาษาอังกฤษ). 22 January 2021. คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 17 September 2020. สืบค้นเมื่อ 22 January 2021.