Reimplementing “git clone” in Haskell from the bottom up (2013)
stefan.saasen.me
stefan.saasen.me
Even though I'm not very familiar with Haskell, I find this code much more concise and easy to follow compared to the original git-clone implementation in C. Though perhaps that's more down to the author's coding style?
So much Haskell pedagogy wants you to write a compiler or a parser or ... whereas this article is taking you through a solution. And whaddyaknow -- Haskell comes across as gorgeous, elegant, compact, and highly comprehensible.
When I show a FIX server or REST API written in Haskell to a non-Haskeller coworker (ie everyone else :) ), with minimal explanation they're getting what's going on. I look forward to many more "Haskell-in-anger" articles to show the world how fantastic it is to work with.
Languages like Agda can do this even more impressively. You can do stuff like write
if_then_else_ : Bool -> a -> a -> a
And you can split up the "if", "then", and "else" and put the arguments where the underscores are.This was hard to understand.
Simply put, my assertion is that it is the accompanying prose and diagrams that truly make the code easy to understand. Not its implementation language.
I would love to say that my terrible sentence above illustrates that prose is not a panacea. Well, I think I can claim that. I can not claim it was intentional. :)
Haskell does help somewhat, in that it's offers you a lot of flexibility in how to structure your program. So you can tailor your program to your explanation. (Knuth's literate programming tools help bring those capabilities and more to more conventional languages.)
[ foo ]
bar !
! baz
etc.It also supports precedence parsing.
I don't Smalltalk can do all of these.
Smalltalk, unlike Agda, can probably omit the spacing around operators, though, while Agda can't :)
But the if_then_else_ example is basically smalltalk equivalant - although I suspect Agda will be able to do without the angle brackets that Smalltalk often needs in these cases.
There's an interesting example in the manual ( http://maude.cs.uiuc.edu/maude1/manual/maude-manual-html/mau... ) where juxtaposition is defined as an operation, specifically:
op __ : Bits Bits -> Bits [assoc] .
The underscores are placeholders for arguments, just like in Agda, but there's no name defined! Since `0` and `1` are defined as constructors of `Bit` (which is a sub-type of `Bits`) this will parse values like `0101010` as `Bits`. sortBy (comparing salary) employees
The grammar is not as close to English, but close enough to understand. sortBy (compare `on` salary) employeers (λ x → x + x) (fib 2000)
will evaluate `fib 2000` twice. Agda programs can also be compiled to Haskell, in which case they would have Haskell's evaluation strategy, which is generally call-by-need (and so would share the result of fib 2000 above.)In a pure, terminating language like Agda evaluation is "confluent" which means that CBV and CBN evaluations are identical.
It would also be a nice exercise to implement all of the internet RFCs, such as an email server, etcetera in Haskell. That's still a bit lacking. And it would be very useful if it existed, IMHO.
[1] http://www.reddit.com/r/programming/comments/1cgi2x/reimplem...
It uses ASCII-art boxes, lines, etc. as input (which you can draw using Emacs's artist-mode, for example)