Structural Prototypes
A Sane Framework for Statically-Typed OO+FP
Structural Prototypes A Sane Framework for Statically-Typed OO+FP - - PowerPoint PPT Presentation
Structural Prototypes A Sane Framework for Statically-Typed OO+FP Avoiding Religion Were doing static typing, like it or not! Assume with me that OO is good Expressiveness is good More expressiveness is better? Class Types
A Sane Framework for Statically-Typed OO+FP
Class Types
Class Types Parametric Polymorphism
Class Types Parametric Polymorphism Declaration Site Variance
Class Types Parametric Polymorphism Declaration Site Variance Existentials
Class Types Parametric Polymorphism Declaration Site Variance B
n d e d Q u a n t i fi c a t i
Existentials
Class Types Parametric Polymorphism Declaration Site Variance B
n d e d Q u a n t i fi c a t i
Existentials P a t h Dependent
Class Types Parametric Polymorphism Declaration Site Variance B
n d e d Q u a n t i fi c a t i
Existentials P a t h Dependent Higher Kinds
Class Types Parametric Polymorphism Declaration Site Variance B
n d e d Q u a n t i fi c a t i
Existentials P a t h Dependent Higher Kinds
Apricot = Origin.with( sweetness: 7 bites: 0 takeBite: #(this.with(bites: bites + 1))) Grapefruit = Apricot.with(sweetness: 1) Apple = Apricot.with(sweetness: 5)
Some = #(x, Origin.with( getOrElse: #(_, x) map: #(f, Some(f(x))) flatMap: #(f, f(x)))) None = Origin.with( getOrElse: #(x, x) map: #(_, this) flatMap: #(_, this))
Seq = #(foldRight, Origin.with( builder: #(xs, Seq(xs.foldRight)) foldRight: foldRight map: #(f, res = foldRight(Vector0, #(x, acc, acc.prepend(f(x)))))))
Seq = #(foldRight, Origin.with( builder: #(xs, Seq(xs.foldRight)) foldRight: foldRight map: #(f, res = foldRight(Vector0, #(x, acc, acc.prepend(f(x))))))) ListImpl = #(foldRight, Seq(foldRight).with( builder: #(xs, xs.foldRight(Nil, Cons)))) Cons = #(head, tail, foldRight = #(z, f, f(head, tail.foldRight(z, f))) ListImpl(foldRight)) Nil = ListImpl(#(_, z, z))
Vector = #(xs, ds = Origin.with( /* hard core data structure */ ) Seq(ds.foldRight).with( builder: Vector prepend: #(x, …))) Vector0 = … // empty vector