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/