Functional programming Created 2026-10-13 Updated 2026-11-05
Functional programming emphasizes computation by evaluating and composing functions, often using immutable data and expression-based definitions. A pure function has no observable side effects and returns the same result for the same inputs, allowing substitution of equals for equals. Mapping a square function over a list illustrates a direct transformation without an externally updated accumulator. Higher-order functions accept or return functions, making patterns such as mapping and folding reusable. Functional languages differ in strictness and effect handling; the paradigm does not imply that real programs never perform input or output.
Haskell concatMap function 2026-10-31
The higher-order function with type
(a -> [b]) -> [a] -> [b] and value concat (map f xs). It replaces each input element by a list and concatenates those lists in input order. A direct definition is concatMap f = foldr (\x rest -> f x ++ rest) []. This formulation processes an input element's produced list once; it need not repeatedly append an already accumulated output prefix. Haskell iterate function 2026-10-31
The higher-order function
iterate :: (a -> a) -> a -> [a], satisfying iterate f x = x : iterate f (f x). Its result begins with the initial value and continues with successive applications. Lazy evaluation permits finite prefixes of this infinite list to be observed whenever the necessary applications terminate. Haskell takeWhile function 2026-10-31
The higher-order function
takeWhile :: (a -> Bool) -> [a] -> [a] retains the longest initial segment whose elements all satisfy its predicate. It stops at the first failure and does not resume later. Thus it differs from a list filter, which tests later elements as well.