Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've been Learning Me A Haskell For Great Good because I thought it looked interesting. Of course, I'm completely sold on the idea that functional programming will end world hunger, bring about world peace, send crows to peck out the eyes of my enemies, bring many young women with good birthing hips to my beck and call, double my order for free, and just generally improve my life in every way, shape, and form with zero drawbacks whatsoever.

I am pretty well-versed in imperative paradigms. I learned Java and C++ before I dropped out of university, after which I taught myself Python. My problem is that even beginner tutorials get way far over my head pretty quickly and I'm not sure if there's something specific I'm missing or not understanding or if I just can't quite wrap my head around the whole paradigm just yet. I made it all the way to Section 4.7 of the Haskell Tutorial for C Programmers before I couldn't understand it anymore.

Am I missing something foundational (like those last two years of university)? Or should I just keep going slowly and hopefully it will click? Put another way, what information would help me best bridge the gap between an imperative paradigm and a functional paradigm?

share|improve this question

migrated from stackoverflow.com Sep 14 '11 at 6:17

This question came from our site for professional and enthusiast programmers.

1  
"good birthing hips"? –  duffymo Sep 14 '11 at 2:38
4  
You should have learned how to bend your mind around the unknown in your first year in the university. As well as all the math you'd need (set theory, some basic logic). You must be well equipped already - just try harder. –  SK-logic Sep 14 '11 at 8:07
2  
    
A nice recent article about the topic is functional thinking for the imperative mind –  faif Aug 16 '12 at 17:11
    
I like your sense of humor - but it does point out one thing: there's no real-world reason you are doing this :) –  dbracey Aug 16 '12 at 18:16

11 Answers 11

It's rare to understand any new material the first time you see it. Everyone is ignorant when they start a new topic, be it functional programming or vegetarian cooking.

The people who master difficult to acquire skills are the ones that can press through the "I'm too stupid" anxiety and doggedly work until they achieve some level of mastery.

We can't all be Donald Knuth, but you shouldn't give up on first reading. You probably fell the first day you tried to walk. Look at you now!

share|improve this answer
2  
+1 for "we can't all be Donald Knuth.."!! –  yati sagade Sep 14 '11 at 13:14
2  
+1 for "fell the first day you tried to walk" My 14 month old's been walking for 4 months and just blackened his eye in a fall yesterday :) –  Michael Sep 14 '11 at 13:28

Nan-in, a Japanese master during the Meiji era (1868-1912), received a university professor who came to inquire about Zen.

Nan-in served tea. He poured his visitor's cup full, and then kept on pouring.

The professor watched the overflow until he no longer could restrain himself. "It is overfull. No more will go in!"

"Like this cup," Nan-in said, "you are full of your own opinions and speculations. How can I show you Zen unless you first empty your cup?"

http://www.ashidakim.com/zenkoans/1acupoftea.html

The hardest thing about learning FP is forgetting what you think you "know". It might be true, but not in this context. Everything is different, so you need to start from the very beginning.

If you know C++, and you want to learn Java, you compare both languages all the time, and this works fine. It's the same with natural languages: If you know English and want to learn Spanish, it's okay to compare both languages all the time, as they follow the same indo-germanic paradigm. But if you want to learn something fundamental different, like Japanese, or Haskell, you have to "unlearn" first. You won't make real progress until you stop comparing.

share|improve this answer
1  
+1 for "unlearn". Very true, both in natural as well as programming languages. –  Dan Burton Sep 14 '11 at 18:17
    
+1 Hah! I always thought this koan was nonsense, but woah... it truly does apply to learning Haskell! You must forget a lot of stuff you consider natural from imperative languages before Haskell starts to "click". –  Andres F. Aug 16 '12 at 21:27

Many people will tell you that language immersion is the best way to learn a spoken language and I think there is a case to be made that the same is true for programming languages. Keep at it! Pure functional programming is quite different from main-stream programming so you shouldn't expect to "get it" in a short period of time.

Some specific advice? The folks in the #haskell IRC channel have really helped me get over certain conceptual humps as I continue to learn Haskell.

share|improve this answer

More specifics would help. What are you having trouble understanding? I ask because Haskell is not only a purely functional language, but also one with a very sophisticated type system. Are you having trouble with the functional parts, or the type system? Grokking both at the same time might be overloading you.

Depending on what you're getting stuck on, it might be worth learning Lisp first. While Lisp defies categorization (it's not purely functional, but can be; it's not OO, but can be; etc), it is by default dynamically typed. Hence, you can master functional programming concepts with Lisp independent of a type system, and then move on to languages like Haskell or Scala when you're ready to tackle type signatures, type constructors, monads, and the like.

share|improve this answer
    
Accidentally gave a +1, instead of a -1. Please stop talking about the type system if you obviously have no clue what it is and how helpful it is. –  Ingo Sep 14 '11 at 9:38

FP requires much more abstract thinking to understand as it has more powerful abstraction and works at higher level of abstraction that imperative programming. So I would suggest try to improve your abstract thinking (it will take some time, but when you finally get it you will feel this amazing sensation in your head that you probably never had before). Go slowly through the book if you don't understand some abstract concepts try to go through them more then once or ask questions in here or SO for people to help you understand those concepts.

share|improve this answer

Seconding Landei, I want to add:

From my own experience I know that an imperative programmer automatically tries to map a programming problem into a problem of how to modify variables, store intermediate results, etc. hence onto an already very low abstraction level.

It takes some time until oneself notices how inappropriate this is in the context of pure FP. There you ask what a certain function IS, not what it DOES.

share|improve this answer

There is nothing you have to learn. Haskell is just hard.

In order to get Haskell, your brain will have to get seriously rewired, keep trying until that happens.

The one thing you might want to learn is recursion, but you can just do that by writing some Haskell.

share|improve this answer
    
Well, all those while loops that one writes in imperative languages are also a form of recursion. So, nothing new to learn, just a different way of looking at it. –  Giorgio Feb 25 at 18:10

I used to lecture on Haskell and related stuff.

The most important idea IMHO is that functional programming is about data and transformations. A lot of people forget to mention this in their rush to get to complex stuff (and the complex stuff is just about getting more control and power over the basic stuff). Nothing mystical!

I'd also recommend getting up to speed on unix pipes and tools first, eg think about how you'd handle (slightly contrived) examples like the following. Convert the output of ps into a shortlist of memory-hogging processes then into a page of html links with a summary of the info plus a file link into /proc/nnn etc

If you get this, then stuff like "unwords . map reverse . filter (\w -> length w > 3) . words" will not be a mystery

share|improve this answer
    
\w -> length w > 3 is quite noisy, why not just (> 3) . length? ;) –  FredOverflow Sep 14 '11 at 18:23
    
not . null . drop 3, perhaps? –  sreservoir Jun 26 '13 at 2:51

I think your problem is that a lot of the FP literature is the product of academia, and so the classical academic style of language is used - inventing new terms and making them complex so that everything can be worded very precisely and unambiguously.

You'll just have to keep with it until you get used to the funny language. Its kinda like calculus - its easy to teach and understand when you talk about slopes, areas, rates and such for the simpler things - concepts most people become familiar with at a young age and which have everyday relevance. Start talking about calculus, integrals and derivatives and people will get lost even though you are talking about exactly the same things - however a more precise language is necessary to move on to more advanced concepts.

Think about how many people cite calculus as a example of something with no everyday usage, but wouldn't dream to make the same statement about speeds, slopes, areas and such - despite the fact that they are identical.

I reach this conclusion based on where you get stuck in the guide for C programmers.

Stick with it. The beautiful thing about the human brain is that provided there is positive/negative stimulus it will learn anyway - even if you don't understand it or consciously think about it.

share|improve this answer

According to the wikipedia:

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data

To program functionally you basically need two know two things:

  • Everything is a constant. Nothing is mutable.
  • No side effects: your functions must only use the arguments you passed, no globals or anything.

Your program just

output = f(input)

So if you pick your favorite programming language and never assign a variable twice, you essentially programming functionally.

share|improve this answer

For me, haskell just didn't work. I tried two times to 'get' haskell, but I never did.

First when I learned Common Lisp (using the book Land of lisp which uses functional programming), I finally got it. I later moved to Clojure which works even better.

For me, simplicity is very important, and functional programming is a simplistic paradigm. Haskell with it's syntax and enforcing pure functions, isn't. That makes haskell inadequate for me as a functional language.

Learning functional programming is therefore preferably not done in haskell, since the syntax is always in the way.

share|improve this answer
    
I agree Haskell is hard, but out of curiosity, what do you mean "the syntax is always in the way"? I find purity and laziness are the real difficulties (and of course, Monads, Applicatives, etc.), not so much the syntax. –  Andres F. Nov 13 '11 at 21:23
    
In lisp, you have a list, values and some syntax that changes the interpretation of those lists. With a bit of simplification, that's it. When I say that the syntax is in the way, I mean that it's overly complicated, compared to lisp syntax. –  odyssomay Nov 14 '11 at 21:30
2  
-1, "I don't understand Haskell, therefore no one else can and you shouldn't either". –  dan_waterworth Aug 16 '12 at 18:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.