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
Ad

More Related Content

What's hot (18)

Monoids, monoids, monoids
Monoids, monoids, monoidsMonoids, monoids, monoids
Monoids, monoids, monoids
Luka Jacobowitz
 
16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors
Roman Brovko
 
Oh, All the things you'll traverse
Oh, All the things you'll traverseOh, All the things you'll traverse
Oh, All the things you'll traverse
Luka Jacobowitz
 
Value objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progressValue objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progress
Brendan Eich
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Brendan Eich
 
Kotlin Delegates: Reduce the boilerplate
Kotlin Delegates: Reduce the boilerplateKotlin Delegates: Reduce the boilerplate
Kotlin Delegates: Reduce the boilerplate
Dmytro Zaitsev
 
Type classes
Type classesType classes
Type classes
Dmytro Mitin
 
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional Programming
Luka Jacobowitz
 
oop presentation note
oop presentation note oop presentation note
oop presentation note
Atit Patumvan
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
Selvin Josy Bai Somu
 
Constructors
ConstructorsConstructors
Constructors
shravani2191
 
Extensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScriptExtensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScript
Brendan Eich
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
Vinod Kumar
 
Web futures
Web futuresWeb futures
Web futures
Brendan Eich
 
Review constdestr
Review constdestrReview constdestr
Review constdestr
rajudasraju
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
Kamal Acharya
 
Concept of constructors
Concept of constructorsConcept of constructors
Concept of constructors
kunj desai
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS Responsibilities
Brendan Eich
 
Monoids, monoids, monoids
Monoids, monoids, monoidsMonoids, monoids, monoids
Monoids, monoids, monoids
Luka Jacobowitz
 
16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors16 - Scala. Type of length-indexed vectors
16 - Scala. Type of length-indexed vectors
Roman Brovko
 
Oh, All the things you'll traverse
Oh, All the things you'll traverseOh, All the things you'll traverse
Oh, All the things you'll traverse
Luka Jacobowitz
 
Value objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progressValue objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progress
Brendan Eich
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Brendan Eich
 
Kotlin Delegates: Reduce the boilerplate
Kotlin Delegates: Reduce the boilerplateKotlin Delegates: Reduce the boilerplate
Kotlin Delegates: Reduce the boilerplate
Dmytro Zaitsev
 
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional Programming
Luka Jacobowitz
 
oop presentation note
oop presentation note oop presentation note
oop presentation note
Atit Patumvan
 
Extensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScriptExtensible Operators and Literals for JavaScript
Extensible Operators and Literals for JavaScript
Brendan Eich
 
Review constdestr
Review constdestrReview constdestr
Review constdestr
rajudasraju
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
Kamal Acharya
 
Concept of constructors
Concept of constructorsConcept of constructors
Concept of constructors
kunj desai
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS Responsibilities
Brendan Eich
 

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

Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptx
ElijahSantos4
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
Debasish Ghosh
 
Data Science.pptx00000000000000000000000
Data Science.pptx00000000000000000000000Data Science.pptx00000000000000000000000
Data Science.pptx00000000000000000000000
shaikhmismail66
 
Struktur data 1
Struktur data 1Struktur data 1
Struktur data 1
bagus dwi saputra
 
R Programming.pptx
R Programming.pptxR Programming.pptx
R Programming.pptx
kalai75
 
R Basics
R BasicsR Basics
R Basics
Dr.E.N.Sathishkumar
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
decoupled
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
Aleksandar Veselinovic
 
C# Summer course - Lecture 2
C# Summer course - Lecture 2C# Summer course - Lecture 2
C# Summer course - Lecture 2
mohamedsamyali
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and Haskell
Hermann Hueck
 
R교육1
R교육1R교육1
R교육1
Kangwook Lee
 
C# p9
C# p9C# p9
C# p9
Renas Rekany
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
Mohsen Zainalpour
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
Anand Kumar Rajana
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
simenehanmut
 
Kotlin and Domain-Driven Design: A perfect match - Kotlin Meetup Munich
Kotlin and Domain-Driven Design: A perfect match - Kotlin Meetup MunichKotlin and Domain-Driven Design: A perfect match - Kotlin Meetup Munich
Kotlin and Domain-Driven Design: A perfect match - Kotlin Meetup Munich
Florian Benz
 
python
pythonpython
python
ultragamer6
 
Python-3-compiled-Cheat-Sheet-version-3.pdf
Python-3-compiled-Cheat-Sheet-version-3.pdfPython-3-compiled-Cheat-Sheet-version-3.pdf
Python-3-compiled-Cheat-Sheet-version-3.pdf
letsdism
 
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
AnirudhaGaikwad4
 
Python Data Types,numbers.pptx
Python Data Types,numbers.pptxPython Data Types,numbers.pptx
Python Data Types,numbers.pptx
adityakumawat625
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptx
ElijahSantos4
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
Debasish Ghosh
 
Data Science.pptx00000000000000000000000
Data Science.pptx00000000000000000000000Data Science.pptx00000000000000000000000
Data Science.pptx00000000000000000000000
shaikhmismail66
 
R Programming.pptx
R Programming.pptxR Programming.pptx
R Programming.pptx
kalai75
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
decoupled
 
C# Summer course - Lecture 2
C# Summer course - Lecture 2C# Summer course - Lecture 2
C# Summer course - Lecture 2
mohamedsamyali
 
Type Classes in Scala and Haskell
Type Classes in Scala and HaskellType Classes in Scala and Haskell
Type Classes in Scala and Haskell
Hermann Hueck
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
simenehanmut
 
Kotlin and Domain-Driven Design: A perfect match - Kotlin Meetup Munich
Kotlin and Domain-Driven Design: A perfect match - Kotlin Meetup MunichKotlin and Domain-Driven Design: A perfect match - Kotlin Meetup Munich
Kotlin and Domain-Driven Design: A perfect match - Kotlin Meetup Munich
Florian Benz
 
Python-3-compiled-Cheat-Sheet-version-3.pdf
Python-3-compiled-Cheat-Sheet-version-3.pdfPython-3-compiled-Cheat-Sheet-version-3.pdf
Python-3-compiled-Cheat-Sheet-version-3.pdf
letsdism
 
Python Data Types,numbers.pptx
Python Data Types,numbers.pptxPython Data Types,numbers.pptx
Python Data Types,numbers.pptx
adityakumawat625
 
Ad

Recently uploaded (20)

To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Ad

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