SlideShare uma empresa Scribd logo
1 de 16
Make Unacceptable Data
Unrepresentable
Jack Fox
@foxyjackfox
Engineer at
Visual Studio and Development Technologies MVP
Ideally…
Front
End Business Logic
Incoming data
properly edited
Database
imposes
constraints
Perspective of the Applications Programmer
?
?
?
?
?
?
?
? ?
Static Types
• String
• Int
• Float
• Datetime
• List
What if you could easily create custom types
implementing the required business rule constraints?
What if you could easily create custom types
implementing the required business rule constraints?
…and give the type a meaningful name.
What if you could easily create custom types
implementing the required business rule constraints?
…and give the type a meaningful name.
• Assurance the data is always acceptable
What if you could easily create custom types
implementing the required business rule constraints?
…and give the type a meaningful name.
• Assurance the data is always acceptable
• No worries about whether edits performed
What if you could easily create custom types
implementing the required business rule constraints?
…and give the type a meaningful name.
• Assurance the data is always acceptable
• No worries about whether edits performed
• No worries about meeting DB constraints (if they exist)
Dependent Types
U A universe of types (i.e. a type of types)
A:U A is a type inhabiting a universe of types
B: B is a collection of types
(depending on the element, x : A)
We call this a family of types
Π-type, or dependent typeA B
A U
Dependent Function
/// type hint not necessary, enhances intellisense
let f n : DependentType<_, _, int, int> =
match n with
| n' when n' < -100 ->
LTminus100.Create n |> box
| n' when n' > 100 ->
GT100.Create n |> box
| _ ->
Minus100To100.Create n |> box
|> unbox
The DependentType type
type LTminus100 = DependentType<SetUp.MaxMinus101, int, int, int>
type Minus100To100 = DependentType<SetUp.RangeMinus100To100, int * int, int, int>
Π function type
Π function parm type
‘T1 input
‘T2 underlying
Idris
Definitional equality + propositional equality
Constructor + proof ‘T
Constrained to A element matching specific type in B family
User writes functions operating directly on ‘T, but (probably) implicitly on A
F#
Definitional equality (types are equal by construction)
Constructor + Π-function ‘T option
Π-function is explicit type of same scope as dependent type
Π-function output to singleton B family
User writes functions operating explicitly on A
Some Use Cases
• trimmed, non-empty, non-null string
• non-empty generic set
• utc datetime, or any particular timezone
• uppercase Latin string of undetermined or static length
• digit string of undetermined or static length
• integer restricted to a range
• collection of length within a range
• any string validated by a RegEx
• anything validated by a predicate
Dependent Types – Future Directions
• Support extension methods
https://github.com/jackfoxy/DependentTypes/issues/1
• Literal type parameters
https://github.com/jackfoxy/DependentTypes/issues/3
• Add to F# core library
• C# / VB.NET support
Bibliography
F# Dependent Types
https://jackfoxy.github.io/DependentTypes
Looking Outward: When Dependent Types Meet I/O
David Raymond Christiansen, M.Sc. Thesis
http://itu.dk/people/drc/david-christiansen-thesis.pdf
An intuitionistic theory of types, Per Martin-Löf
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.131.926&rep=rep1&type=pdf
Type Theory: A Modern Computable Paradigm for Math
http://www.science4all.org/article/type-theory/

Mais conteúdo relacionado

Semelhante a Dependent Types make bad data unrepresentable

Semelhante a Dependent Types make bad data unrepresentable (20)

Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2
 
Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain Modeling
 
Type Systems
Type SystemsType Systems
Type Systems
 
C#
C#C#
C#
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
From DOT to Dotty
From DOT to DottyFrom DOT to Dotty
From DOT to Dotty
 
Functional Programming in C#
Functional Programming in C#Functional Programming in C#
Functional Programming in C#
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptx
 
Aspdot
AspdotAspdot
Aspdot
 
DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
 
Python Data Types,numbers.pptx
Python Data Types,numbers.pptxPython Data Types,numbers.pptx
Python Data Types,numbers.pptx
 
Recommender System with Distributed Representation
Recommender System with Distributed RepresentationRecommender System with Distributed Representation
Recommender System with Distributed Representation
 
2013 - Andrei Zmievski: Machine learning para datos
2013 - Andrei Zmievski: Machine learning para datos2013 - Andrei Zmievski: Machine learning para datos
2013 - Andrei Zmievski: Machine learning para datos
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NET
 
An Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm ReviewAn Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm Review
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
Python programming
Python programmingPython programming
Python programming
 

Mais de Jack Fox

Mais de Jack Fox (9)

Introduction to the lambda calculus
Introduction to the lambda calculusIntroduction to the lambda calculus
Introduction to the lambda calculus
 
Tools for reading papers
Tools for reading papersTools for reading papers
Tools for reading papers
 
Functional programming for production quality code
Functional programming for production quality codeFunctional programming for production quality code
Functional programming for production quality code
 
Intoduction to Homotopy Type Therory
Intoduction to Homotopy Type TheroryIntoduction to Homotopy Type Therory
Intoduction to Homotopy Type Therory
 
Type Theory and Practical Application
Type Theory and Practical ApplicationType Theory and Practical Application
Type Theory and Practical Application
 
F# for functional enthusiasts
F# for functional enthusiastsF# for functional enthusiasts
F# for functional enthusiasts
 
Semantically coherent functional linear data structures
Semantically coherent functional linear data structuresSemantically coherent functional linear data structures
Semantically coherent functional linear data structures
 
Linear structures lightning talk
Linear structures lightning talkLinear structures lightning talk
Linear structures lightning talk
 
Functional linear data structures in f#
Functional linear data structures in f#Functional linear data structures in f#
Functional linear data structures in f#
 

Último

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Último (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

Dependent Types make bad data unrepresentable

  • 1. Make Unacceptable Data Unrepresentable Jack Fox @foxyjackfox Engineer at Visual Studio and Development Technologies MVP
  • 2. Ideally… Front End Business Logic Incoming data properly edited Database imposes constraints
  • 3. Perspective of the Applications Programmer ? ? ? ? ? ? ? ? ?
  • 4. Static Types • String • Int • Float • Datetime • List
  • 5. What if you could easily create custom types implementing the required business rule constraints?
  • 6. What if you could easily create custom types implementing the required business rule constraints? …and give the type a meaningful name.
  • 7. What if you could easily create custom types implementing the required business rule constraints? …and give the type a meaningful name. • Assurance the data is always acceptable
  • 8. What if you could easily create custom types implementing the required business rule constraints? …and give the type a meaningful name. • Assurance the data is always acceptable • No worries about whether edits performed
  • 9. What if you could easily create custom types implementing the required business rule constraints? …and give the type a meaningful name. • Assurance the data is always acceptable • No worries about whether edits performed • No worries about meeting DB constraints (if they exist)
  • 10. Dependent Types U A universe of types (i.e. a type of types) A:U A is a type inhabiting a universe of types B: B is a collection of types (depending on the element, x : A) We call this a family of types Π-type, or dependent typeA B A U
  • 11. Dependent Function /// type hint not necessary, enhances intellisense let f n : DependentType<_, _, int, int> = match n with | n' when n' < -100 -> LTminus100.Create n |> box | n' when n' > 100 -> GT100.Create n |> box | _ -> Minus100To100.Create n |> box |> unbox
  • 12. The DependentType type type LTminus100 = DependentType<SetUp.MaxMinus101, int, int, int> type Minus100To100 = DependentType<SetUp.RangeMinus100To100, int * int, int, int> Π function type Π function parm type ‘T1 input ‘T2 underlying
  • 13. Idris Definitional equality + propositional equality Constructor + proof ‘T Constrained to A element matching specific type in B family User writes functions operating directly on ‘T, but (probably) implicitly on A F# Definitional equality (types are equal by construction) Constructor + Π-function ‘T option Π-function is explicit type of same scope as dependent type Π-function output to singleton B family User writes functions operating explicitly on A
  • 14. Some Use Cases • trimmed, non-empty, non-null string • non-empty generic set • utc datetime, or any particular timezone • uppercase Latin string of undetermined or static length • digit string of undetermined or static length • integer restricted to a range • collection of length within a range • any string validated by a RegEx • anything validated by a predicate
  • 15. Dependent Types – Future Directions • Support extension methods https://github.com/jackfoxy/DependentTypes/issues/1 • Literal type parameters https://github.com/jackfoxy/DependentTypes/issues/3 • Add to F# core library • C# / VB.NET support
  • 16. Bibliography F# Dependent Types https://jackfoxy.github.io/DependentTypes Looking Outward: When Dependent Types Meet I/O David Raymond Christiansen, M.Sc. Thesis http://itu.dk/people/drc/david-christiansen-thesis.pdf An intuitionistic theory of types, Per Martin-Löf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.131.926&rep=rep1&type=pdf Type Theory: A Modern Computable Paradigm for Math http://www.science4all.org/article/type-theory/