पाठ 1 / 25
What Haskell Is and Why Learn It
Describe Haskell's purity, laziness and type system, and where it is used.
Pure, lazy and strongly typed
Haskell is a purely functional programming language designed by an academic committee and first defined in 1990; the Haskell 2010 report is the current standard, and the GHC compiler, with many language extensions, is the de facto implementation. Three ideas define it. Purity: functions always return the same output for the same input and have no hidden side effects; effects such as I/O are tracked in the type system (IO), so a function of type Int -> Int cannot secretly write to a file. Laziness: expressions are evaluated only when their values are needed, enabling infinite data structures and modular code, but requiring care with memory. A powerful static type system with type inference, algebraic data types and type classes, which catches many bugs at compile time and makes refactoring safe. Haskell is used in finance (Standard Chartered, Mercury), blockchain (Cardano), compilers and developer tools (Pandoc, ShellCheck, the Elm and PureScript compilers were written in Haskell), Meta's spam-fighting rules engine (Sigma) and research. Ideas from Haskell, such as Maybe/Option, type classes and monadic composition, have spread to Rust, Scala, Swift, Kotlin and TypeScript.
Haskell's three pillars
Purity, laziness and a strong static type system work together.
A first Haskell program
Type signatures, pure functions and an IO main.
module Main (main) where
-- A pure function: same input, same output, no side effects
square :: Int -> Int
square x = x * x
-- Function application is just a space; no parentheses needed
sumOfSquares :: [Int] -> Int
sumOfSquares xs = sum (map square xs)
-- main is an IO action: the only place effects happen here
main :: IO ()
main = do
putStrLn "Hello, Haskell!"
print (sumOfSquares [1, 2, 3, 4]) -- 30
print (take 5 (map square [1 ..])) -- [1,4,9,16,25] from an infinite list
-- run with: runghc Main.hs or ghc Main.hs && ./MainExpect a different way of thinking
Haskell has no loops, no mutable variables by default and no statements, only expressions. The first weeks feel slow, but the habits it builds (small pure functions, explicit effects, types as design) improve code in every language.
त्वरित जाँच: What does purity mean in Haskell?
- Functions return the same output for the same input and have no hidden side effects
- Functions cannot take arguments
- Programs cannot perform I/O
- All values are strings
Answer
Functions return the same output for the same input and have no hidden side effects — Effects are tracked in types such as IO; ordinary functions are pure.