Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Haskell: The Confusing Parts (rsmw.net)
50 points by fogus on Oct 5, 2009 | hide | past | favorite | 24 comments


"Lisp is known for hating infix notation, but Haskell embraces it. ... There are ten levels of operator precedence (0 through 9)"

This is one of the things I prefer about Lisp. Am I the only one who still has to stop and think occasionally about what binds more tightly with what when reading and writing code in languages with many precedence levels? Never a problem in a Lisp.


I haven't noticed it being a problem in Haskell. Most of Haskell's weird operators are either uncommon enough so that everybody uses parentheses with them (such as bitwise (.|.) and (.&.) and so on), common enough that you don't forget (but (&&) and (||) are the two I always forget, and occasionally some people don't use parentheses with them), or weird and common but it's very hard to use them incorrectly without getting a compile error ((.) and ($) and (>>=) and (<$>) and (<*>) and (++) and (:) and (&&&) and so on). I don't think most of the operators in the last list would be usable without static type checking.

In particular, operators like ($) and (.) are hugely beneficial and the latter's existence is one of the main reasons people like Haskell's syntax.


I appreciate both, honestly. Lisp achieves a great deal through purity of syntax, but that sort of thing was never Haskell's goal. Personally, I almost never think about how precedences compare; instead you learn a Haskell coding style that support the syntactic tricks allowed by operator precedence. A pretty common one goes something like this:

  forM [1..] $ \n -> do
    a <- monadicAction1 n
    b <- monadicAction2 a
    return b
Which is sort of ugly from a Lisp point of view, but I think it's a great trick enabled by having $ be an ultra-low precedence sequencing combinator. It looks like a Ruby block almost, but has zero extra syntax and very clear semantics.


Misses laziness, which is arguably the most confusing part.


This page immediately crashes Firefox 3.5.3 on Snow Leopard!


Ditto. Like, immediately and hard.

I had a look at the source in Safari and there's little contentious on there. No JavaScript, Flash, or whatever. The only oddity is some horrifically formatted HTML with the end of tags coming on the next line every time - could merely that be killing FF though?


Checks out fine with 3.5.3 on WinXP, but I'd point the finger at that poorly-formatted HTML.


Also works fine with 3.5.3 on Ubuntu 9.04.


The HTML is autogenerated by my Markdown program. Sorry it looks weird. Anyway, the CSS (in particular, the use of the Hoefler Text font) is what brings Gecko to its knees.


Really? That's weird. I've used Hoefler Text in mockups before (though ultimately decided against it). Useful to know though!


Using Pandoc like a good Haskell user, eh?



Same here. Pretty big bug. Had to load up Safari.

Someone report the bug, I'm too lazy.


The article itself was perhaps a little disappointing --- it mostly discussed syntax rather than semantics that I find confusing. It did link to http://blog.sigfpe.com/2006/08/you-could-have-invented-monad..., though, and I am finding that very enlightening.


I still find the most confusing aspect of Haskell to be that it makes me feel like I have to think like a mathematician rather than a programmer.


not sure why this is here, it's not really worth reading yet.


As he says in the first part, feel free to discuss what parts of Haskell are confusing to _you_, and then it can be made by the community, rather than just by him.


Also does not tackle monads.


Monads are nothing special. "They" somehow acquired some stigma of being "difficult", which caused people to write tutorials to help others understand them. Then the proliferation of tutorials led people to believe that they are difficult to understand, which caused people to write more tutorials. And here we are today, where people avoid a programming language because they think there is some incredibly hard concept they have to master but will never be smart enough to understand.

Anyway, the Typeclassopedia is recommended reading: http://www.haskell.org/haskellwiki/Typeclassopedia

Once you understand the relationship between functions, applicative functors, monads, and arrows, everything will make sense -- they are all the same thing.

(The next issue is, "why would I want this kind of abstraction", but that's best for you to decide on your own.)


I don't believe tutorials are the right way to figure out monads. For one thing, they aren't as extremely important as they're made out to be, people have just latched on to the name. If you really want to understand monads you have to actually try to write code using them, and struggle through it.


I understand monads just fine. I would like to see a readable explanation of the exact syntactic transformation of the 'do' notation to the actual function that the monad is to logically return the wrapped application of.


If I'm reading that right, you want to see how do-notation is desugared? The best explanation I could find was http://metafoo.co.uk/practical-monads.txt The two sections "Binding lines together" and "Lines that don't return values" explain it nicely.


Deliberately. Please note the links to two existing (and very good) monad tutorials... The last thing the Haskell community needs is another lackluster one.


I had one semester of Haskell in school and thought I knew a thing or two about it. The last thing I attempted in Haskell was the game of blackjack. The two big problems there were user input, and the random numbers that were used to shuffle the deck of cards. Very quickly I had to combine two monads in my code to get anything going and I found it very confusing. It seemed like my entire program had become tainted with the non functional aspects. The tutorials didn't really clear things up either, I'm trying Scala now and that at least seems like it will let me pull in the functional pieces where I can use them.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: