Why should I want to learn haskell?

Possible Duplicate:
Haskell vs. procedural programming in the real world

Few times I heard people saying things like "Every programmer should know Haskell", "You aren't a programmer if you don't know haskell" and so on. However, I'm not exactly sure if I should bother trying to get a brief understanding of that language or not. Playing around with interpreter (to get intuitive understanding of basics) will take at least few days (if not weeks), and I"m not exactly sure if the result will be worth it.

A bit of background (to get idea of my knowledge)
I've started programming as a kid (somewhere between 10 or 13 years ago) with programmable calculator, moved to basic, then onto non-x86 assembly (reimlementing multiplication and division, and writing self-modifying mouse driver was fun), pascal, delphi, now I'm using C++ almost exclusively. Know my way around unix shell, can write software in python and probably in anything (if I have a reference book nearby) that remotely resembles C++ or Pascal (ie blocks, similar flow control, etc). Specialization is 3D programming and shaders. "Fish in the water" with low-level operations (C-style memory allocation, pointers), less comfortable with extremely OOP approach (ie when classes are made for the sake of having classes). Almost completely self-taught. Ie definitely not a newbie, but there are areas where I could improve.

So... what could I possibly gain from studying Haskell at this point? As far as I know, this language is not really widely used, as a result there probably is less libraries it can interface with (as it was with Delphi programming - you can do DirectX programming in delphi, if you really want, but you can't write 3dsmax/maya plugin with it (well, it is probably theoretically possible, but it certainly won't be easy)). I also don't think that I'll be easily able to plug a piece of Haskell code into game engine.

So, what kind of useful knowledge I can get from it?

PS I won't buy "if you learn another language, you'll probably learn something that will be probably useful" argument.


(Surely this is a duplicate question, but I can't find one now.)

You learn it in order to learn pure functional programming, which forces you to do many things in a completely different way. You get a new way of thinking. Programming without state? Programming without effects? Everything is lazy? Crazy type system with type inference? What the hell are monads? Your mind will be repeatedly blown, but in the end you come out with new perspectives/techniques from functional programming that are hard to otherwise pick up without going full-blown Haskell.

The problem with trying to be specific, is that trying to tell a non-Haskeller what they'll learn from Haskell is like trying to explain the color "green" to a blind guy.


A few years ago, a pretty girl in our department decided to study Computer Science part-time. Many people were surprised to discover one of the introductory courses was being taught using Haskell as a/the programming language! Although I didn't have experience with Haskell, I had some background in Lisp and other Functional Programming languages and was able to help her with her exercises.

No, there's no happy end to this story: She dropped out, married somebody else and I haven't seen her in a long time. But I think the anecdote shows how knowledge can be useful when you least expect it.


In more practical terms: You may have noticed that CPU speeds hit a wall some years ago, and now the most practical way to pull more performance from computers is by installing multiple CPUs. Now it so happens that most if not all of the programming languages you know are essentially single tasking, and subject to the Von Neumann bottleneck. An obvious solution is parallel programming, but that can be very painful if the parallel parts of your program end up sharing state, ie memory - and this is most often the case.

It turns out that Functional Programming is a style that allows you to mostly circumvent the problems of parallel programming with shared state. Stated differently, it's fairly easy to write programs in the FP style that are "naturally" thread safe and suitable for parallel processing. Depending on the language, compiler and hardware you may even find (as I recently did) parts of your program running in parallel without ever having done any explicit coding for parallelism.

I'm frequently wrong, but my guess is that Functional Programming will turn out to be one of the hot programming paradigms of the future as parallel programming becomes more important and more difficult. Haskell may not turn out to be the language of choice - my personal favorite is currently Clojure - but it may well be worthwhile to take a look at one or more FP languages.


I also don't think that I'll be easily able to plug a piece of Haskell code into game engine.

If you only want to write 3D game engines then maybe there's not much point in learning Haskell.

If you want to be a well-rounded programmer capable of programming in multiple paradigms and you currently only know C-like languages then it is worth a look.

Every time you learn a new very different language it makes learning the next language easier because you're not just memorizing new syntax, you're also learning different ways of thinking about programming. If you try out a new language and you see some new feature you will more quickly understand it if you can relate it to another feature in a language you already know. The more languages you know the more likely it is that this new feature is similar to something you've seen before.

It's also handy to have many tools available in your toolbox. Some problems are better solved in one language than another. If you have 5 very different types of languages then you can select the best one for each problem. If you know only 2 or 3 very similar languages then some problems will be easy to solve, but others might be more difficult than if you used a language which is better at that specific task.

链接地址: http://www.djcxy.com/p/80854.html

上一篇: 为什么不独立输入?

下一篇: 我为什么要学习haskell?