SlideShare a Scribd company logo
Introduction to programming with
dependent types in Scala
Dmytro Mitin
https://stepik.org/2294
April 2017
Dmytro Mitin Introduction to programming with dependent types in Scala
Values and types
Types
Int, Boolean, String, . . .
Values
10, true, "abc", . . .
10 : Int
true : Boolean
"abc" : String
. . .
Dmytro Mitin Introduction to programming with dependent types in Scala
Value functions, type families and dependent types
Value-level function (value depending on another value)
(x: Int) => x * x, (x: String) => x + "ab", . . .
Type family (type depending on another type)
Seq[Int], Seq[Boolean], Seq[String], . . .
List[Int], List[Boolean], List[String], . . .
Dependent type (type depending on value of another type)
Sized[Seq[String], 0], Sized[Seq[String], 1], Sized[Seq[String], 2], . . .
val x: Seq[String] = Seq("a", "b", "c")
val x1: Seq[String] = Seq("a", "b", "c", "d")
import shapeless.Sized // Vector type
val x2 : Sized[Seq[String], 3] = Sized("a", "b", "c")
val x3 : Sized[Seq[String], 3] = Sized("a", "b", "c", "d")
Dmytro Mitin Introduction to programming with dependent types in Scala
Homotopy type theory (HoTT)
https://homotopytypetheory.org/book/
Fiber bundle
Dependent pair type
mkPair(n, vn) !: Sgma(n !: Nat, Vec(n))
( 3, Sized("a", "b", "c")) : Σ(n : Nat, Sized[Seq[String], n])
Dmytro Mitin Introduction to programming with dependent types in Scala
Type-level programming
Types
True, False, 0, 1, 2, . . . , Int, Boolean, String, . . .
Values
True, False, 0, 1, 2, . . .
Type-level calculations (compile time)
implicitly[(True# && [False])# || [True] =:= True]
implicitly[( 1# + [ 2])# * [ 3] =:= 9]
Value-level calculations (run time)
(true && false) || true == true
(True.&&(False)).||(True) == True
(1 + 2) * 3 == 9
( 1.+( 2)).*( 3) == 9
Dmytro Mitin Introduction to programming with dependent types in Scala
Theorem proving
import provingground.
import HoTT.
import TLImplicits.
import shapeless.
val indN assoc = NatInd.induc(n :-> (m ∼>: (k ∼>: (
add(add(n)(m))(k) =:= add(n)(add(m)(k)) ))))
val hyp = "(n+m)+k=n+(m+k)" :: m ∼>: k ∼>: (
add(add(n)(m))(k) =:= add(n)(add(m)(k)) )
val assoc = indN assoc(m :∼> (k :∼> add(m)(k).refl))(
n :∼> (hyp :-> (m :∼> (k :∼>
IdentityTyp.extnslty(succ)(add(add(n)(m))(k))
(add(n)(add(m)(k))) (hyp(m)(k))
))))
assoc !: n ∼>: m ∼>: k ∼>: (
add(add(n)(m))(k) =:= add(n)(add(m)(k)) )
Dmytro Mitin Introduction to programming with dependent types in Scala

More Related Content

PDF
00 - Scala. Intro
PDF
Sigma type
PDF
15 - Scala. Dependent function type (Π-type)
PDF
Type-level programming
PDF
Traversals for all ocasions
PPTX
Constructor in c++
PPTX
ATS Programming
PDF
Monoids, Monoids, Monoids - ScalaLove 2020
00 - Scala. Intro
Sigma type
15 - Scala. Dependent function type (Π-type)
Type-level programming
Traversals for all ocasions
Constructor in c++
ATS Programming
Monoids, Monoids, Monoids - ScalaLove 2020

What's hot (18)

PDF
Monoids, monoids, monoids
PDF
16 - Scala. Type of length-indexed vectors
PDF
Oh, All the things you'll traverse
PDF
Value objects in JS - an ES7 work in progress
PDF
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
PDF
Kotlin Delegates: Reduce the boilerplate
PDF
Type classes
PDF
Testing in the World of Functional Programming
PDF
oop presentation note
PPSX
Constructor and destructor
PPTX
Constructors
PDF
Extensible Operators and Literals for JavaScript
PPTX
Constructor ppt
PDF
Web futures
PPT
Review constdestr
PDF
Constructor and Destructor
PPTX
Concept of constructors
PDF
JS Responsibilities
Monoids, monoids, monoids
16 - Scala. Type of length-indexed vectors
Oh, All the things you'll traverse
Value objects in JS - an ES7 work in progress
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Kotlin Delegates: Reduce the boilerplate
Type classes
Testing in the World of Functional Programming
oop presentation note
Constructor and destructor
Constructors
Extensible Operators and Literals for JavaScript
Constructor ppt
Web futures
Review constdestr
Constructor and Destructor
Concept of constructors
JS Responsibilities
Ad

Similar to Introduction to programming with dependent types in Scala (20)

PPTX
Python-CH01L04-Presentation.pptx
PDF
Power of functions in a typed world
PPTX
Data Science.pptx00000000000000000000000
PPTX
Struktur data 1
PPTX
R Programming.pptx
PPTX
PDF
An overview of Python 2.7
PDF
A tour of Python
PDF
C# Summer course - Lecture 2
PPTX
IOT notes,................................
PPTX
R교육1
PDF
PPT
An introduction to scala
PPT
Understanding linq
PDF
Advanced Web Technology ass.pdf
PDF
Kotlin and Domain-Driven Design: A perfect match - Kotlin Meetup Munich
PPTX
python
PDF
Python-3-compiled-Cheat-Sheet-version-3.pdf
PPTX
Python Session - 3
PPTX
Python Data Types,numbers.pptx
Python-CH01L04-Presentation.pptx
Power of functions in a typed world
Data Science.pptx00000000000000000000000
Struktur data 1
R Programming.pptx
An overview of Python 2.7
A tour of Python
C# Summer course - Lecture 2
IOT notes,................................
R교육1
An introduction to scala
Understanding linq
Advanced Web Technology ass.pdf
Kotlin and Domain-Driven Design: A perfect match - Kotlin Meetup Munich
python
Python-3-compiled-Cheat-Sheet-version-3.pdf
Python Session - 3
Python Data Types,numbers.pptx
Ad

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Lesson notes of climatology university.
PDF
Basic Mud Logging Guide for educational purpose
PDF
Sports Quiz easy sports quiz sports quiz
102 student loan defaulters named and shamed – Is someone you know on the list?
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Abdominal Access Techniques with Prof. Dr. R K Mishra
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
human mycosis Human fungal infections are called human mycosis..pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
O7-L3 Supply Chain Operations - ICLT Program
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Final Presentation General Medicine 03-08-2024.pptx
Pharma ospi slides which help in ospi learning
Insiders guide to clinical Medicine.pdf
Lesson notes of climatology university.
Basic Mud Logging Guide for educational purpose
Sports Quiz easy sports quiz sports quiz

Introduction to programming with dependent types in Scala

  • 1. Introduction to programming with dependent types in Scala Dmytro Mitin https://stepik.org/2294 April 2017 Dmytro Mitin Introduction to programming with dependent types in Scala
  • 2. Values and types Types Int, Boolean, String, . . . Values 10, true, "abc", . . . 10 : Int true : Boolean "abc" : String . . . Dmytro Mitin Introduction to programming with dependent types in Scala
  • 3. Value functions, type families and dependent types Value-level function (value depending on another value) (x: Int) => x * x, (x: String) => x + "ab", . . . Type family (type depending on another type) Seq[Int], Seq[Boolean], Seq[String], . . . List[Int], List[Boolean], List[String], . . . Dependent type (type depending on value of another type) Sized[Seq[String], 0], Sized[Seq[String], 1], Sized[Seq[String], 2], . . . val x: Seq[String] = Seq("a", "b", "c") val x1: Seq[String] = Seq("a", "b", "c", "d") import shapeless.Sized // Vector type val x2 : Sized[Seq[String], 3] = Sized("a", "b", "c") val x3 : Sized[Seq[String], 3] = Sized("a", "b", "c", "d") Dmytro Mitin Introduction to programming with dependent types in Scala
  • 4. Homotopy type theory (HoTT) https://homotopytypetheory.org/book/ Fiber bundle Dependent pair type mkPair(n, vn) !: Sgma(n !: Nat, Vec(n)) ( 3, Sized("a", "b", "c")) : Σ(n : Nat, Sized[Seq[String], n]) Dmytro Mitin Introduction to programming with dependent types in Scala
  • 5. Type-level programming Types True, False, 0, 1, 2, . . . , Int, Boolean, String, . . . Values True, False, 0, 1, 2, . . . Type-level calculations (compile time) implicitly[(True# && [False])# || [True] =:= True] implicitly[( 1# + [ 2])# * [ 3] =:= 9] Value-level calculations (run time) (true && false) || true == true (True.&&(False)).||(True) == True (1 + 2) * 3 == 9 ( 1.+( 2)).*( 3) == 9 Dmytro Mitin Introduction to programming with dependent types in Scala
  • 6. Theorem proving import provingground. import HoTT. import TLImplicits. import shapeless. val indN assoc = NatInd.induc(n :-> (m ∼>: (k ∼>: ( add(add(n)(m))(k) =:= add(n)(add(m)(k)) )))) val hyp = "(n+m)+k=n+(m+k)" :: m ∼>: k ∼>: ( add(add(n)(m))(k) =:= add(n)(add(m)(k)) ) val assoc = indN assoc(m :∼> (k :∼> add(m)(k).refl))( n :∼> (hyp :-> (m :∼> (k :∼> IdentityTyp.extnslty(succ)(add(add(n)(m))(k)) (add(n)(add(m)(k))) (hyp(m)(k)) )))) assoc !: n ∼>: m ∼>: k ∼>: ( add(add(n)(m))(k) =:= add(n)(add(m)(k)) ) Dmytro Mitin Introduction to programming with dependent types in Scala