exintro.lhs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. %include lhs2TeX.fmt
  2. %if anyMath
  3. %format . = ".~"
  4. %format alpha = "\alpha"
  5. %format beta = "\beta"
  6. %format gamma = "\gamma"
  7. %format delta = "\delta"
  8. %format phi = "\phi"
  9. %format psi = "\psi"
  10. %format Set = "\SET"
  11. %format |- = "\vdash"
  12. %format ? = "~{?}"
  13. %format when = "\mathbf{when}"
  14. %endif
  15. %However, when adding meta-variables things get more complicated.
  16. %The convertibility of $A$ and $B$ might now be unknown until some of the meta
  17. %variables have been instantiated.We will give an example illustrating the problem. Given
  18. %the set of natural numbers, |Nat|, and the set of booleans, |Bool|. Given also a function, |F : Bool -> Set|. The problem we consider is checking if the term
  19. %|\g. g 0| has type|((x : F ?) -> F (not x)) -> Nat|
  20. %, where the term |?| is a meta-variable of type |Bool| and |0| is a natural number. We now get the constraints |F ? = Bool|, |F ? = Nat|,
  21. % and |F (not 0) = Nat|. We can now see that we have a problem since |F (not 0)|
  22. % is ill-typed.
  23. When adding meta-variables equality checking gets more complicated, since we cannot
  24. always decide the validity of an equality, and we may be forced to keep it as a
  25. constraint. This is well-known in higher order
  26. unification\cite{huet:unification}: the constraint $?~0 = 0$ has two solutions
  27. $? = \lambda x.x$ and $? = \lambda x.0$. This appears also in type theory with
  28. constraints of the form |F ? = Bool| where $F$ is defined by computation rules.
  29. The fact that we type check modulo yet unsolved constraints can lead to
  30. ill-typed terms.
  31. For instance,
  32. consider the type-checking problem
  33. |\g. g 0:((x : F ?) -> F (not x)) -> Nat|\footnote{The notation |(x:A) -> B x| should be read as $\forall x:A. B ~x$.}
  34. where the term ? is a meta-variable of type |Bool|, |0:Nat|, and |F:Bool->Set| where |F false = Nat| and |F true = Bool|.
  35. First we check that |((x : F ?) -> F (not x)) -> Nat| is a well-formed type, which
  36. generates the constraint |F ? = Bool|, since the term |not x| forces |x| to be
  37. of type |Bool|. Checking |\g.g 0| against the type |((x : F ?) -> F (not x)) -> Nat|
  38. generate then the constraints |F ? = Nat| and then |F (not 0) = Nat|, which contains
  39. an ill-typed term\footnote{In fact we will also get the constraint |Bool = Bool| which is trivially
  40. valid and therefore left out.}.