Introduction to Haskell
"I know why you're here. ...why you hardly sleep, why night after night, you sit by your computer."
Features of Haskell
- Purely functional
- Statical typed
- Lazy
1. Purely functional
- Every input has a corresponding output
- f(x) = x² + 1
-
Powerful function compositions
g(x) = x - 1
g(f(x)) = x²
-
PURE
That means no side effects
A function will never modify a global variable
Order doesn't matter!
Easy concurrency
Functional:
Haskell, Lisp, ML, Scheme, Erlang
Focuses on the high-level "what"
Imperative:
C++, Java, Python, Pascal
Focuses on the low-level "how"
2. Statically Typed
- f x = x² + 1
- f :: Int → Int
- There is never confusion about types
(Bool, Int, Char, etc)
- Strong formalism. The proof is the code.
- If your code compiles, you're 99% done
3. Lazy?
- Nothing is evaluated unless necessary
The list will only be sorted enough to find the minimum
- Allows infinite data structures