170 points · by mietek · 13y ago · 87 comments
1. Where do you use automatic differentiation? I've done machine learning, signal processing, etc., but never even heard of it until now. Why should I care? Your pitch should include that (especially when the wikipedia article doesn't really provide real use cases).
2. What's special about lenses? I tried reading http://www.haskellforall.com/2013/05/program-imperatively-us... but there's no summary of what this is about, and from the first paragraphs it seems like a Haskell workaround for setters and immutability. Again, I feel like the community is not pitching these things correctly. People like me start reading, don't understand the point of it all, and give up.
And I can go on... What is the target audience of these features (or Haskell itself)? Is it people like me, or is it more hardware validation engineers, automatic proof system developers, database people?
EDIT: If anyone is interested, edwardkmett has replied to me in http://www.reddit.com/r/haskell/comments/1k3fq7/what_are_som...
Users of dynamically typed languages talk about "fighting" the type system—and yes, there can be a bit of that, espencially early on—but once you become a proficient Haskell user, you learn to use the type system and the guarantees provided you by the language to enforce properties you want to be true, and thereby effectively use the compiler as a pre-emptive, exhaustive testing mechanism for the correctness of your code. A good Haskell programmer will set up types in such a way that the logic errors of their program will be translated into type errors, so an incorrect program cannot even be compiled.
So, I suppose, the target audience of Haskell is people for whom program correctness is a stronger motivation than, say, the speed gains of C/C++ or the development time increases of dynamic languages[1] or the like. (EDIT: To avoid the charge of excessive language zealotry, I should clarify that I don't think program correctness is the overriding factor in all cases, and consequently I don't think Haskell is the correct tool in all situations, as well.)
[1]: I personally don't find Haskell particularly slow to develop in—in fact, I find it much faster and easier to develop in than the dynamic languages I know—but I do use it literally daily, and, to be frank, a new programmer will likely find it tricky and confusing until familiarity sets in. Similarly, Haskell can—used correctly—have spectacular performance, sometimes matching C and beating out C++, but again, it takes experience and understanding to milk the best performance out of Haskell.
Then you can compose these lenses together and retain these properties. You can also pick lenses which operate with different multiplicities from 0 to infinity. Finally, you can use their seemless connection to object isomorphisms to create a very general interface for working with various kinds of "similar" objects in Haskell.
At the end of the day you can write a first-class lens which represents getting and setting over a set of parameterized Map keys deeply inside of a stateful computation, mapping over anything that looks like a string, and viewing/modifying it as decoded JSON.
obj . ix "aKey" . each . _Object . ix "3" . _Number .~ 4
might modify a record in a type like this IsString s => SomeState { obj :: Map s s }
where the string values of the Map have a JSON schema like {"1" ..., "2" ..., "3": <aNumber> } for o in obj["aKey"]: o["3"] = 4
The OP:s point was that lenses seem like a workaround for Haskell's lack of mutable state.EDIT: What I'm meaning is that to show lenses unique benefits, you would have to come up with an example in which the code is more succinct than the equivalent code implemented without lenses in another language.
Lenses let you think of a JSON-encoded string as an actual JSON string without ever explicitly doing the decoding due to their close connection to Isomorphisms and "partial Isomorphisms" (called, non-standardly, Prisms here).
Furthermore, lenses don't really have anything to do with mutable state—they just happened to form a convenient wrapper for using the State monad, but that's really a coincidence.
Succinctness is difficult to grasp. It'd be a good exercise that I'm not going to try in an HN comment to even translate the entirety of the concept embedded in that one line into, say, Python. It would start to feel like an XPath implementation.
(Edit: Also, as usual, the whole typesafe thing. That Python fragment can lead to runtime errors. The Haskell one never does—using it inappropriately is simply impossible.)
It's the experience of grubbing around in unfamiliar libraries (in my case a database lib and a visualization lib), not knowing much Haskell and struggling to get the damn thing to compile. The very first time I got the types to line up, the program ran and I had my timeseries graph from the database.
This is a magical, life changing experience.
Any other language I've used would have been many iterations of, "this is null", "you passed a string where it was supposed to be a list of strings" (looking at you python)! Now that I know it's possible, I much prefer to do my thinking up front, and know that there's a compiler out there that's got my back :-)
I tend to prefer dynamic typing these days as a lot of what I do feels easier to achieve when I can throw something together to test ideas without thinking about types, and then refine the idea based on actually using a cobbled together prototype, and I feel static typing often got in the way of that.
Especially coupled with Smalltalk style runtime inspection / modification on error (e.g. for Ruby I use "pry" which lets me drop into a shell anywhere in the program and modify or inspect state and then continue execution).
In particular, type-driven-development is wonderful. You can write light, compiler-checked specifications of code you haven't bothered to write yet and see if your logic all typechecks even without implementation. I can run through lots of ideas that way very quickly since the only thing I have to produce is the high-level type skeleton of my program.
Then I just go through and implement it all.
It's a lot like test driven development except that your executable tests are much more lightweight and carry a strong sense of the logic of your program. If your tests don't hang together, you'll find out eventually. If your types don't hang together, your compiler tells you immediately.
When do you determine you've gotten it to execute correctly? Achievement Unlocked: You Can Stop Testing Now?
How is that any different from Haskell? You think that merely lining up types and having it compile determines that it also "executes correctly"? There are also algorithmic and other mistakes.
Many Haskell libraries are focused on allowing you to define entities that correspond to your desired semantics, while many libs in OO-languages are just about constructing the correct object-graph that happens to give you the result you want.
Haskell's type system and syntax are richer in ways which I think makes it possible to unambiguously describe more results in code in ways which makes unit testing certain aspects superfluous. I'm skeptical of most "you don't have to test" claims, but I can see more of a case for reducing the need for testing with Haskell than with many other statically-typed languages.
Have you tried Lisp? I've always found that to be a really friendly environment when it comes to working out why something doesn't work. :)
Edit: that said, it still has one. GHCi is a nice Repl.
I'm just not sure what it's doing on the HN front page, and I find the contents of the post lacking in terms of convincing outsiders into a favourable opinion on the language.
There's nothing wrong with such a comment on /r/haskell, but I think it's out of place here. I realize the fact that it is voted up to the front page proves that many people think otherwise, but when I last checked, people were allowed to voice contrary opinions on the Internet.
Besides features of the haskell language itself, I was wondering if there were any libraries in haskell that stood out as being unique--not a sinatra-like web interface for example. Something like erlang's mnesia or rails for ruby, maybe, or hazelcast for java or any frameworks (for web programming or whatever), that were truly a step above comparable libraries or don't even have a non-Haskell equivalent. Something that once you use it, you hate not using it in other projects.
All this stuff sounds cool. Is it fast and scalable?
Most people eventually complain that high-performance Haskell doesn't resemble the Haskell we're taught to program. This is less and less true as things like iteratee-based I/O and really advanced libraries like bytestring and text displace older facilities, but it is still something to think about. Haskell tends to perform well by sacrificing lots of memory. This is why you see discussion about "space leaks" rather than "memory leaks" and whatnot. There are a lot of ways to address the problems that come up, but you need to have a strong handle on the way Haskell works before you can accurately diagnose and treat the problem. This is a significant barrier to using Haskell in production. It doesn't take long to acquire the expertise to throw Ruby into production. The road with Haskell is a bit longer and a bit more taxing, because it's so very foreign.
I agree with your comment, but these sentences are a bit weird. Usually space leaks occur where you should have evaluated things strictly rather than lazily or the other way around. It's a bug (with the amount of memory that we have now).
But I don't agree that Haskell tends to perform well by sacrificing lots of memory. For example, you mention the iteratee proposals/libraries. Iteratees are well-known to be fast and can be used to do constant-space I/O. Bytestrings are much more performant than their precursor (lists of characters, aka String), but are also not demanding in terms of memory use.
Not more so than any other garbage-collected language
Concurrency has always been possible to do with Ruby just fine. There's just been a limit on system level threads until 1.9 (and there still is a limitation in terms of the interpreter lock). There's on the other hand nothing that has ever stopped us from multi-process concurrency, including using shared memory (though with the caveat that Ruby won't let us put Ruby objects there).
Haskell allows you to run "green" or userspace threads in the millions, similar to what erlang and scala (akka) provide (and F#), with dispatcher designed to run i nthose numbers. So it's something like Celluloid, but I don't know how many people have used celluloid in production, in haskell the runtime's been well documented (Simon Marlow's oreilly book) and tested in heavily loaded systems.
But still there is a lot of traps, a lot of situations where high-level nature of the language makes writing an efficient implementation harder and obscures that (unless you're an expert in GHC internals). For example, darcs is known for accidental problems on large projects (though I can't corroborate this from my experience), maybe of algorithmic nature.
From my experience: choosing a right library matters much. Choosing one numeric library from cabal instead of another had drastically boosted performance of a number-crushing task for a crypto course. A simple program using HXT (xml processing library with beautiful mind-boggling API based on arrows) has exploded on a large input.
Also, I am interested pretty much what's the largest site written in Yesod/Happstack/Snap and how well they behave there (these frameworks' benchmarks are mostly good and promising).
[1] - http://benchmarksgame.alioth.debian.org/u32/haskell.php