Fish TouchingšŸŸšŸŽ£

Functional Programming

Jul 28, 2023

# Functional

Programming in a functional style often includes using functions as values by passing them in arguments, returning them from other functions, assigning them to variables for later execution, and so forth.
Adapting to that perspective requires letting go of old ideas: assignment statements, loops, classes and objects, among others. That won’t be easy.

A function maps an input to an output; for the same input, it always produces the same output. That is, mathematical functions areĀ stateless: they do not maintain any extra information orĀ stateĀ that persists between usages of the function.
Functions areĀ first-class: you can use them as input to other functions, and produce functions as output. Expressing everything in terms of functions enables a uniform and simple programming model that is easier to reason about than the procedures and methods found in other families of languages.

# Properties

# Example

let rec fast_fib n =
  let rec helper i pp p = 
    if i = 0 then pp
    else helper (i - 1) (pp + p) p
  in
  if n = 0 then 0 
  else helper n 0 1