SlideShare ist ein Scribd-Unternehmen logo
1 von 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/

Weitere ähnliche Inhalte

Ähnlich wie Dependent Types make bad data unrepresentable

Ähnlich wie 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
 

Mehr von Jack Fox

Mehr von 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#
 

Kürzlich hochgeladen

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
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
 
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...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
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
 
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
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
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 ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
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
 

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/