Haskell
In short
Haskell is a purely functional, statically typed language with lazy evaluation, known for its expressive type system and mathematically precise code.
What is Haskell?
Haskell is a general-purpose, purely functional programming language designed by a committee of researchers and first defined in 1990. It is named after the logician Haskell Curry. The language is standardized in the Haskell 2010 report, while in practice nearly all code targets the Glasgow Haskell Compiler (GHC), which adds many optional language extensions.
In Haskell, functions are pure by default: a function can't change variables or perform input and output unless its type says so, using the IO type. It uses lazy evaluation, meaning expressions are computed only when their values are actually needed, which allows elegant tricks like working with infinite lists. Its static type system infers most types automatically and uses type classes, such as Eq and Show, to describe behavior shared across types, similar to interfaces in other languages.
Haskell is used in compilers and programming language research, financial systems, static analysis tools and backend services where correctness matters. Many ideas now common in mainstream languages, such as type inference, pattern matching, algebraic data types and Option-style types for missing values, were refined in Haskell and its relatives. Writing Haskell is often compared to writing mathematical definitions: you describe what a value is, and the compiler checks that the pieces fit together.
Haskell is often compared with F# and OCaml, which are also statically typed functional languages with strong type inference. The key difference is that F# and OCaml evaluate expressions eagerly and allow side effects anywhere, while Haskell is lazy by default and tracks side effects in the type system, which makes it stricter and more distinctive to learn.
Key takeaways
- Haskell is purely functional: side effects are tracked in the type system through types like
IO. - It uses lazy evaluation, computing values only when they are needed.
- Its static type system infers most types and uses type classes for shared behavior.
- GHC is the compiler used for nearly all Haskell code.
- Many modern language features were refined in Haskell and its relatives.
Example
-- A type signature: takes a list of Ints, returns an Int
sumOfSquares :: [Int] -> Int
sumOfSquares xs = sum (map (^ 2) xs)
-- Lazy evaluation: an infinite list, only the needed part is computed
evens :: [Int]
evens = [0, 2 ..]
main :: IO ()
main = do
print (sumOfSquares [1, 2, 3]) -- 14
print (take 5 evens) -- [0,2,4,6,8]Readers ask
Why is Haskell called purely functional?
Because ordinary Haskell functions cannot have side effects. Actions like reading files or printing text are values of type IO that the runtime executes, so a function's type tells you whether it can affect the outside world.
Is Haskell used in industry?
Yes, though it's a niche choice. Companies use it for financial systems, compilers, developer tooling and backend services where strong correctness guarantees are worth the learning curve.
What is a monad in Haskell?
A monad is a pattern for chaining computations that carry extra context, such as possible failure (Maybe), multiple results (lists) or input and output (IO). Haskell's do notation is syntax for writing those chained steps in a readable, sequential style.
See also
- Functional ProgrammingProgramming Fundamentals, p. 22Functional programming is a style of building software from pure functions that avoid changing shared data, making code more predictable and easier to test.
- Pure FunctionProgramming Fundamentals, p. 47A pure function always returns the same output for the same input and has no side effects, meaning it does not change anything outside itself.
- Type InferenceProgramming Fundamentals, p. 55Type inference is a compiler feature that works out the type of a variable or expression automatically, so you don't have to write every type annotation.
- ImmutabilityProgramming Fundamentals, p. 27Immutability means a value cannot be changed after it is created, so every update produces a new value instead of modifying the original in place.
- F#Programming Languages, p. 11F# is a functional-first, statically typed language for .NET that pairs concise, type-inferred code with full access to the .NET ecosystem and C# libraries.
- GenericsProgramming Fundamentals, p. 24Generics are a language feature that lets you write functions, classes, and types that work with many data types while still keeping full type safety.
Spotted a mistake or something missing on this page?Suggest an edit