Skip to content
scrambled
Programming Language Theory Concept

Dependent type

JourneyProgramming Language Theory Statuslearning Tags
  • logic
  • type theory

Consider the texthead 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 head function which returns the first item of a list.

    head:Lista→a

    Based on the signature, this must either:

    • Crash on empty lists.

    • Return Maybea.

    • Lie.

      -> With dependent types, the precondition is the caller's proof obligation-no runtime check, no partiality.

      -> A safe head function on vectors:

      head:Vec(n+1)a→a

      -> The type guarantees length ≥1.