SlideShare a Scribd company logo
1 of 25
Idris
Abdulsattar - http://bimorphic.com
Features
Strictly evaluated purely functional language
Has backends to LLVM, C, Javascript and even Erlang!
Full dependent types with dependent pattern matching
Simple foreign function interface (to C)
Compiler-supported interactive editing: the compiler helps you write code using the types
where clauses, with rule, simple case expressions, pattern matching let and lambda bindings
Dependent records with projection and update
Motivation
def first(arr)
arr[0]
end
Points of Failure:
1. arr is not an array
2. arr is null
3. arr is empty
Motivation
public int first(int[] list)
{
return list[0];
}
Point of Failures:
1. arr is not an array
2. arr is null
3. arr is empty
Motivation
first :: [Int] -> Int
first xs = xs !! 0
Point of Failures:
1. arr is not an array
2. arr is null
3. arr is empty
Actual Requirement
arr must be an array of at least 1 length
Problem
first :: [Int] -> Int
first xs = xs !! 0
public int first(int[] list)
{
return list[0];
}
def first(arr)
arr[0]
end
anything → anything (or runtime error)
array or null → int (or runtime error)
array → int (or runtime error)
Problem
● Types don’t capture all the invariants
● Functions work for only a subset of inputs ‒ they are not
total
Dependent Types
Dependent Types allow types to depend on their values.
e.g. length of a list can be part of the type of the list
Natural Numbers
data Nat = Z | S Nat -- peano numbers
zero = Z
one = S Z
two = S (S Z)
…
Operations
plus : Nat -> Nat -> Nat
plus Z y = y
plus (S k) y = S (plus k y)
0 + y = y
(1 + x) + y = 1 + (x + y)
0 ✕ y = 0
(1 + x) ✕ y = y + (x ✕ y)
mult : Nat -> Nat -> Nat
mult Z y = Z
mult (S k) y = plus y (mult k y)
Vectors
data Vect : Nat -> Type -> Type where
Nil : Vect Z a
(::) : a -> Vect k a -> Vect (S k) a
zeroVect : Vect 0 Int
zeroVect = Nil
oneVect : Vect 1 Int
oneVect = 3 :: Nil
threeVect : Vect 3 String
threeVect = "I" :: "hope" :: "i'm not confusing you" :: Nil
Solution
first : Vect (S k) a -> a
first (x::xs) = x
Points of Failure:
1. arr is not an array
2. arr is null
3. arr is empty
Concatenation
(++) : Vect n a -> Vect m a -> Vect (n + m) a
(++) Nil ys = ys
(++) (x :: xs) ys = x :: xs ++ ys
(++) : Vect n a -> Vect m a -> Vect (n + m) a
(++) Nil ys = ys
(++) (x :: xs) ys = x :: xs ++ xs
Error: Expected Vect (n + m) a; Got Vect (n + n) a
Another problem
Getting an element in an array by index
Goal: No more ArrayIndexOutOfBoundsException!
elemAt
elemAt : Fin n -> Vect n a -> a
elemAt FZ (x :: xs) = x
elemAt (FS k) (x :: xs) = elemAt k xs
data Fin : Nat -> Type where
FZ : Fin (S k)
FS : Fin k -> Fin (S k)
Even Numbers
data Even : Nat -> Type where
EZ : Even Z
ES : Even k -> Even (S (S k))
zeroIsEven : Even 0
zeroIsEven = EZ
twoIsEven : Even 2
twoIsEven = ES EZ
Proofs
Theorem: 4 is even
0 is even
0 + 2 is even
(0 + 2) + 2 is even
Proof by Mathematical Induction
fourIsEven : Even 4
fourIsEven = ES (ES EZ)
Idris
Curry Howard Correspondence
Programs and mathematical proofs are the same thing,
basically
Equality
data (=) : a -> b -> Type where
Refl : x = x
twoIsTwo : 2 = 2
twoIsTwo = Refl
3Plus2IsFive : 3 + 2 = 5
3Plus2IsFive = Refl
Falsity or the Empty Type
disjoint : (n : Nat) -> Z = S n -> Void
disjoint n p = replace {P = disjointTy} p ()
where
disjointTy : Nat -> Type
disjointTy Z = ()
disjointTy (S k) = Void
data Void : Type where
Interactive Editing
DEMO
Types as First-Class citizens
DEMO
Type Safe printf
DEMO
Thank you!
Q & A

More Related Content

What's hot

What's hot (20)

Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Extractors & Implicit conversions
Extractors & Implicit conversionsExtractors & Implicit conversions
Extractors & Implicit conversions
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
 
Gates and Flip flop
Gates and Flip flopGates and Flip flop
Gates and Flip flop
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskell
 
Arrays
ArraysArrays
Arrays
 
Dependent Types with Idris
Dependent Types with IdrisDependent Types with Idris
Dependent Types with Idris
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Multi dimensional array
Multi dimensional arrayMulti dimensional array
Multi dimensional array
 
Lec3
Lec3Lec3
Lec3
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
basic concepts
basic conceptsbasic concepts
basic concepts
 

Viewers also liked

Birgit Plietzsch “RDM within research computing support” SALCTG June 2013
Birgit Plietzsch “RDM within research computing support” SALCTG June 2013Birgit Plietzsch “RDM within research computing support” SALCTG June 2013
Birgit Plietzsch “RDM within research computing support” SALCTG June 2013SALCTG
 
5 Ways Your SMB Can Make More Money Using Social Media
5 Ways Your SMB Can Make More Money Using Social Media5 Ways Your SMB Can Make More Money Using Social Media
5 Ways Your SMB Can Make More Money Using Social MediaDave Kerpen
 
5 Tips on Twitter: #Live Storytelling w/ Patrick Stewart at #CannesLions #Ogi...
5 Tips on Twitter: #Live Storytelling w/ Patrick Stewart at #CannesLions #Ogi...5 Tips on Twitter: #Live Storytelling w/ Patrick Stewart at #CannesLions #Ogi...
5 Tips on Twitter: #Live Storytelling w/ Patrick Stewart at #CannesLions #Ogi...Ogilvy
 
Presentación sobre el Informe de Desarrollo Sostenible de Euskadi
Presentación sobre el Informe de Desarrollo Sostenible de EuskadiPresentación sobre el Informe de Desarrollo Sostenible de Euskadi
Presentación sobre el Informe de Desarrollo Sostenible de EuskadiPEGIP2020
 
Mad Max Tribute
Mad Max TributeMad Max Tribute
Mad Max TributeNova Media
 
Responsive design in sp seminar buildingi 20130918
Responsive design in sp seminar buildingi 20130918Responsive design in sp seminar buildingi 20130918
Responsive design in sp seminar buildingi 20130918Bill England
 
Μαθαίνω τον ΗΥ
Μαθαίνω τον ΗΥΜαθαίνω τον ΗΥ
Μαθαίνω τον ΗΥExpertin
 
Vimbai s Curriculum Vitae-1
Vimbai s Curriculum Vitae-1Vimbai s Curriculum Vitae-1
Vimbai s Curriculum Vitae-1Vimbai Vsingizi
 
Врезка_замка_в_межкомнатную_дверь
Врезка_замка_в_межкомнатную_дверьВрезка_замка_в_межкомнатную_дверь
Врезка_замка_в_межкомнатную_дверьspecdveri
 
Ibm colloquium 070915_nyberg
Ibm colloquium 070915_nybergIbm colloquium 070915_nyberg
Ibm colloquium 070915_nybergdiannepatricia
 
Albania america community twining project 01 club twin
Albania america community twining project  01 club twinAlbania america community twining project  01 club twin
Albania america community twining project 01 club twinAvi Dey
 
задание 6 насекина
задание 6 насекиназадание 6 насекина
задание 6 насекинаKriiiiis
 
Business innovation rick huijbregts 16oct2013
Business innovation   rick huijbregts 16oct2013Business innovation   rick huijbregts 16oct2013
Business innovation rick huijbregts 16oct2013Rick Huijbregts
 
СПГСГ,,Арх.Георги Козаров" гр.Сливен
СПГСГ,,Арх.Георги Козаров" гр.СливенСПГСГ,,Арх.Георги Козаров" гр.Сливен
СПГСГ,,Арх.Георги Козаров" гр.СливенИскра Косева
 
Bba diversity conference report 6.5.12
Bba diversity conference report 6.5.12Bba diversity conference report 6.5.12
Bba diversity conference report 6.5.12SuffolkLALSA
 
El bullying!
El bullying!El bullying!
El bullying!Abel0700
 

Viewers also liked (20)

Birgit Plietzsch “RDM within research computing support” SALCTG June 2013
Birgit Plietzsch “RDM within research computing support” SALCTG June 2013Birgit Plietzsch “RDM within research computing support” SALCTG June 2013
Birgit Plietzsch “RDM within research computing support” SALCTG June 2013
 
5 Ways Your SMB Can Make More Money Using Social Media
5 Ways Your SMB Can Make More Money Using Social Media5 Ways Your SMB Can Make More Money Using Social Media
5 Ways Your SMB Can Make More Money Using Social Media
 
5 Tips on Twitter: #Live Storytelling w/ Patrick Stewart at #CannesLions #Ogi...
5 Tips on Twitter: #Live Storytelling w/ Patrick Stewart at #CannesLions #Ogi...5 Tips on Twitter: #Live Storytelling w/ Patrick Stewart at #CannesLions #Ogi...
5 Tips on Twitter: #Live Storytelling w/ Patrick Stewart at #CannesLions #Ogi...
 
Return vs output
Return vs outputReturn vs output
Return vs output
 
Presentación sobre el Informe de Desarrollo Sostenible de Euskadi
Presentación sobre el Informe de Desarrollo Sostenible de EuskadiPresentación sobre el Informe de Desarrollo Sostenible de Euskadi
Presentación sobre el Informe de Desarrollo Sostenible de Euskadi
 
1 cv en wilson couto
1 cv en wilson couto1 cv en wilson couto
1 cv en wilson couto
 
Mad Max Tribute
Mad Max TributeMad Max Tribute
Mad Max Tribute
 
Responsive design in sp seminar buildingi 20130918
Responsive design in sp seminar buildingi 20130918Responsive design in sp seminar buildingi 20130918
Responsive design in sp seminar buildingi 20130918
 
Μαθαίνω τον ΗΥ
Μαθαίνω τον ΗΥΜαθαίνω τον ΗΥ
Μαθαίνω τον ΗΥ
 
Vimbai s Curriculum Vitae-1
Vimbai s Curriculum Vitae-1Vimbai s Curriculum Vitae-1
Vimbai s Curriculum Vitae-1
 
Врезка_замка_в_межкомнатную_дверь
Врезка_замка_в_межкомнатную_дверьВрезка_замка_в_межкомнатную_дверь
Врезка_замка_в_межкомнатную_дверь
 
Ibm colloquium 070915_nyberg
Ibm colloquium 070915_nybergIbm colloquium 070915_nyberg
Ibm colloquium 070915_nyberg
 
Albania america community twining project 01 club twin
Albania america community twining project  01 club twinAlbania america community twining project  01 club twin
Albania america community twining project 01 club twin
 
New orleans
New orleansNew orleans
New orleans
 
задание 6 насекина
задание 6 насекиназадание 6 насекина
задание 6 насекина
 
Business innovation rick huijbregts 16oct2013
Business innovation   rick huijbregts 16oct2013Business innovation   rick huijbregts 16oct2013
Business innovation rick huijbregts 16oct2013
 
СПГСГ,,Арх.Георги Козаров" гр.Сливен
СПГСГ,,Арх.Георги Козаров" гр.СливенСПГСГ,,Арх.Георги Козаров" гр.Сливен
СПГСГ,,Арх.Георги Козаров" гр.Сливен
 
Bba diversity conference report 6.5.12
Bba diversity conference report 6.5.12Bba diversity conference report 6.5.12
Bba diversity conference report 6.5.12
 
El bullying!
El bullying!El bullying!
El bullying!
 
Gotham ΙΙΙ
Gotham ΙΙΙGotham ΙΙΙ
Gotham ΙΙΙ
 

Similar to Introduction to Dependently Types: Idris

Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idrisConor Farrell
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional ProgrammingEelco Visser
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Scott Wlaschin
 
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.pdfletsdism
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala Knoldus Inc.
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scaladjspiewak
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
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 worldDebasish Ghosh
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about lazinessJohan Tibell
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Mattersromanandreg
 
Scalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with ScalaScalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with ScalaDaniel Sebban
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Functional and reactive u is gwt.create 2015
Functional and reactive u is gwt.create 2015Functional and reactive u is gwt.create 2015
Functional and reactive u is gwt.create 2015hezamu
 

Similar to Introduction to Dependently Types: Idris (20)

Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idris
 
Scala by Luc Duponcheel
Scala by Luc DuponcheelScala by Luc Duponcheel
Scala by Luc Duponcheel
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 
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
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
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
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about laziness
 
Monadologie
MonadologieMonadologie
Monadologie
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
Scalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with ScalaScalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with Scala
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
Scala
ScalaScala
Scala
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Functional and reactive u is gwt.create 2015
Functional and reactive u is gwt.create 2015Functional and reactive u is gwt.create 2015
Functional and reactive u is gwt.create 2015
 

Recently uploaded

办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 

Recently uploaded (20)

办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 

Introduction to Dependently Types: Idris

  • 2. Features Strictly evaluated purely functional language Has backends to LLVM, C, Javascript and even Erlang! Full dependent types with dependent pattern matching Simple foreign function interface (to C) Compiler-supported interactive editing: the compiler helps you write code using the types where clauses, with rule, simple case expressions, pattern matching let and lambda bindings Dependent records with projection and update
  • 3. Motivation def first(arr) arr[0] end Points of Failure: 1. arr is not an array 2. arr is null 3. arr is empty
  • 4. Motivation public int first(int[] list) { return list[0]; } Point of Failures: 1. arr is not an array 2. arr is null 3. arr is empty
  • 5. Motivation first :: [Int] -> Int first xs = xs !! 0 Point of Failures: 1. arr is not an array 2. arr is null 3. arr is empty
  • 6. Actual Requirement arr must be an array of at least 1 length
  • 7. Problem first :: [Int] -> Int first xs = xs !! 0 public int first(int[] list) { return list[0]; } def first(arr) arr[0] end anything → anything (or runtime error) array or null → int (or runtime error) array → int (or runtime error)
  • 8. Problem ● Types don’t capture all the invariants ● Functions work for only a subset of inputs ‒ they are not total
  • 9. Dependent Types Dependent Types allow types to depend on their values. e.g. length of a list can be part of the type of the list
  • 10. Natural Numbers data Nat = Z | S Nat -- peano numbers zero = Z one = S Z two = S (S Z) …
  • 11. Operations plus : Nat -> Nat -> Nat plus Z y = y plus (S k) y = S (plus k y) 0 + y = y (1 + x) + y = 1 + (x + y) 0 ✕ y = 0 (1 + x) ✕ y = y + (x ✕ y) mult : Nat -> Nat -> Nat mult Z y = Z mult (S k) y = plus y (mult k y)
  • 12. Vectors data Vect : Nat -> Type -> Type where Nil : Vect Z a (::) : a -> Vect k a -> Vect (S k) a zeroVect : Vect 0 Int zeroVect = Nil oneVect : Vect 1 Int oneVect = 3 :: Nil threeVect : Vect 3 String threeVect = "I" :: "hope" :: "i'm not confusing you" :: Nil
  • 13. Solution first : Vect (S k) a -> a first (x::xs) = x Points of Failure: 1. arr is not an array 2. arr is null 3. arr is empty
  • 14. Concatenation (++) : Vect n a -> Vect m a -> Vect (n + m) a (++) Nil ys = ys (++) (x :: xs) ys = x :: xs ++ ys (++) : Vect n a -> Vect m a -> Vect (n + m) a (++) Nil ys = ys (++) (x :: xs) ys = x :: xs ++ xs Error: Expected Vect (n + m) a; Got Vect (n + n) a
  • 15. Another problem Getting an element in an array by index Goal: No more ArrayIndexOutOfBoundsException!
  • 16. elemAt elemAt : Fin n -> Vect n a -> a elemAt FZ (x :: xs) = x elemAt (FS k) (x :: xs) = elemAt k xs data Fin : Nat -> Type where FZ : Fin (S k) FS : Fin k -> Fin (S k)
  • 17. Even Numbers data Even : Nat -> Type where EZ : Even Z ES : Even k -> Even (S (S k)) zeroIsEven : Even 0 zeroIsEven = EZ twoIsEven : Even 2 twoIsEven = ES EZ
  • 18. Proofs Theorem: 4 is even 0 is even 0 + 2 is even (0 + 2) + 2 is even Proof by Mathematical Induction fourIsEven : Even 4 fourIsEven = ES (ES EZ) Idris
  • 19. Curry Howard Correspondence Programs and mathematical proofs are the same thing, basically
  • 20. Equality data (=) : a -> b -> Type where Refl : x = x twoIsTwo : 2 = 2 twoIsTwo = Refl 3Plus2IsFive : 3 + 2 = 5 3Plus2IsFive = Refl
  • 21. Falsity or the Empty Type disjoint : (n : Nat) -> Z = S n -> Void disjoint n p = replace {P = disjointTy} p () where disjointTy : Nat -> Type disjointTy Z = () disjointTy (S k) = Void data Void : Type where
  • 23. Types as First-Class citizens DEMO