Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tastywheat/34d0e2d04fbb2f29d5cf to your computer and use it in GitHub Desktop.

Select an option

Save tastywheat/34d0e2d04fbb2f29d5cf to your computer and use it in GitHub Desktop.
What makes functional programming languages declarative as opposed to Imperative?
# http://programmers.stackexchange.com/questions/283989/what-makes-functional-programming-languages-declarative-as-opposed-to-imperative
```
The basic unit of an imperative program is the statement. Statements are executed for their side effects.
They modify the state they receive. A sequence of statements is a sequence of commands, denoting do this then do that.
The programmer specifies the exact order to perform the computation. This is what people mean by telling the computer
how to do it.
The basic unit of a declarative program is the expression. Expressions do not have side effects. They specify
a relationship between an input and output, creating a new and separate output from their input, rather than
modifying their input state. A sequence of expressions is meaningless without some containing expression specifying
the relationship between them. The programmer specifies the relationships between data, and the program infers
the order to perform the computation from those relationships. This is what people mean by telling the computer what to do.
Imperative languages have expressions, but their primary means of getting things done is statements. Likewise,
declarative languages have some expressions with semantics similar to statements, like monad sequences inside
Haskell's do notation, but at their core, they are one big expression. This lets beginners write code that is
very imperative-looking, but the true power of the language comes when you escape that paradigm.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment