Haskell

purely functional programming language From Wikipedia, the free encyclopedia

Remove ads

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.

Quick Facts Paradigm, Designed by ...
Remove ads

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:[4]

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

Remove ads

Features

Data Types

More information Data Type, Purpose ...

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".[6]

More information Type Class, Description ...

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]

Remove ads

References

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads