SlideShare une entreprise Scribd logo
1  sur  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/

Contenu connexe

Similaire à Dependent Types make bad data unrepresentable

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 2Knoldus Inc.
 
Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingDebasish Ghosh
 
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#Hawkman Academy
 
Functional Programming in C#
Functional Programming in C#Functional Programming in C#
Functional Programming in C#Tadeusz Balcer
 
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 SwiftFatih Nayebi, Ph.D.
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxElijahSantos4
 
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#Rasan Samarasinghe
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingEelco Visser
 
Python Data Types,numbers.pptx
Python Data Types,numbers.pptxPython Data Types,numbers.pptx
Python Data Types,numbers.pptxadityakumawat625
 
Recommender System with Distributed Representation
Recommender System with Distributed RepresentationRecommender System with Distributed Representation
Recommender System with Distributed RepresentationRakuten Group, Inc.
 
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 datosPHP Conference Argentina
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NETRasan Samarasinghe
 
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 ReviewBlue Elephant Consulting
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha BaliAkanksha Bali
 
Python programming
Python programmingPython programming
Python programmingsaroja20
 

Similaire à 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
 

Plus de Jack Fox

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

Plus 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#
 

Dernier

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 

Dernier (20)

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 

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/