Search code examples
haskellfunctional-programmingimperative-programmingdeclarative-programming

Is Haskell an imperative or declarative paradigm?


I have read some sources where the Haskell's paradigm is described as functional but imperative paradigm. The main source where this is said is Wikipedia. How is possible a functional and imperative paradigm at the same time, or is this a mistake?


Solution

  • Functional languages generally use a declarative methodology when describing their programs, and Haskell is definitely one of these languages; Haskell programs are described as a set of declarations of values (including functions, because functions are first class values).

    However, in order for a computer to execute a program, it has to follow a sequence of instructions. To that end, Haskell has a way you can describe what can end up as sequencing when it's executed, in a special syntax (called "do syntax"). Each line of this syntax looks like the next "statement" in a normal imperative language, and kind of behaves that way, too. Really, though, it's just syntactic sugar for ordinary Haskell expressions of function application.

    Because it's still written in Haskell, though, and Haskell values and expressions are for the most part typesafe, Haskell is often called "the best imperative language".