Embed presentation
Download to read offline

![FUNCTION[-A, +B]
f: A => B
g: B => C
F[+A] : if A’ <: A then F[‘A] <: F[A]
A’ <: A => if a: A’ then a:A
A
A’
F[- A] : if A’ <: A then F[A] <: F[A’]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-2-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
F[+A] : if A’ <: A then F[‘A] <: F[A]
A’ <: A => if a: A’ then a:A
A
A’
F[- A] : if A’ <: A then F[A] <: F[A’]
‘T
T](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-3-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g
Liskov Principle: Expr[T], T’ < T => Expr[T’]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-4-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g
Liskov Principle: Expr[T], T’ < T => Expr[T’]
f’ < f; f’ |> g](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-5-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g
Liskov Principle: Expr[T], T’ < T => Expr[T’]
f’ < f; f’ |> g f’ : A’ => B’](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-6-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f’ g
f’ < f; f’ |> g f’ : A => B’ Let B’ :> B
Problem: g is not defined on B’ - B](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-7-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f’ g
f’ < f; f’ |> g f’ : A => B’ Let B’ :< B
Function[.. , +B]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-8-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g’
g’ < g; f |> g’ g’ : B’ => C Let B’ :< B
Function[.. , +B]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-9-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g’
g’ < g; f |> g’ g’ : B’ => C Let B’ :< B
Problem: g’ is not defined on B - B’](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-10-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g’
g’ < g; f |> g’ g’ : B’ => C Let B’ :> B
Function[-A , +B]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-11-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g’
Function[-A , +B] :
application of Liskov substitution principle
// Barbara Liskov, CLU Language ~ 1974](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-12-2048.jpg)


The document discusses functions and the Liskov substitution principle. It defines functions with signatures like f: A => B, meaning a function f that takes an input of type A and returns an output of type B. It explains function composition using andThen and |>. It also discusses how the Liskov substitution principle states that if S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any desirable properties of that program. This allows subclasses to substitute behavior while preserving contracts with external consumers.

![FUNCTION[-A, +B]
f: A => B
g: B => C
F[+A] : if A’ <: A then F[‘A] <: F[A]
A’ <: A => if a: A’ then a:A
A
A’
F[- A] : if A’ <: A then F[A] <: F[A’]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-2-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
F[+A] : if A’ <: A then F[‘A] <: F[A]
A’ <: A => if a: A’ then a:A
A
A’
F[- A] : if A’ <: A then F[A] <: F[A’]
‘T
T](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-3-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g
Liskov Principle: Expr[T], T’ < T => Expr[T’]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-4-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g
Liskov Principle: Expr[T], T’ < T => Expr[T’]
f’ < f; f’ |> g](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-5-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g
Liskov Principle: Expr[T], T’ < T => Expr[T’]
f’ < f; f’ |> g f’ : A’ => B’](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-6-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f’ g
f’ < f; f’ |> g f’ : A => B’ Let B’ :> B
Problem: g is not defined on B’ - B](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-7-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f’ g
f’ < f; f’ |> g f’ : A => B’ Let B’ :< B
Function[.. , +B]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-8-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g’
g’ < g; f |> g’ g’ : B’ => C Let B’ :< B
Function[.. , +B]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-9-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g’
g’ < g; f |> g’ g’ : B’ => C Let B’ :< B
Problem: g’ is not defined on B - B’](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-10-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g’
g’ < g; f |> g’ g’ : B’ => C Let B’ :> B
Function[-A , +B]](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-11-2048.jpg)
![FUNCTION[-A, +B]
f: A => B
g: B => C
f andThen g
g(f(x))
f |> g
A B С
f g’
Function[-A , +B] :
application of Liskov substitution principle
// Barbara Liskov, CLU Language ~ 1974](https://image.slidesharecdn.com/covariance-171214123254/75/co-contr-variance-from-LSP-12-2048.jpg)
