tags:

views:

826

answers:

8

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 (i.e. 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 (i.e. when classes are made for the sake of having classes). Almost completely self-taught. I.e. 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?

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

+3  A: 

Learning a functional language will be quite a change from what you are used to. So yes, you'll probably going to learn something useful ;)

LeonG
+7  A: 

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.

Mark Byers
+17  A: 

(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.

Brian
BTW, reacting to "crazy type system" — I find Haskell's type system to be the most natural thing imaginable, and it makes me wonder why other languages didn't have such sensible type systems. :-)
ShreevatsaR
@Shreevatsa, If your "wondering" is not rhetorical, then: "other" languages don't have such type systems because they are oriented to the operations carried on during execution (even OO langs), not to the beauty of notation or to relations between concepts that constitute the program.
Pavel Shved
I'm of two minds about type systems. I enjoy the security of strong typing, but I get nervous when a language's type system becomes a language in its own right. If you (or any reader) are/is interested in a language with a deep, capable complex type system, I can recommend Scala. It's like Haskell's type system with Java bolted on as a scripting language.
Carl Smotricz
@Carl Smotricz: *"It's like Haskell's type system with Java bolted on as a scripting language."* ...that's possibly the most terrifying thing I've ever heard. :)
camccann
@Carl, strong typing is not for security, and not for the other shiny trinkets you like to play! It's just in sake of beauty.
Pavel Shved
@Pavel: I was using "security" in a more general sense: It's a matter of my personal safety in programming, i.e. it takes me by the hand and acts as a guard rail to keep me from falling off type-related cliffs. See also: [Security blanket](http://en.wikipedia.org/wiki/Security_blanket) :)
Carl Smotricz
A: 

Functional languages like Haskell are a different way of thinking about a problem. They are useful for learning and teaching data structures and algorithms, as they simplify those kinds of problem.

If you use the STL from C++, that has functional concepts that are similar to Haskell and other languages, so having a grounding in Haskell will help understand how the STL works.

If you use XSL:T to transform XML, that is very functional in its design.

reece
I guess you confused "functional" with "declarative". XSLT doesn't have first-order functions, does it?
Roman Cheplyaka
+3  A: 

There are several things you can get, mainly in the way you think about things. For example, it is interesting to notice what a minimal language is. If you go through SICP (and the same concepts apply to Haskell too), you will notice how you don't need loop syntax at all. You don't need any predefined functions that work on larger structures. You can define pretty much everything you need if you are given a cons constructor/deconstructor, or a way of defining one, and ability to recurse functions. You can define everything else yourself - and it is an interesting exercise to do so. And this is only the tip of the iceberg.

On a more practical level, for example, a couple of weeks ago I was doing OCaml homework and moaning "why doesn't this $%$%# language have call/cc!?!" My mind was blown when I noticed what I was thinking - I would never have missed it if I didn't know what it was, and I wouldn't known what it was if I didn't take a look at Scheme, Haskell, Ruby.

You can find many nice examples at ICFP contest; the one that really wowed me was this entry at this contest. They created a new language inside Haskell to solve their problem.

Amadan
+1 for the language feature that you crave but can't have. Ignorance is a bliss, so learn only one programming language and forget all others. They will taint your mind with ideas of sin but can't use!
trinithis
+9  A: 

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, i.e. 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.

Carl Smotricz
+4  A: 

If 3D programming is your thing, you might be interested in some slides from a talk entitled The Next Mainstream Programming Languages: A Game Developer's Perspective by Tim Sweeney, the founder of Epic and technical director for the Unreal engine. He's spoken on the subject multiple times, and he clearly thinks very highly of Haskell.

camccann
Very interesting, thanks for the link!
Carl Smotricz
A: 

I would say, if it's a chore don't do it. Otherwise start to read this and you should see after 10 mn if you are bored or if you are gripped and can't stop reading it.

mb14