Functionnal programming in Scala

2nd of January, 2020 in notes

Functionnal programming in Scala

  1. What is functional programming
    1. Referentiel transparency
    2. Substitution model
    3. Benefits
  2. Scala
    1. Functional loop (without mutated variable)
      1. Tail call elimination
      2. Polymorphic functions
  3. Functionnal data structures
    1. Functional structure
    2. LinkedList
    3. PatternMatching
  4. Sources

What is functional programming

Referentiel transparency

An expression e is referentially transparent if, for all programs p, all occurrences of e in p can be replaced by the result of evaluating e without affecting the meaning of p.

A function f is pure if the expression f(x) is referentially transparent for all referentially transparent x.

Substitution model

Consists in replacing all variables with their referents and reduce the function to its simplest form.

Benefits

Scala

Functional loop (without mutated variable)

Recursive loop.

Tail call elimination

A call is said to be in tail position if the caller does nothing other than return the value of the recursive call.

Polymorphic functions

Abtsracting over types

Functionnal data structures

Functional structure

Operated on using only pure functions. Immutable. End up with extra copies of data => no !

LinkedList

PatternMatching

Sources

Graphic logo for Visual Studio Code software from en.wikipedia.org/wiki/Visual_Studio_Code#/media/File:Visual_Studio_Code_1.18_icon.svg