Motivation: “lambda calculus” → any computable problem can be solved by composing one or more “pure” functions.
Every functions must take an argument and every function must return a value. Functions are considered “pure” and have no side effects.(i.e. no variables would be changed ) so functions with the same input would always produce the same output.
All variables in functional programming language are immutable, and functions can be stored in variables and passed as arguments.
<aside> 💡 Pure Function Definition A function that has two properties:
</aside>
Compare to imperative programming, multi-threading is easy and the order of execution is less important.
Since functions have no side effects, lazy evaluation is used — a variable is only calculated when it need to be used
square x = x*x
hypot a b = sqrt(square a + square b)
First rule first, Haskell uses indentation like python. It is a statically typed language, and it uses type inference to figure out the type we are writing.
And if we don’t want to use the type inference and do explicit types
nerds = 150::Int
:t nerd --gives out the type
nerds / 10 -- ERROR. Division does not support integers
nerds `div` 10 -- this would work
nerds + (-1) -- Unary operator needs to be enclosed by a bracket