312 points · by kakashi19 · 8y ago · 132 comments
https://www.manning.com/books/type-driven-development-with-i...
But most of the work you'd be doing to write quicksort is writing the machinery for structurally recursive sorting, which a lot of tutorials write not because you have to, but because it's a very good exercise for learning how to write total functions that are recursive in a way DT systems can prove totality on.
Most of these tools are in the contrib library (and the book mentions this). For example the preorder interface you need:
https://github.com/idris-lang/Idris-dev/blob/master/libs/con...
If you are interested in the implementation, you can read more about it from one of the authors: http://davidchristiansen.dk/tutorials/nbe/
This brings into focus a question I've had for a long time: Why this gap, and especially in this direction? E.g. in aerodynamics we had Bernoulli's principle for a couple of hundred years before we could build airplanes, which depend on it. In formal language theory we had lambda calculus, Turing's universality results, etc. decades before we had Lisp and Fortran.
We often see the difficulty of building a practice to exploit theory.
So it seems very strange to me that we are able to write / plug together literally world-spanning software systems -- which do have bugs but fact work correctly nearly all the time. But we can't easily well-type even simple algorithms with extremely well understood properties.
Why this huge gap, in this direction?
Software is a bit different from architecture in that partial failures tend to work and can be refined around repeatedly (a partially failed building tends to rip itself apart, partial failures in software can linger for years and only cease when their dependencies fault out). People are just more amenable to altering their processes, products and lives around bad software.
I think dependent typing reveals to us, to some extent, what a house of cards we truly have built for ourselves.
Network stacks, databases etc. that correctly handle trillions of interactions, some of them adversarial, have indeed been "refined around [their failures] repeatedly" and have gotten pretty robust along the way.
On the other hand useful formal accounts of their behavior (distributed, highly parallel, loosely coupled, asynchronous) seem far, far way.
It would be helpful to have an account of approximation to formal properties, especially if that can help us understand how repair and refactoring can lead to progressively better approximations.
Perhaps the house of cards that is revealed is formal methods not software.
But they have also incorrectly handled a similar order of magnitude of transactions! Routing failures and issues that people troubleshoot around, misconfigurations and bugs, and simple electromechanical glitches exist in the real world and they're not some kind of zebra, you can force them by pining a server.
Our networking systems "mostly work" because they're persistent, and because (interestingly) the difference between a perfectly coordinated networking system and a purely chaotic networking system with random traffic is actually rather small compared to other domains.
> On the other hand useful formal accounts of their behavior (distributed, highly parallel, loosely coupled, asynchronous) seem far, far way.
Generally what makes a difference between a "robust" program and a brittle program that simply falls over is how much of its own failure it attempts to take into account. Even bad models of self-failure (pre-OTP erlang, for example) are better than no model at all.
> Perhaps the house of cards that is revealed is formal methods not software.
Given that almost no one applies formal methods and dependent typing is by no means a part of that discipline, I'm not sure it's fair to draw those comparisons in this conversation.
Dependent Typing is not formal methods, nor is it verifcation. It's code that allows for automated reasoning. It's closer to the machinery of formal methods, like datalog or an SMT solver.
Can anyone recommend a book (or whatever) that introduces the aspects of type theory relevant to a would-be language designer?
[1] https://www.amazon.com/Types-Programming-Languages-MIT-Press...
I assume you know some math/set theory and some Haskell, otherwise you may want to work though some of the chapters in Real World Haskell first.
Oh and put the videos at 1.25× or 1.5× otherwise you will fall asleep.
Or even if you did, but your types were [i: i%4 == 0] or [i: (i+1)%2 == 1] or whatever, you'd have to write proofs that they types were compatible. Even some simple things are just not worth it.
One appealing aspect of dependent types is that they let you decouple validation of inputs from the function calls themselves, while still disallowing passing wrong inputs to the function by mistake.
There are difficulties with dependent types, but having to go all in can be avoided via a shift in culture.
I suspect it’s taken a while for the theory behind dependent types to become widespread enough for some enterprising hacker or grad student to make a useable language for them (e.g. Idris). Even if a new theory comes along it takes time for appropriate metaphors and methods of using them to be created and disseminated.
Though does computing the dependent types at compile time take more process.
No, it's not really that bad. But almost. I really suggest you play with Idris some; what you can do with it is brilliant, for simple tasks. For complicated tasks, like the fully general propositions you need for library functions, it can get much more complicated than the code itself.
qsort :: Ord a => [a] -> [a]
qsort [] = []
qsort (p:xs) = qsort (filter (< p) xs) ++ [p] ++ qsort (filter (>= p) xs)
and let me know how it goes, if you will. That's when I gave up on Idris.Is there a companion book detailing the ugly downsides of dependent types and how to avoid them, one step at a time?
There's this Reddit answer from two years ago, and the subsequent comments https://www.reddit.com/r/haskell/comments/3zc81v/tradeoffs_o...
It's not really clear why you'd want a book about the downsides of a quite recent development in practically usable programming models. Is it just because you are a hater?
Adopting something purely on it's merits is a bad idea, but nobody ever writes the book about a language/paradigm's downsides. I'm pretty sure that was the joke, but I might be off.
Indeed. One can argue that books like "optimizing X" or "secure X" are about ways to easily write slow or insecure code in X, but this is somewhat narrow. Is there never enough demand for a broader book on downsides of X?
Both of those implementations are very honest about their shortcomings, and nearly every talk and blogpost for them mentions you can't yet use this in many industrial contexts.
It's very difficult to see this as anything but the usual distate for PL theory that constantly swirls around this community. If the author didn't intend to associate a post with that, then they've done it by accident.
This space reserved for JELLY STAINS!How does Idris solve this problem when compiling to JavaScript?
There is no problem compiling dependent (or static) types to JaveScript, as the type checks are done at compile time, and don’t require any support from the JavaScript runtime.
Also Library Genesis is amazing: http://libgen.io/search.php?req=knuth
It's everything I dreamed of when I was a kid. I used to spend hours at the local library scouring through crummy "Learn C++ in 24 hours" type books.
http://custodians.online/ is worth a read too.
So firstly I agree, $40 seems like a lot. I personally couldn’t justify it at the moment. Particularly when the reproduction cost is nearly zero.
But $40 also doesn’t seem like a lot to pay for a book that will probably not sell more than a few thousand copies. Most likely revenue generated won’t fully cover the time and effort required to create such a book.
But... the author is also a professor at MIT. I feel like if this work wasn’t somewhat publicly funded, it really should have been.
In the end, I’m left morally confused. But it feels like something is wrong in the world when a book like this is available only to a select few, when for the same capital outlay it could be available to everybody.
Only to a select few? For $40? The book costs less than most console video games.
This is in the western world... imagine how many people in the world can’t afford this book. On a global scale... very few people could afford this book (or a 40USD video game).
It makes me kind of sad that you’d so casually suggest that this is not the case. Makes me think that perhaps people in the tech world don’t have a great understanding of how poor many people are...
Also if you were to somehow poll everyone reading this and ask "Did you buy this book?" you'd get some number, x. But if the book were priced at $5, then $5y would be much greater than $40x.
I bought a bamboo fineline pencil for $50 the other day. It's a tool that will serve me for at least a year. It's unclear whether this book would.
I want work like this to exist, and for the author to be rewarded for it. But ultimately, in an era when words are infinitely and instantaneously copyable, the economic value of words seems to drop.
Given the choice between stealing knowledge and not stealing knowledge, when you wouldn't have paid for it anyway, where's the harm?
This is published by MIT press, but the author (Friedman) is a professor at Indiana University.
Even though watching that, I probably think I understand Dependent Types then I'll read the Little Typer and discover my intuition was wrong like when I read the Seasoned Schemer and thought I already knew everything there was to know about the concept of higher order functions.
At least local libraries actually buy the book to support the authors.
Carpenters and other craftspeople who earn far less than the denizens of Hacker News buy whatever they need to further their business. They don't steal others' tools.
You act as if I have $40. Would it surprise you to learn my power was cut off within the last few months?
Another point: "Stealing" implies something was lost. The words are still there, even if I have copied them.
The game industry and the iPhone app store have proven that when you price something closer to $1, it will generate exponentially more revenue than $40.
There was a lot of energy put behind those words, and I expect to get paid a modest sum for it. The means of knowledge transmission aren't free, just as you discovered that while a river wants to be free, the mechanism of converting it to useful energy and transmitting it to you isn't free.
This may be true for mass-market, high-volume products like mobile games, (although even there the real money is in in-app purchases). It is not necessarily true for special-interest, low-volume products like this book. In order for it to be true, you need to assume that over 40 times as many people will buy the book at $1 as will buy it at $40. Frankly, the audience for this book is so narrow that I suspect that they would eventually get three times as many free downloads as they will get sales at $40.
Passive verbs are weak (Mistakes were made, versus I made a mistake). You failed to pay your electric bill.