3 ms·
I'm no mathematician and I was able to easily understand the premise and follow most of the reasoning (some Scala idiosyncrasies went above my head at the last
by pygy_ 15y ago
I'm no mathematician and I was able to easily understand the premise and follow most of the reasoning (some Scala idiosyncrasies went above my head at the last step where he adds syntactic sugar).
The proof is as basic as can be. If it helps, you can substitute types with sets, "being a subtype" with "being included in", imagine Venn diagrams and procede from there visually.
Edit: see the first half of this article for an illustration of what I mean.
http://www.ams.org/feature-column/fcarc-venn http://www.ams.org/feature-column/fcarc-venn "Topolgy of Venn Diagrams"
- wccrawford 15y agoRead the first example. Easy to understand, even if you don't know much scala, yes? Now read the final code. Can you really make heads or tails of that without reading his whole post? Imagine if the whole program was as arcane as that. Someone else will have to maintain that code eventually, and without his magic post to clarify it, it's insanely hard to read. I would end up writing tests to determine exactly what it did and didn't do, then rewrite it from scratch so I (and everyone after me) could read it.
- pygy_ 15y ago1) Who says that this is meant for production code? It is first and foremost a demonstration of the power and flexibility of the Scala type system. 2) I wouldn't mind actually using it in production if the library was written as a litterate program including the whole blog post. Once you wrap your head around the concept, the code becomes clear (and is so simple that you can understand it doesn't have any bug to be fixed anyway)
- Uchikoma 15y agoThe important sentence is: "Obviously it would be nicer if Scala supported union types as primitives, but at least this construction shows that the Scala compiler has all the information it needs to be able to do that. " Which means the compiler can do this but need syntactic sugar to make it more accessible.