Concept
Dependent type
Journey Statuslearning Tags
Consider the function which returns the first item of a list.
Elaboration
Simple types can say "this is a list" but not "this is a list of length 5".
Dependent types extend Curry-Howard correspondence to predicate logic:
- becomes (dependent function).
- becomes (dependent pair).
Types can mention values, so preconditions become part of the signature, enforced by the compiler.
Example
Consider the function which returns the first item of a list.
Based on the signature, this must either:
Crash on empty lists.
Return .
Lie.
-> With dependent types, the precondition is the caller's proof obligation-no runtime check, no partiality.
-> A safe head function on vectors:
-> The type guarantees length .