Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I want to learn haskell? [duplicate]

Tags:

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

like image 437
SigTerm Avatar asked Jul 04 '10 18:07

SigTerm


People also ask

Why is it important to learn Haskell?

Learning Haskell teaches you to think with immutable data Immutability refers to data or objects that can't be modified after creation. Expressions in Haskell are immutable, which makes for effortless refactoring, helps avoid unintended side effects, and makes the code much easier to reason about.

Should I learn Haskell in 2021?

Like many questions like this, the answer is, it depends. If you want to learn Haskell with the intent of using it in a job, it's probably isn't worth it. You'll be better off with Python/C++/Java in that case. There aren't that many companies that widely use Haskell.


8 Answers

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

like image 80
Brian Avatar answered Oct 01 '22 11:10

Brian


A few years ago, 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.

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.

like image 20
3 revs, 2 users 59% Avatar answered Oct 01 '22 11:10

3 revs, 2 users 59%


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.

like image 30
Mark Byers Avatar answered Oct 03 '22 11:10

Mark Byers


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.

like image 27
C. A. McCann Avatar answered Oct 02 '22 11:10

C. A. McCann


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.

like image 22
Amadan Avatar answered Oct 03 '22 11:10

Amadan


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 ;)

like image 21
LeonG Avatar answered Oct 01 '22 11:10

LeonG


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.

like image 44
mb14 Avatar answered Oct 05 '22 11:10

mb14


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.

like image 36
reece Avatar answered Oct 01 '22 11:10

reece