7

Some lambda terms, such as the church number 3: (f x -> (f (f (f x)))), are easily typeable on the simply typed lambda calculus. Others, such as pred, (a b c d e f -> (d (g -> (t -> (t (g e)))) (g -> f) (g -> g))), are known to require more complex systems such as System-F. Some of them aren't typeable on System-F itself, as this zip I posted in another question. As András Kovács observed on the follow-up, that function can be typed in Agda, although the technique he used for doing so isn't trivial.

I have a lot of similarly tricky terms such as nTuple = (k -> (k (b c d -> (b (e -> (c e d)))) (b -> b) (b -> b))), which receives a church number and returns an N-Tuple of that length. I don't know if those terms are typeable. I would like to know:

  1. Some systems seems to ban many "desirable" terms, while others bans less of those. What is the property of a system that determines if it is more accepting or more restricting?

  2. Is there any type system in which arbitrary lambda terms are typeable?

  3. Is there any general technique/algorithm to find the types of those expressions in such system?

MaiaVictor
  • 4,127
  • 1
  • 17
  • 33
  • 1
    Some systems seem to ban many "desirable" terms, while others ban less of those. Yes, type systems are a trade off. In an untyped system (e.g. JavaScript, untyped Scheme, etc.) you can write any "incorrect" program. The onus of writing "correct" programs is on the programmer. A type system removes this onus by disallowing certain "incorrect" expressions. However, type systems also disallow certain "correct" expressions in favor of simplicity. As type systems become more powerful, they disallow fewer "correct" expressions but they also become more complicated. – Aadit M Shah Jul 01 '15 at 19:01
  • 1
    @AaditMShah: I'll come out and say that if you can't type your term in dependent type theory, there's little reason to believe that it is correct by any criteria. Type theory is expressive enough to be a foundation for mathematics in general; and by what means could we accept any argument about a program's correctness if not by mathematical reasoning? –  Jul 01 '15 at 21:03
  • @AndrásKovács does that mean there is probably a type for any of my "useful" terms, or that those "useful" terms are under some sense "wrong"? –  Jul 01 '15 at 21:54
  • 2
    In general, if they're total then there should be a type for them. There are some esoteric exceptions to this (for example, no total language can implement its own interpreter, by a version of Gödel's second incompleteness theorem), but I believe it's a fair general rule. –  Jul 01 '15 at 22:04
  • 2
    @AaditMShah your example is easily typeable even in Haskell, and there's a package for it. –  Jul 02 '15 at 06:33
  • 1
    @AndrásKovács Today I learned something new. Thank you for proving me wrong. =) – Aadit M Shah Jul 02 '15 at 07:10
  • You ask four questions, one in the title and three in the body. Please focus on one. As for the question in the title, no, because the set of all total recursive functions is not enumerable. – Raphael Jul 14 '15 at 21:52
  • That's quite a broad question here, but I think http://cs.stackexchange.com/questions/2638/does-there-exist-a-turing-complete-typed-lambda-calculus/2639#2639 should cover it. – Gilles 'SO- stop being evil' Jul 14 '15 at 22:23
  • @Raphael The answer to the title is “yes”. If it was changed to “type system that assigns a type to all halting terms and only halting terms”, it would still be “yes”. If it was changed to “decidable type system that assigns a type to all halting terms and only halting terms”, it would be “no”. – Gilles 'SO- stop being evil' Jul 14 '15 at 22:25
  • @Gilles Right, thanks for clearing that up. (I think semi-decidability is enough to make the answer "no", isn't it?) – Raphael Jul 15 '15 at 05:22

0 Answers0