Haskell

Haskell
Paradigmfunctional, lazy/non-strict, modular
Designed bySimon 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
First appeared1990; 36 years ago (1990)
Stable releaseHaskell 2010 / July 2010; 16 years ago (2010-07)
Preview releaseAnnounced as Haskell 2014
Typing disciplinestatic, strong, inferred
OSCross-platform
Filename extensions.hs, .lhs
Websitehaskell.org
Major implementations
GHC, Hugs, NHC, JHC, Yhc, UHC
Dialects
Helium, Gofer

Haskell /ˈhæskəl/ 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.

Examples

The following is an example Hello World program in Haskell:

module Main where

main :: IO ()
main = putStrLn "Hello, World!"

One way to create an infinite list of Fibonacci numbers is this:

fib n = fibs !! n
        where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

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.

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 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

(+) :: Num a => a -> a -> a

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".

Type Classes
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.

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.

Haskell itself has influenced many later programming languages, such as Agda, Bluespec, C++11/Concepts, C#/LINQ, Cayenne, Clean, Clojure, CoffeeScript, Curry, F#, Isabelle, Java/Generics, Mercury, Perl 6, Python, Scala, Visual Basic 9.0.