Running a Startup on Haskell
infoq.com
infoq.com
(Retrieved by setting my User-Agent to that of an iPad, which causes infoq to serve up a <video> tag.)
- Haskell has exceptionally thorough type inference (almost all type declarations are optional).
- anything impure (e.g. involving an I/O) is typed as such
- the types are easier to read and tend to give a good idea of what the function in question is doing
- much more complicated types are readable
- idioms like Monads lead to a lot of code that is much more abstract and generic than anything I've seen in Java. There are tons of library functions that can work on lists, or IO things, or parsers, or random values...
Some things that I found particularly cool in Haskell:
- functions (and even constants!) can be polymorphic on their return type. The function read, for example, always takes in a String but returns whatever type you happen to need.
- You can easily express things like a "list of list": [[a]]. I don't even know how to begin writing a function like join in Java. (On lists, join takes a list of lists of something and flattens it.)Overall, I've found Haskell's type system to be much more useful, and much less of a burden, than Java's.
That said, I'm just a college student with limited experience with either language. I've used Java more than Haskell but I've been using the latter more recently; I've never used C#.
So I think to like Haskell, you have to truly believe that more abstraction is better. It's very much a mathematician's language.
The thing is, when writing code, I don't want to write a math paper. When I'm done, I want it to be as smooth and easy to read and as obvious as an article in the New Yorker.
Your metaphor is apt; if your code is going to be that smooth, you need to learn Haskell to the same extent you know English for the New Yorker. The Internet suggests that the New Yorker is written for a "10th grade reading level", but of course the average American has between an 8th or 9th grade level.
It does get easier with practice to read the language, and what's left after that is whatever core difficult the code being expressed has regardless of the target language, the essential difficulty. Haskell can hardly be blamed for bringing that to the foreground where other languages stuff it in the background.
so in java a simple way would be to initialize an l = arrayList and then do a foreach on each list in the list of the lists and foreach element in each list add it to the arrayList l. Not as elegant, much more how instead of what but 4 noisy lines max.
C# has list.selectMany( _ => _ ) for that.
Though you probably wouldn't want to do use that approach for performance reasons.
I'd love for somebody to convince me why a Haskell approach to web frameworks is superior to Python/PHP/Ruby/JS beyond the usual "it's a matter of taste" argument.
Edit: And for Haskell, achieving needed performance can be quite tricky with regard to its laziness.
But Snap is driven by enumerators/iteratees (via the enumerator package), which make it much easier to do fast near-constant space IO.
I have built a web application that uses Snap to query large (parse) treebanks, and it was easy to make it performant.
No .Net in there, though.
At the moment, my answer is "Not yet, but ask again in a year." There are tons of interesting things happening in the area of letting you have "performance, correctness, rapid development and prototyping, pick three", but they're still in the early phases yet.
Next, the author mentions about several limitations that C# has and that Haskell has a much better approach.
So, why use C#? Why not only use Haskell?
The client-side code is written in C# because the .net APIs for Office are the easiest to deal with.
I'd like to use this "property-based testing" he stressed.
Slides are here: http://bos.github.com/strange-loop-2011/talk/talk.html#%281%...
Navigation uses keyboard arrows.
He had a similar/same talk about a month prior and here is the video on Vimeo if you're not a fan of InfoQ's format:
http://vimeo.com/27192476 (Bryan O'Sullivan - Building Solid Distributed Applications with Haskell and Riak)