r/ProgrammingLanguages • u/[deleted] • May 14 '21
Resource Counterexamples in Type Systems
http://counterexamples.org13
u/cxzuk May 14 '21
I'm a bit weak on type systems, really enjoying this and the corner cases and clear details. This is a great resource, thanks for sharing!
16
u/crassest-Crassius May 14 '21
This is brain porn, no more and no less. Excellent, concise and well-expressed in several languages!
8
u/hou32hou May 15 '21
Reading the counter-examples caused me to hesitate further whether I should include mutations in my language or not
4
u/Uncaffeinated 1subml, polysubml, cubiml May 15 '21
Mutations are fine by themselves. You just have to be careful not to sneak in contradictory assumptions elsewhere.
1
u/hou32hou May 15 '21
Do you have examples of contradictory assumptions?
4
u/Uncaffeinated 1subml, polysubml, cubiml May 15 '21
There's a bunch listed on the site. A classic example is polymorphism and the value restriction. However, there are also issues with e.g. compilers assuming that values don't change when optimizing pattern matches.
5
3
u/umlcat May 15 '21
I accidentally made counterexamples in my pet project, but was very useful experience, allows to detect bugs, even ones that may pass undetected undee non error conditions.
2
4
u/matthieum May 15 '21
I was quite intrigued by the heading that counter-examples would provide programs that corrupt memory in Rust, and thought I would find gold. Without an index mapping language to counter-example, I actually had to skim the whole thing, and I was disappointed by what I found to be honest :(
There is one outstanding issue in Rust Type System -- on this site -- and this is 30. Nearly-universal quantification.
All the others seem to confound Language and Implementation. For example, 6. Eventually, Nothing:
In the Rust language,
loop {}has the never type (!) as it always diverging.Up until LLVM 12, there was no way to instruct LLVM not to consider that loop without observable effects may not terminate.
Therefore, until https://github.com/rust-lang/rust/pull/81451, rustc would miscompile programs with
loop { }or equivalent.Okay, great, the compiler has a bug. Everybody agrees it's a compiler bug too. That's not near as remotely interesting as when the language is fundamentally unsound though... I felt cheated :(