SlideShare a Scribd company logo
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

PPTX
Java Foundations: Maps, Lambda and Stream API
PPTX
Java Foundations: Arrays
PPTX
Dev Concepts: Data Structures and Algorithms
PPTX
Address calculation-sort
PPTX
Java Foundations: Lists, ArrayList<T>
PPT
1 D Arrays in C++
PPTX
Unit 6. Arrays
PDF
Swift Study #3
Java Foundations: Maps, Lambda and Stream API
Java Foundations: Arrays
Dev Concepts: Data Structures and Algorithms
Address calculation-sort
Java Foundations: Lists, ArrayList<T>
1 D Arrays in C++
Unit 6. Arrays
Swift Study #3

What's hot (20)

PDF
Lecture 3
PPT
Extractors & Implicit conversions
PPTX
Java Foundations: Data Types and Type Conversion
PPTX
Gates and Flip flop
PDF
Functional programming with haskell
PPTX
Dependent Types with Idris
PDF
Lecture 2
PPT
17 linkedlist (1)
PPTX
2- Dimensional Arrays
PDF
Lecture 4
PDF
The Functional Programming Triad of fold, scan and iterate
PPT
Array in Java
PPTX
Strings in C language
PPTX
Array Introduction One-dimensional array Multidimensional array
PDF
Multi dimensional array
PPT
Java: Introduction to Arrays
PPTX
Arrays in Java
PPT
basic concepts
Lecture 3
Extractors & Implicit conversions
Java Foundations: Data Types and Type Conversion
Gates and Flip flop
Functional programming with haskell
Dependent Types with Idris
Lecture 2
17 linkedlist (1)
2- Dimensional Arrays
Lecture 4
The Functional Programming Triad of fold, scan and iterate
Array in Java
Strings in C language
Array Introduction One-dimensional array Multidimensional array
Multi dimensional array
Java: Introduction to Arrays
Arrays in Java
basic concepts
Ad

Viewers also liked (20)

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

Similar to Introduction to Dependently Types: Idris (20)

PDF
Introduction to idris
PDF
Scala by Luc Duponcheel
PDF
Lecture 5: Functional Programming
PDF
(How) can we benefit from adopting scala?
PPTX
Scala Back to Basics: Type Classes
PDF
Functional Programming Patterns (BuildStuff '14)
PDF
Python-3-compiled-Cheat-Sheet-version-3.pdf
ODP
Functions In Scala
PDF
High Wizardry in the Land of Scala
PDF
Python 2.5 reference card (2009)
PDF
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
PDF
Power of functions in a typed world
PDF
Reasoning about laziness
PDF
Monadologie
PDF
Why Haskell Matters
PDF
Scalapeno18 - Thinking Less with Scala
ODP
Introducing scala
PPTX
PDF
An overview of Python 2.7
PDF
A tour of Python
Introduction to idris
Scala by Luc Duponcheel
Lecture 5: Functional Programming
(How) can we benefit from adopting scala?
Scala Back to Basics: Type Classes
Functional Programming Patterns (BuildStuff '14)
Python-3-compiled-Cheat-Sheet-version-3.pdf
Functions In Scala
High Wizardry in the Land of Scala
Python 2.5 reference card (2009)
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Power of functions in a typed world
Reasoning about laziness
Monadologie
Why Haskell Matters
Scalapeno18 - Thinking Less with Scala
Introducing scala
An overview of Python 2.7
A tour of Python

Recently uploaded (20)

PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
System and Network Administraation Chapter 3
PPTX
Introduction to Artificial Intelligence
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Transform Your Business with a Software ERP System
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Essential Infomation Tech presentation.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PPTX
history of c programming in notes for students .pptx
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
VVF-Customer-Presentation2025-Ver1.9.pptx
System and Network Administraation Chapter 3
Introduction to Artificial Intelligence
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How to Choose the Right IT Partner for Your Business in Malaysia
wealthsignaloriginal-com-DS-text-... (1).pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Transform Your Business with a Software ERP System
How Creative Agencies Leverage Project Management Software.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Essential Infomation Tech presentation.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
L1 - Introduction to python Backend.pptx
history of c programming in notes for students .pptx
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

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