12 ms·
Why Haskell Is Worth Learning
- dschiptsov 14y agoThat complex function will turn out to be not all that complex at all; it can be written as just three simple functions composed together! -- Why this requires to learn Haskell, instead of ML or Scheme or Erlang?
- prg318 14y agoThe skill of breaking down large functions into smaller simple functions is a common skill of programming and should be practiced in all languages (C, Java, Python, etc). I'm not really sure from the article what I am supposed to gain by learning Haskell. I'm not debating the opinion that Haskell is great language to learn, but the benefits of learning the language were not clear to me after reading the article. Does anyone care to elaborate?
- deleted 14y ago[deleted]
- deleted 14y ago[deleted]
- jerf 14y ago"The skill of breaking down large functions into smaller simple functions is a common skill of programming and should be practiced in all languages (C, Java, Python, etc)" Haskell will show you that when you thought you broke your code down into small functions in those languages, you were wrong in ways you currently can't even see and they're still shot through with duplication and mixing of concerns. This is really the core of the "it changes how you program"; the environments you mention are so full of conflation of IO and mutation and state that you don't even see it, because it's just the way it is. Haskell will ungently pry those apart for you, if you stick around long enough to actually become proficient. You can take this back into other programming languages where this separation is not enforced, but I'm not convinced you can learn it where it is not enforced. The feedback cycle is so direct in Haskell ("Type Error: ...") and so diffuse in other languages (two months later "Aw crap, I should have isolated IO from non-IO better..."). (Oh you think that last parenthetical is a joke? Ha! I wish.)
- prg318 14y agoThank you (and jochu and pilgrim689) for elaborating on this. I hope to take the plunge at some point and learn Haskell! It seems like an interesting perspective on programming.
- xaa 14y agoLearning Haskell taught me that mutation and state are good things, present both in the fundamental nature of computers and the real world. Haskell's attempts to eliminate state entirely results in a profound increase in complexity. For me, learning Haskell was like visiting a third-world country: enlightening, very different, but ultimately I leave feeling very grateful that I'm not a permanent resident. All in all, I would recommend the experience.
- papsosouid 14y agoIt doesn't sound like you actually did learn haskell. Haskell does not in any way make any attempt to eliminate state, and the idea that it does is absurd. Why would the language ship with a module called "State" if it were trying to eliminate state?
- rafcavallaro 14y agoSubstitute "treat like a pariah" for "eliminate" and you're good to go!
- ibotty 14y agono state in haskell? not in my haskell. state is usually made explicit, yes. there is a state monad because of a reason...
- nightski 14y agoSo obviously you were not very enlightened because it makes no such attempts.
- jvranish 14y agoThose are all great languages. Haskell by no means has a monopoly on mind expanding features. But I think that the enforced purity of Haskell along with laziness and the powerful type system is a particularly brain twisting mix.
- alberich 14y agoI believe this too. Presuming that functional programming is a good thing, Haskell is a great way to learn it. It will force you to operate in a functional way all the time, thus speeding up your learning process.
- klrr 14y agoI'm no expert, but I think Haskell is the most practical of the non-practical languages.
- deleted 14y ago[deleted]
- maxbaroi 14y ago(define compose (f g) (lambda (x) (f (g x)))) What if f is a function of n-arity (define compose (f g) (lambda (x) (f . (g x)))) If g is n-arity (define compose (f g) (lambda (x) (f (g . x)))) I gave them all the same name because naming things is hard.
- Surio 14y agoRelevant points on Haskell, from another discussion, and sort of echoes my own thoughts: http://news.ycombinator.com/item?id=5314701 http://news.ycombinator.com/item?id=5314701 http://news.ycombinator.com/item?id=5314507 http://news.ycombinator.com/item?id=5314507
- octo_t 14y agoAt university the very first language we are taught is Haskell. Lots of people had never programmed before, in anything and everyone managed fine. Nothing scary at all, no need for an understanding of category theory or anything. Monads are (fairly) simple things that just have a really bad reputation, partly the fault of the haskell docs which make them seem complex. Firstly: Functors are things we can map over in a logical way; thats it. Monads are just a fancy way of saying "side-effects might happen here" (obviously not in all cases, but its fair enough for most uses - things like the Maybe Monad are not side effects)
- redman25 14y agoI'm curious what school you went to, there can't be a lot of universities that teach Haskell?
- octo_t 14y agoImperial College London, I believe the Oxford also teach Haskell to first year CS students.
- Ramp_ 14y agoGlasgow University teaches Haskell to 2nd year students.
- wting 14y agoUniversity of Texas at Austin teaches Haskell to 2nd year students in a required course: CS 337 - Theory in Programming Practice. Programming Languages is also taught in Haskell, but it's an optional course and languages varies by professor.
- Millennium 14y agoI was told to learn me a Haskell for great good. Is that not enough for people anymore?
- papsosouid 14y agoLYAH is a good introduction, and is probably enough for a lot of people. Real world haskell adds more practical real world examples, and some people would benefit from reading it also.
- bobajett 14y agoI started with LYAH loved the first 6 chapters. Got bogged down on the 7th because it was more abstract. Now Im reading both LYAH and Real World Haskell and reading both makes a great combination. If I get bogged down in one the other keeps my momentum going.
- dkhenry 14y agoI am no Haskell expert, so I might be wrong on this, but is that code right ? I would imagine the fourth line should read isIfOfInterest (CIf cond _ _ _) = not (null (listify isFooIdent cond)) not isIfOfInterest (CIf cond _ _ _) = not (null (listify fooIdent cond))
- pestaa 14y agoYou are correct. The nice thing is that this mistake would have been caught compile-time.
- lolcraft 14y agoYou mean, "identifier not found"... ?
- pestaa 14y agoExactly. Ever tried running PHP, Ruby or Python code with an undefined variable somewhere? It works flawlessly... for a minute... an hour... or a month... and then it suddenly hits you out of the blue.
- nandemo 14y agoThe bad thing is that people still write blog posts containing uncompiled code.
- minimax 14y agoI was thinking about this the other day and I think it generalizes beyond any specific language. I'm pretty sure every time I have learned a new programming language I came away a better programmer. Different programming languages (and their standard libraries) suggest that you approach problems in different ways, and that has real cognitive benefits. I was actually trying to think if there was ever a case where I had spent time learning a language (or library) that didn't pay some sort of dividend in terms of increasing my skill as a programmer.
- tmoertel 14y agoThe point about learning Haskell in particular is that it's a way different different language. It's a single language that gives you exposure to a lot of new ideas: purity, laziness, modern type systems, functors, monads, monoids, etc.
- solistice 14y agoThe massive difference though gives people like me, who've never done anything like Haskell before and do not properly comprehend it some real trouble though. It's similar to assembler. At first, you don't understand how the code works, how the logic is implemented, and everything just seems strange. Then you start looking at it as seperate commands to the processor and suddenly you understand. Sudenlly MOV r1,0x90 start: MOV A,#0x04 INC A DJNZ r1,start makes sense to you. Sorry, I started fantasizing about Assembly again, my actual question was: "If you could find a metaphor that describes how Haskell works with Data, what'd be that metaphor?"
- epsylon 14y agoAll of these exist or can be implemented in other major functional languages.
- bad_user 14y agoThere's not much value in learning programming languages that are similar. If you learn Ruby, you already know pretty much everything there is to know about Python. If you learn Java, you already know much about C#. The only real value you can get out of learning new mainstream languages is from learning the architecture of popular libraries. Like when I was inspired a few years ago to do database migrations after I played around with Rails. So you end up learning from the libraries written in those languages, not the languages themselves. It isn't a bad outcome, especially since learning a new language that's similar to something you already know becomes second nature and doesn't take too long. It takes me something like 2 weeks to learn a new language. Haskell is on a whole new level though. I don't know Haskell, but in the last couple of months I've been building stuff with Scala and lots of functional programming related idioms, both for personal stuff and for our startup and I've learned more than I learned in the last 5 years. There's lots of good stuff to learn in the Scala ecosystem, like how to build rock solid pieces of functionality with referential transparency, how to work with Futures/Promise, how to do concurrency with shared-transactional memory, how to do non-blocking and safe I/O using Iteratees, how functional data-structures are designed and so on. Of course, Scala is tainted by its hybrid and JVM-related nature. It's much too easy to cheat if it's easier than alternatives that are referentially transparent and even if your interface is pure, that interface is probably wrapping something which isn't pure. In practice it works great for building stuff, but unfortunately I'll have to take the plunge and learn Haskell to be able to take my knowledge to the next level. One example where Scala falls short is in its implementation of lazy data structures. You see, even though Scala does have really good lazy data structures, it cheats here and there because it makes sense to do so ... like for instance a Stream is a lazy list and it does behave lazily, except when it doesn't. sort() on a lazy stream is actually implemented eagerly, which means algorithms using sort() will not have the complexity characteristics of lazy algorithms. There's nothing stopping one from implementing a lazy sort() in Scala, but it's probably not going to have any benefits so people don't do that. That's actually the reason why I want to learn Haskell, because the best implementations for lazy data-structures and algorithms are written in Haskell. Many idioms that people use now in Scala or in other languages have been used in Haskell since years ago. Like Iteratees or type-classes.
- kreek 14y agoI investigated Haskell for a while and as long as I didn't try to add any libs it was fun. However once I started using cabal to try and manage dependencies all hell broke loose. Obviously it takes a while to get it right (looking at you SBT and Ruby gems) but Haskell has been around forever.
- papsosouid 14y agoI'm writing 3 different web apps, plus some command line tools in haskell. I have been working on these projects for a year now, and I've never seen any cabal problems that aren't typical problems that occur with any package manager (trying to install conflicting modules). $ ghc-pkg list | wc -l 182
- tel 14y agoI felt that way up until last week! I somehow felt I was special, that cabal-hellfires had burnt a ring around me. Then next thing I knew I had a 4 page cabal conflict problem and had to just toast .ghc and .cabal and start over. It's a real problem.
- carterschonwald 14y agouse Cabal-Dev! Also the next major release of cabal should have a lot of the cabal-dev machinery baked in. Theres also active brain storming by GHC dev folks on how to make things better on the compiler side too.
- papsosouid 14y agoYour response makes it sound like you just had a simple problem like you get with any language, and followed bad advice on solving it based on the assumption that "cabal is just bad and you have to do this". The big give away is that you didn't need to delete your .cabal directory, advice to do so is coming from someone who doesn't know the basics of how cabal works. It is just storing downloaded sources, all deleting it accomplishes is making you re-download stuff for no reason. The installed packages are in your .ghc directory. Cabal is no more broken than cpan.
- cletus 14y agoI have to admit that I'm really on the fence about Haskell. My major gripe with this point I think is point (3). Haskell has (IMHO) gone down a similar road to Scala. Scala has literally tied itself into knots to make statically typesafe collections (amongst other things). I see parallels with Haskell (maintaining functionality purity but dealing with the "outside world" through monads). I'm not saying this is wrong. What I am saying is that the gap between making something 99% consistent and 100% consistent is often huge in terms of complexity. This is why I think the so-called mixed paradigm languages (Python, Ruby, even C#) have done so well since you can use these programming models while still writing easy-to-understand imperative code. This is also why I'm so bullish on the future of Go. Someone wrote a book called Learning Go that tells you most of what you need to know and you can knock that out in an afternoon. Go has a good model for parallel programming and a simple syntax. It has made the choice of simplicity over completeness (eg no "generics"). The net effect is that Haskell will never be mainstream (IMHO) because it's too complex whereas Go probably will be because it's incredibly simple. We've had complex functional languages (eg Lisp) for decades. Yet they haven't gone mainstream. You have to ask yourself why. Some pride themselves in using something so esoteric. Others attribute the lack of popularity to poor marketing or bad timing. The answer is (again, IMHO) is that simplicity matters. Now it should be noted that we're talking about perceived simplicity. You can write multithreaded code in Java, C or C++ but getting it right is incredibly hard yet it can appear simple. The goal of any language I think should be to narrow or eliminate the gap between perceived simplicity and actual simplicity. IMHO Go does a remarkably good job of this. FWIW Python and Go also play nice with C. It's true functional programming does change the way you think but I think writing idiomatic Python or Ruby will get you much the same benefit at much lower cost.
- tikhonj 14y agoHaskell is also very simple--not from an implementation standpoint but from a semantics standpoint. Having polymorphism with no sub-typing (and no casting) is conceptually simple and easy to work with. Parametric polymorphism (like Java's generics but simpler and less horrible) is actually an extremely simple concept. The difficulty comes from a) implementing it in a stupid way after the fact (cough Java) or b) having sub-typing. Neither is necessary! In this day and age, semantics are far more important than implementation. You can fit Haskell's evaluation rules and its typing rules on one page. Haskell's syntax is also very simple and consistent. It has fewer constructs than most imperative languages--fewer constructs than anything short of Lisp. It just also happens to be much more flexible than other languages. Moreover, much of Haskell's syntax is very transparent syntax sugar. You can easily desguar it in your head. It makes code nicer to read but does not add any real complexity because it trivially maps to a bunch of simple function calls. Most of Haskell is a very transparent layer over a typed lambda calculus. Lambda calculus is basically one of the simplest possible constructs. Ignoring the type system for a moment, it has literally three concepts: functions, variables and application. We then throw in some very straight-forward extensions like numbers, add a bit of syntax sugar and a type system. The type system is also surprisingly simple. It has to be, for the inference to work! It's also very consistent in the way that is almost unique to mathematics. Consistency is pretty important. This is where I shall bring up the "Simple Made Easy"[1] talk. It comes up a lot in these discussions, for a reason: most people mix the two up. I don't agree with all the points in the talk, but the core message is completely correct and very valuable. [1]: http://www.infoq.com/presentations/Simple-Made-Easy http://www.infoq.com/presentations/Simple-Made-Easy Simplicity is valuable. And Haskell, for all its being hard to learn, is simple. IO is a great example here. Monads are difficult to learn, granted. But they are not complex. Rather, they are abstract. In fact, monads are extremely simple; the actual difficulty is twofold: it's not immediately obvious why they matter and they're too abstract to permit any analogies. Ultimately, a monad in Haskell is just any type with three simple functions that behave consistently--it's just an interface. Go is not particularly simple; rather, it's easy. It's familiar. The syntax is more arbitrary, but it is C-like. The built-in constructs like loops are more complex and arbitrary (Haskell, after all, has no built-in iteration at all), but hey, it's C-like. The exposed features? Again, fairly arbitrary. That's how I would sum up Go's design: arbitrary. And mostly C-like. Where C itself is pretty arbitrary. Especially from a semantics standpoint. Essentially, Go has whatever the designers felt like adding. Just look at all the different ways you can write a for-loop! Or the fact that you have a loop at all. Haskell, on the other hand, has a deep and elegant underlying theory which ensures that different parts of the language are all consistent. Haskell is much less arbitrary. Most of the features naturally go together. Many are just generalizations or facets of the same concept. Even the complicated, advanced features like "type families" or "GASDTs" are just fairly natural extensions of Haskell's basic concepts. It's very much akin to mathematical ideas, which have an elegance and consistency eluding most other languages. Here's a particular example of how the features fit together: algebraic data types. Haskell essentially has two fundamental ways to create data types: you can combine fields into a record (like a struct) or you can have a choice (a tagged or disjoint union). The really neat bit? These aren't arbitrary--they're actually deeply related. In fact, they're duals of each other. Having both makes the most sense. It also gives you a much better way to signal errors. In Go, for whatever reason, errors are essentially built into the language as an implicit tuple. However, in practice, you either have a result or an error. If you have an error, the result is meaningless; if you have a result, you shouldn't have any error! So it makes much more sense to represent errors as a variant, a choice--a sum type. This lets Haskell avoid baking in error handling into the language, making it simpler. Haskell is as mixed-paradigm as the languages you listed. Those languages are imperative with some weak support for functional programming. Haskell is functional with some weak support for imperative programming. It's the same idea, inverted. Except Haskell can also support things like non-deterministic and logic programming. It's just that, for some reason, when people say "mixed-paradigm" what they really mean is "imperative with some functional support" and never "functional with some imperative support". Sure, Haskell's syntax for mutable structures is awkward. But have you seen C#'s or Python's or even Go's syntax for functional programming? Compared to Haskell, it's just as awkward! And Haskell's "syntax" for mutable constructs is just a library; it can be improved. It just turns out that imperative features aren't useful enough for experienced Haskellers to warrant the improved syntax. (Also GHC sucks at optimizing sufficiently complex imperative code, I gather.) There's a nice example of what you can do on Lennart Augustss's blog[2]. He essentially embedded a very C-like language into Haskell without using macros. So it's certainly possible, just not worth it. [2]: http://augustss.blogspot.com/2007/08/programming-in-c-ummm-haskell-heres.html http://augustss.blogspot.com/2007/08/programming-in-c-ummm-h... So yes, perhaps Haskell will never be popular. But that's a social issue. It is not an issue of the language's qualities. And it shouldn't stop you from using Haskell. At your startupt. Hint, hint.
- tel 14y agoHaskell is just playing a different game. Clojure/Scala/F# might also be playing that game or something somewhat like it, but until you start to realize just how relaxing pure, statically checked code is you're coding in a tar pit. Even the IO system is better because you think of it as nothing more than a way to manipulate and combine a kind of pure data corresponding to sequences of "real world" actions.
- MrMan 14y agoI will learn Haskell if you people will stop spamming me about it.
- ibotty 14y agoi don't read any page about ruby. why do you read everything about haskell?
- tikhonj 14y agoI dunno, even on here it gets less press than Python, Ruby or even Go. It's just since most people already know imperative programming well, the Python/Ruby/Go articles that get upvoted tend to be a bit more advanced. Will you stop using Python? Or would you not learn Python?
- pmk 14y agoHaskell implements functional programming that's truly pure of side effects, strongly statically typed with inference and overloading, and lazily evaluated. There's really nothing else out there that's like it. Programming in Haskell is really difficult, but I've learned to appreciate that this is because Haskell programmers are forced to fix more of their bugs at compilation time, rather than later when code is deployed. Don't make the mistake of conflating Haskell (pure, typed, and lazy) with Lisp (impure, untyped, eager), ML, Scala, or anything else out there. It's truly a unique experience, and it's one that every good programmer must know.
- freshhawk 14y agoI love haskell but I wish there was less blogging about why everyone else should use it and more building things that will make people want to use it. The community is extraordinarily friendly to beginners, as long as you only count how they interact with beginners. If you count having resources that allow beginners to figure something out without having to ask then they are extraordinarily unfriendly. If I find a potentially interesting library on hackage I'm no longer surprised to find it has no documentation at all, certainly no usage documentation or explanation of what it actually does or what it should be used for. Just code and autogenerated API docs. I'm surprised if there is anything that would allow me to actually use it. I'm not often surprised this way. That and the wild west, "not invented here", multiple incompatible implementations of new ideas used in different important libraries (iteratees at the moment). Not trying to throw blame around of course, but people probably don't need your "I have a new metaphor for monads" blog post or an argument for why it's worth learning. People need more posts like the 24 Days of Hackage(http://ocharles.org.uk/blog/ http://ocharles.org.uk/blog/) series and the Real World Haskell book and they need some brave person to try and convince those amazing library developers to standardize on an imperfect solution a little sooner and for a little longer (only in public of course).
- tel 14y agoI think generally the advice to beginners is to ignore most of Hackage and focus on the Haskell platform—which is frankly kind of terrible advice. It's intended to avoid things like the enumerator/iteratee/conduit/pipes madness and focus on a stable library interface, but almost all of the fun is being developed on the bleeding edge of Hackage. I'd agree completely that this is a deficiency with the Haskell community, but I also don't see it stopping until there's a larger critical mass of new users—a chicken and egg problem, certainly.
- freshhawk 14y agoI don't think it's a chicken and egg problem quite. It's true that the types of people that do these kinds of things arrive when you have critical mass, but that's just statistics. I think you can recruit people to do this kind of thing, or at least encourage people to do so, but it would require community management and such which doesn't really exist in the haskell community. If I felt cruel I would nominate dons to do it, since it's so easy to want to give more work to the guy who's already doing a ridiculous amount of good work.
- gfodor 14y agoI'm at the point where I have zero interest in learning new languages to "expand my mind" unless they have very obvious application to problems I am facing right now. For example, Matlab sucks, and scientific computing sucks in most other languages, so learning Julia is probably worth my time. What is Haskell's killer domain? Meta-programming C code seems more than a little esoteric for it to be worth the massive investment of time and opportunity cost of curling up with a Haskell book and a REPL in my free time. I spent a lot of time learning Clojure, which is an amazing language, but here I am years later and I still reach into my toolbox of imperative languages (C, Ruby, Matlab, Java) to solve any "real" problems quickly, efficiently, and in the most straightforward (and understandable by mere mortals) way. If I want to expand my mind (towards the end of building software) I will fire up Coursera and study math or algorithms, things which are, imho, more widely applicable, timeless, and have a "bigger bang for the buck" for self-study than learning another programming language.
- oscilloscope 14y agoAlgebras? I learned some basic Haskell: the type system and algebraic data types. When I went to study group theory, I found it came easily. Now I'm working my way towards lie algebra. The cool thing about Haskell is for any particular algebra, there's often a good tutorial or literate Haskell implementation. Picking the right algebra for the problem domain can save you a lot of computation, but once you understand how it works you're always free to drop back to an imperative language to do the computation. Haskell makes it easy to play around and discover deep relationships, but it does require being an a mind-expanding mood to get to a comfortable place.
- lazydon 14y ago
- axilmar 14y agoDoes FP really help reasoning about programs in a better way? I have a hard time believing that, since what ever logical errors I do in programs can easily manifest themselves in FP programs as well. Having tried a little Haskell myself, the same bugs that I have in imperative code also appear in functional code, albeit with a different form.