Skip to content
Back to the collection

Java Generics are Turing Complete

Radu Grigore

2016 · arXiv

Read the paper
HN score
0
Mentions
12
Readers
11
Months
11
What’s in a score?

From the abstract

This paper describes a reduction from the halting problem of Turing machines to subtype checking in Java. It follows that subtype checking in Java is undecidable, which answers a question posed by Kennedy and Pierce in 2007. It also follows that Java's type checker can recognize any recursive language, which improves a result of Gil and Levy from 2016. The latter point is illustrated by a parser generator for fluent interfaces.

Metadata: arXiv. Abstracts retain their original authors’ rights.

In the conversation

Original HN comments, with labels from simple text rules. A label describes the whole comment and may miss context or irony. Read the discussion to make up your own mind. About the labels

12 selected excerpts · 12 total mentions

ynik
Neutral mention · rule
Turing completeness doesn't have to come from a single feature, it often comes from a combination of features. e.g. the interaction between subtyping (e.g. inheritance) and generics (with variance) is tricky: https://www.cis.upenn.edu/~bcpierce/papers/variance.pdf It can be highly nontrivial to tell if a language actually has a Turing complete type system: the 2007 Kennedy&Pierce paper made it likely that java was turing complete; but it took until 2016 until it was finally proven that to be turing complete (https://arxiv.org/abs/1605.05274). > What would it take a for a type system to NOT become Turing complete? An analysis of all possible interactions between all features in the type system, building a formal proof that the type system is not turing complete. This is not really realistic for the style of complex generic type systems that programmers are now used to, it would need to be a vastly simpler language.
bhouston
Neutral mention · rule
> Rust’s type system ended up being Turing-complete anyway. It seems like it fell into the same trap as C++ templates: it’s an accidental programming language in a programming language, but with way worse syntax. Most anything in software can easily end up Turing-complete though. It isn't that high of a bar unfortunately. I think most mature type and template systems end up as Turing-complete. To single out Rust for this is to ignore that this is just standard fare for mature typing systems. TypeScript's types are Turing complete: https://github.com/microsoft/TypeScript/issues/14833 Python's type hints are Turing complete: https://arxiv.org/abs/2208.14755 Java generics are Turing complete: https://arxiv.org/abs/1605.05274
bmc7505
Neutral mention · rule
Types in TS are Turing Complete [1], so any static analysis you build ontop of that language is bound to be unsound or undecidable. You could argue this rarely occurs in practice, but I would prefer a type system that is incomplete but sound and decidable. Incidentally, this issue also affects Java, which is both unsound [2] and undecidable [3]. Kotlin does have a fairly complicated subtyping relation [4], which has caused similar issues in languages like Scala [5], however whether the same issue affects languages based on mixed use-site and declaration-site variance like Kotlin is still an open question and requires further investigation. [1]: https://github.com/microsoft/TypeScript/issues/14833 [2]: https://io.livecode.ch/learn/namin/unsound [3]: https://arxiv.org/abs/1605.05274 [4]: https://kotlinlang.org/spec/type-system.html#subtyping [5]: https://arxiv.org/abs/1908.05294
wk_end
Neutral mention · rule
> but it's not true of generics in most languages not sure how true that is. * TypeScript: https://github.com/microsoft/TypeScript/issues/14833 * Rust: https://sdleffler.github.io/RustTypeSystemTuringComplete/ * Haskell (GHC): https://mail.haskell.org/pipermail/haskell/2006-August/01835... * Scala: https://michid.wordpress.com/2010/01/29/scala-type-level-enc... * Java: https://arxiv.org/abs/1605.05274
jcelerier
Neutral mention · rule
> There are exceptions of course for a definition of "exceptions" being "virtually all languages with a non-trivial static type system and non-zero userbase" as shown in your link. Java (https://arxiv.org/abs/1605.05274), C# (https://blog.hediet.de/post/how-to-stress-the-csharp-compile...), Scala (https://michid.wordpress.com/2010/01/29/scala-type-level-enc...), Haskell, Rust (https://sdleffler.github.io/RustTypeSystemTuringComplete/), Typescript (https://github.com/Microsoft/TypeScript/issues/14833) ... Having a type system with generics and not being turing-complete as a result is the exception, not the rule.
panny
Neutral mention · rule
Java Generics are Turing complete. [1] You can produce an entire program inside a Java API. The API is part of the implementation in Java. The criteria for copyright is originality and creativity. [2] It doesn't matter if understanding hashcodes is hard. Mathematical functions are not copyrightable. [3] Whereas elegant vs inelegant APIs demonstrate there is creativity in the API design process. Google engineer Bob Lee agreed [4] >Q. Would you say that designing APIs is a creative activity? >THE WITNESS: Yes, absolutely. Copyrights are not patents. Clean room designs are perfectly legal. [5] Google could have avoided the entire fight, but Google failed to prove they did a…
Read the full comment
clean room design. Quite the opposite, Oracle was able to show that Google made direct copies of the code. The evidence at trial showed that Google decompiled at least eight Java files and copied them each in their entirety. [6] [1] https://arxiv.org/pdf/1605.05274.pdf [2] https://copyright.uslegal.com/enumerated-categories-of-copyr... [3] https://www.copyright.gov/circs/circ31.pdf [4] http://www.groklaw.net/pdf3/OraGoogle-398(Ex3).pdf [5] https://en.wikipedia.org/wiki/Clean_room_design [6] http://www.groklaw.net/pdf3/OraGoogle-1123.pdf
Jaxan
Neutral mention · rule
A related result is that java generics are Turing complete [1]. As a result you can write programs which will loop the type checker! I was at the popl presentation where the author showed this result. He gave a demo where he defined a Turing program and a tape, and then let the type checker give the answer (halting with 1 will succeed type checking, halting with 0 will give a type error). This was a lot of fun. [1] https://arxiv.org/pdf/1605.05274.pdf
unholiness
Neutral mention · rule
Turing complete systems are highly capable, and thus, are harder to prove anything about. The halting problem notwithstanding, there's first the "there are things that don't halt" problem: that is, you can write a valid TypeScript program that will never finish compiling. Now, this really shouldn't be an issue unless someone is deliberately abusive. Java's generic types are also Turing complete[0], and it hasn't been problematic. Just because an abusive program exists doesn't mean it will be written. But who am I kidding... this is the JavaScript community. I'll give it 2 weeks until someone releases a framework allowing you to write functions that don't compile unless their input is a prime number. [0] https://arxiv.org/pdf/1605.05274.pdf

Keep following the thread.

More in Other research

More from the same topics.