Haskell
Haskell /ˈhæskəl/[3] is a purely functional programming language. It is named after Haskell Brooks Curry, a U.S. mathematician who contributed a lot to logic. Haskell is based on lambda calculus and uses the Greek letter lambda as its logo. The main implementations are the Glasgow Haskell Compiler (GHC), and Hugs, a Haskell interpreter.
| Paradigm(s) | functional, lazy/non-strict, modular |
|---|---|
| Appeared in | 1990 |
| Designed by | Simon Peyton Jones, Lennart Augustsson, Dave Barton, Brian Boutel, Warren Burton, Joseph Fasel, Kevin Hammond, Ralf Hinze, Paul Hudak, John Hughes, Thomas Johnsson, Mark Jones, John Launchbury, Erik Meijer, John Peterson, Alastair Reid, Colin Runciman, Philip Wadler |
| Stable release | Haskell 2010[1] / July 2010 |
| Preview release | Announced as Haskell 2014[2] |
| Typing discipline | static, strong, inferred |
| Major implementations | GHC, Hugs, NHC, JHC, Yhc, UHC |
| Dialects | Helium, Gofer |
| OS | Cross-platform |
| Usual filename extensions | .hs, .lhs |
| Website | haskell |
Examples
The following is an example Hello World program in Haskell: <syntaxhighlight lang="haskell"> module Main where
main :: IO () main = putStrLn "Hello, World!" </syntaxhighlight>
One way to create an infinite list of Fibonacci numbers is this:[4] <syntaxhighlight lang="haskell"> fib n = fibs !! n
where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
</syntaxhighlight>
Concept
The language is similar to traditional mathematics, in which all variables are pure, meaning they cannot change during the program's runtime. All equations must remain true in principle. For any impure actions, there is the IO monad, which itself is pure, but creates side effects when ran.[5]
Functions are treated like normal values, meaning they can be applied to other functions. 2+ argument functions are fundamentally a one argument function, a function that takes in some input and returns a function in the process of partial application. Traditional variables are treated like zero argument functions.
The order of variable declarations within the file does not matter, allowing for mutual recursion, where variables are defined in terms of each other.
Features
Data Types
| Data Type | Purpose |
|---|---|
| Integer | A signed integer using arbitrary precision arithmetic, meaning the number can be as large as possible |
| Char | Short for "character". Any character stored in Unicode. |
| String | A list of characters. |
| Boolean | See boolean. |
| [a] | List data type, stored as a linked list. |
| a -> b | Function between data types a and b. |
| Double and Float | Floating point numbers, commonly used for decimals due to its efficiency. |
Type Classes
A type class is a descriptor of a data type. These are used to make functions more general. For example, the addition operator has a type signature of<syntaxhighlight lang="haskell"> (+) :: Num a => a -> a -> a </syntaxhighlight>This statement translates to "given some data type that is a number, you can add two variables of that type to create a new one".[6]
| Type Class | Description | Example Functions | Example Data Types |
|---|---|---|---|
| Eq a | Ensures a data type (in this case, a) can be equated | (==): Checks equality between two variables of the same data type | Integer, String |
| Ord a | Places order between variables of a data type | (>) & (<): Compares two variables of the same data type | Integer, Char |
| Num a | Allows for basic mathematical operators between variables of this data type | (+), (-), (*) | Integer, Float, Double |
Lazy Evaluation
Lazy evaluation is where expressions aren't evaluated immediately, sometimes never evaluated. This allows for infinitely long lists, and avoids unnecessary calculations.[7]
Influence
Haskell was influenced by many earlier programming languages. These were Clean, FP, Gofer, Hope and Hope+, Id, ISWIM, KRC, Lisp, Miranda, ML and Standard ML, Orwell, SASL, SISAL, and Scheme.[8]
Haskell itself has influenced many later programming languages, such as Agda,[9] Bluespec,[10] C++11/Concepts,[11] C#/LINQ,[12][13][14][15] Cayenne,[12] Clean,[12] Clojure,[16] CoffeeScript,[17] Curry,[12] F#,[18] Isabelle,[12] Java/Generics,[12] Mercury,[12] Perl 6,[19] Python,[12][20] Scala,[12][21] Visual Basic 9.0.[12][13]
Haskell Media
Hierarchy of type classes in the Haskell prelude as of GHC 7.10.The inclusion of Foldable and Traversable (with corresponding changes to the type signatures of some functions), and of Applicative as intermediate between Functor and Monad, are deviations from the Haskell 2010 standard.
References
- ↑ Marlow, Simon. Announcing Haskell 2010. Haskell mailing list (24 November 2009). Retrieved 12 March 2011.
- ↑ Lynagh, Ian. Haskell 2014. Haskell-prime mailing list (1 May 2013). Retrieved 9 October 2013.
- ↑ Chevalier, Tim. anybody can tell me the pronuncation of "haskell"?. Haskell-cafe mailing list (28 January 2008). Retrieved 12 March 2011.
- ↑ The Fibonacci sequence. HaskellWiki (2 August 2012). Retrieved 27 March 2013.
- ↑ 08-IO. www.cis.upenn.edu. Retrieved 2025-05-28.
- ↑ 05-type-classes. www.cis.upenn.edu. Retrieved 2025-05-28.
- ↑ 06-laziness. www.cis.upenn.edu. Retrieved 2025-05-28.
- ↑ Haskell 98 Language and Libraries: The Revised Report (2003)Cambridge University Press. p. xi. ISBN 0521826144.
- ↑ Norell, Ulf. Dependently Typed Programming in Agda (2008). Gothenburg: Chalmers University. Retrieved 9 February 2012.
- ↑ Hudak and others 2007, p. 12-38,43.
- ↑ Stroustrup, Bjarne. Design of Concept Libraries for C++ (2011). Retrieved 2013-11-01.
- ↑ 12.0 12.1 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.9 Hudak and others 2007, pp. 12-45–46.
- ↑ 13.0 13.1 Meijer, Erik. Confessions of a Used Programming Language Salesman: Getting the Masses Hooked on Haskell. Oopsla 2007.
- ↑ Meijer, Erik. C9 Lectures: Dr. Erik Meijer – Functional Programming Fundamentals, Chapter 1 of 13. Channel 9 (1 October 2009)Microsoft. Retrieved 9 February 2012.
- ↑ Drobi, Sadek (4 March 2009). "Erik Meijer on LINQ". InfoQ (San Francisco: C4Media Inc.). http://www.infoq.com/interviews/LINQ-Erik-Meijer. Retrieved 9 February 2012.
- ↑ Hickey, Rich. Clojure Bookshelf. Listmania!Amazon.com. Retrieved 9 February 2012.
- ↑ Heller, Martin (18 October 2011). "Turn up your nose at Dart and smell the CoffeeScript". JavaWorld (InfoWorld). http://www.javaworld.com/javaworld/jw-10-2011/111018-coffeescript-vs-dart.html. Retrieved 9 February 2012.
- ↑ Syme, Don. Expert F# (2007)Apress. p. 2.
- ↑ Glossary of Terms and Jargon. Perl Foundation Perl 6 WikiThe Perl Foundation. Retrieved 9 February 2012.
- ↑ Kuchling, A. M.. Functional Programming HOWTO. Python v2.7.2 documentationPython Software Foundation. Retrieved 9 February 2012.
- ↑ Fogus, Michael. MartinOdersky take(5) toList. Send More Paramedics (6 August 2010). Retrieved 9 February 2012.