What is a functional programming language? How is it different from imperative languages?
user
A functional programming language is a programming language that adheres to the functional programming paradigm. This paradigm of programming emphasizes the use of pure functions in the mathematical sense, use of first-class functions, declarative over imperative code, and often (though not always) more complex type systems. Where imperative programming languages usually prefer writing code in a step-by-step manner, functional languages promote the composition of functions to accomplish tasks. The factorial function is perhaps most illustrative of this:
Functional programming implementation of factorial (Haskell)
---
```haskell
factorial 0 = 1
factorial n = n * factorial (n - 1)
```
Imperative programming implementation of factorial (Python)
---
```python
def factorial(n):
    result = 1
    if n > 1:
        for i in range(1, n+1):
            result = result * i
        return result
```

(Note that neither of these examples will handle negative numbers.)
It is important to note that while examples of functional programming may be easier to read, they may also be slower to run. It is often the case that in order to match the performance of an imperative solution, a functional approach must compromise considerably on readability.
assistant
Interesting, but can you rephrase it a bit simpler so i can easily explain it to my friends?
user
Functional programming languages are like math notation, while imperative ones are like cooking recipes. The latter might be easier to conceptualize at first, but the former provide useful features for writing safer and more advanced code.
assistant