Contents 1 History 1.1 Haskell 1.0 to 1.4 1.2 Haskell 98 1.3 Haskell 2010 2 Features 3 Code examples 4 Implementations 5 Applications 5.1 Industry 5.2 Web 6 Criticism 7 Related languages 8 Conferences and workshops 9 Haskell Base library and algebra 10 Notes 11 References 12 Further reading 13 External links

Code examples See also: Haskell features § Examples A "Hello world" program in Haskell:[a] module Main where main :: IO () main = putStrLn "Hello, World!" The factorial function in Haskell, defined in a few different ways (the type annotation is optional): -- 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 An efficient implementation of the Fibonacci numbers as an infinite list: -- Type annotation (optional, same for each implementation) fib :: Int -> Integer -- With self-referencing data fib n = fibs !! n where fibs = 0 : scanl (+) 1 fibs -- 0,1,1,2,3,5,... -- Same, coded directly fib n = fibs !! n where fibs = 0 : 1 : next fibs next (a : t@(b:_)) = (a+b) : next t -- Similar idea, using zipWith fib n = fibs !! n where fibs = 0 : 1 : zipWith (+) fibs (tail fibs) -- Using a generator function fib n = fibs (0,1) !! n where fibs (a,b) = a : fibs (b,a+b) The Int type refers to a machine-sized integer (used as a list subscript with the !! operator), while Integer is an arbitrary-precision integer. For example, using Integer, the factorial code above easily computes factorial 100000 as a number of 456,574 digits, with no loss of precision. An implementation of an algorithm similar to quick sort over lists, where the first element is taken as the pivot: -- Type annotation (optional, same for each implementation) quickSort :: Ord a => [a] -> [a] -- Using list comprehensions quickSort [] = [] -- The empty list is already sorted quickSort (x:xs) = quickSort [a | a <- xs, a < x] -- Sort the left part of the list ++ [x] ++ -- Insert pivot between two sorted parts quickSort [a | a <- xs, a >= x] -- Sort the right part of the list -- Using filter quickSort [] = [] quickSort (x:xs) = quickSort (filter (<x) xs) ++ [x] ++ quickSort (filter (>=x) xs)

Conferences and workshops The Haskell community meets regularly for research and development activities. The main events are: International Conference on Functional Programming (ICFP) Haskell Symposium (formerly the Haskell Workshop) Haskell Implementors Workshop Commercial Users of Functional Programming (CUFP) Since 2006, a series of organized hackathons has occurred, the Hac series, aimed at improving the programming language tools and libraries.[79]

Haskell Base library and algebra As Haskell separates domains (types) and behaviour (type classes) you may find correspondences with the algebra world that underlies the standard typeclasses of the Haskell basic library. The Num class has the operation signatures required for a Ring, except for the (+) and (*) neutral elements, which are predefined as literals.[80] Operation laws like (+) and (*) associativity and addition commutativity are not related with the typeclass, but rather proofs to be checked on the instances. \$ ghci Prelude> :type 0 0 :: Num a => a -- 0 belongs to any type that has a Num instance, a Ring Prelude> :type 1 1 :: Num a => a -- neutral for the product of a type that implements Num The Word data types (Word, WordN) implement the Num type class with modular arithmetic whereas the data types Int and IntN use two's complement arithmetic that does not match the decimal arithmetic (see Integer overflow):[discuss] Prelude> (signum maxBound ::Int) == signum (maxBound +1) False -- ??? maxBound successor doesn't obey arithmetic rule (it doesn't throw exceptions) Prelude> (signum maxBound ::Int) == signum (maxBound *2) False -- ??? Int product overflow (no exceptions either) Prelude> (-minBound ::Int) /= minBound -- where Int minBound == sign bit set followed by zeros False -- ??? Negate overflow Possible workarounds to make it match with regular arithmetic, throwing an exception on overflow, are to check the addition result for same signum {-1,0,1} with the operands when operand signs match;[81][82] or to perform the operation with unlimited precision, checking the typecasted result.[82] The Fractional type class adds to Num the multiplicative inverse in the recip function (for "reciprocal") and, as a consequence, the division. It corresponds to a Field.[83] The Real type class requires Num and Ord, corresponds to an Ordered ring,[84] which serves to Integer numbers, Rational[85] and Floating point numbers.[86] The Integral type class adds operations for Euclidean division to the required Real and Enum classes, corresponding to a Euclidean ring, which is an integral ring.[87] The Floating type class adds to Fractional the calculus functions (sqrt, trigonometric functions, logarithms) common to floating point (Float, Double) and complex numbers.[88][86][89] Exponentiation comes in three flavours: A positive integer exponent requires that the base domain has the product (specified in Num, signature of a ring): (^) :: (Num a, Integral ex) => a -> ex -> a -- (^) admits non-negative exponents of an euclidean domain, throws an error if the exponent is negative A negative integer exponent requires that the base domain has the multiplicative inverse (specified in Fractional, signature of a field): (^^) :: (Fractional a, Integral ex) => a -> ex -> a -- (^^) admits all exponents of an euclidean domain A floating point exponent requires that the base domain has the floating point exponentiation and logarithm functions, as specified in the Floating type class:[88] (**) :: (Floating a, Floating ex) => a -> ex -> a Conversions between Euclidean types preserve the representation, not the value. Numeric type downcasting does not throw an overflow exception: \$ ghci Prelude> import Data.Int Prelude Data.Int> fromIntegral (32767 :: Int16) :: Int8 -1 Prelude Data.Int> fromInteger (2^64 :: Integer) :: Int32 0

Notes ^ 'Hello world' is meant as the introductory prototype of a read-eval-print loop. The IO tool putStrLn prints a string, which is the only essential line of this example. The second line of this example is a type definition, which is unnecessary for Haskell, because the compiler infers the type; instead, the second line serves to communicate the programmer's intention to the reader. The first line of the example isn't needed, either, because the start symbol main in this simple example makes the module Main a nicety, which instead would have been a necessity in a multi-module example. Rather, the first two lines are provided for consistency with larger examples.