Hacker Newsnew | past | comments | ask | show | jobs | submit | more da3da's commentslogin

I'm curious what advantages you think Haskell has over ML/Ocaml. I'm pretty familiar with OCaml and like it a lot, and Haskell seems to be very similar, but I haven't used it for anything substantive. What benefits, if any, does Haskell have over Ocaml, and is it worth learning if one already knows Ocaml? I know that Haskell has lazy evaluation while Ocaml doesn't, but you can simulate lazy evaluation in Ocaml.


I actually also really love OCaml. It has some truly brilliant features which Haskell lacks like polymorphic variants (and structural sub-typing in general) and a top-notch module system. (Much unlike Haskell's "worst-in-class" module system.)

Haskell does have a bunch of advantages though. A pretty petty one is syntax: Haskell's is simpler, prettier, more consistent and yet more flexible. They're very similar, of course, but I think Haskell gets all the little details right where OCaml often doesn't.

The single biggest advantage Haskell has--more than enough to offset the module system, I think--is typeclasses. Typeclasses subsume many of the uses of modules, but can be entirely inferred. This moves many libraries from being too awkward, inconvenient and ugly to use to being a breeze. A great example is QuickCheck: it's much more pleasant to write property-based tests in Haskell because the type system can infer how to generate inputs from the types. Being able to dispatch based on return type is also very useful for basic abstractions like monads. Beyond this, you can also do neat things like recursive typeclass instances and multi-parameter typeclasses.

Honestly, if I was forced to pick a single Haskell feature as the most important, I would probably choose typeclasses. They're extremely simple and a foundation for so much of Haskell's libraries and features. Most importantly, typeclasses are probably the most obvious way the type system goes from just preventing bugs to actually helping you write code and making the language more expressive, in a way that a dynamically typed language fundamentally cannot replicate.

Laziness in Haskell is not really a big deal. It can make much of your code simpler, but it also makes dealing with some performance issues a bit trickier. It also tends to make all your code more modular; take a look at "Why Functional Programming Matters"[1]. I am personally a fan of having laziness by default, but I think it's ultimately a matter of philosophy.

And philosophy, coincidentally, is another reason to learn Haskell: it takes the underlying ideas of functional programming further than OCaml. In Haskell, everything is functional and even the non-functional bits are defined in terms of functional programming. Many "functional" languages are actually imperative languages which support some functional programming features. OCaml is one of the few that goes beyond this, but there is really a qualitative difference when you go all the way.

Once you know that everything is functional by default, you can move code around with impunity. You on longer have to worry about the order code gets evaluated in or even if it gets evaluated at all. You also worry far less about proper tail calls, which mostly compensates for having to deal with some laziness issues.

Haskell also embraces the philosophy in another way: you tend to operate on functions like data even more than in OCaml. The immediately obvious example is that Haskell has a function composition operator in the Prelude. There is no reason for OCaml to not have this, but--as far as I know--it doesn't. It's an illustration of the philosophical differences between the two languages. On the same note, Haskell also tends to use a whole bunch of other higher-order abstractions like functors and applicatives.

So I think the most compelling difference is ultimately fairly abstract: Haskell just has a different philosophy than OCaml. This ends up reflected in the libraries, language design and common idioms and thus in your code. I think that by itself is a very good reason to learn Haskell even if you know OCaml; and since you do, picking Haskell up will be relatively easy!


Thanks for the awesome reply! I think you've just convinced me to check out Haskell more thoroughly at the next chance I get.

Edit: It's great that you mention OCaml's module system too; my professor probably mentions the benefits of it in just about every lecture.


That was a great reply. I would personally like to hear more about the advantages OCaml has. OCaml was my first foray into functional programming but I was really put off by +., print_int and friends (which you obviously don't need in Haskell). I know about functors but what else is so bad about Haskells module system? The biggest weakness of it I see is the inability to handle recursive imports.


I used to love Ocaml, but it doesn't have the manpower/momentum/excitement that Haskell has (had?)

(IIUC because Ocaml licensing is not very welcome to open source efforts).

I'm very good at picking losers... (Ocaml, D, Factor..)


I think the difference is we all come in contact with writing every day. So literacy is required if you want to get around in the world and if you want to communicate with others. Almost no non-programmers encounter code in their day to day lives. To me it doesn't make since for the majority of people to learn to code, because without practice their skills are just going to atrophy. Why add a ton of new people who can only write shitty code? We already have enough of those, I don't see the reason to add more. Programming well is hard and if you don't spend a lot of time with it you'll never get good.


Over the past week or so I've seen a lot of food and diet related articles make the front page, and in the comments everyone is going on about how great their favorite diet is and how the science proves that it is the most effective way to lose weight. None of these people show any evidence however that their weight loss came from anything other than calories out > calories in. It's refreshing to see at least a few people like yourself who believe otherwise.


No, they are ranked by their peers.


Have you tried using Heisig's "Remembering the Kanji"? I have never tried to learn Japanese, but I have heard very good things about using this book to learn the Kanji.


For anyone using "RTK" I recommend using http://kanji.koohii.com/ . I also recommend that you actually write the kanji out (on paper, or even just tracing it out with your finger in the air) when reviewing, and only consider a kanji remembered when you can render it properly, with the correct stroke order.


I've heard of Heisig, but only recently.

My method for learning kanji was to count the strokes (it's relatively simple to figure the stroke count for any character: http://infohost.nmt.edu/~armiller/japanese/strokeorder.htm) then use that number to look them up in a dictionary.

But everything I looked up was in the context of a sentence, while trying to read a report at work, e.g.


This is why you get a lawyer. So they can explain that almost no one gets anything close to the maximum sentence. See this post for more information http://www.volokh.com/2013/01/16/the-criminal-charges-agains...


You can actually still go in the cockpit on commercial airlines, just not during the flight. Before or after the flight the pilots are usually happy to show you the cockpit.


I think people are willing to take criticism much better when it is phrased in a respectfully way, rather than an "I'm right you're wrong, here let me prove it" perspective. The OP may have been incorrect, but the best way to help him realize this isn't by yelling at him across the internet, but by politely pointing him to the science.


I agree. If OP is incorrect (I say if because I am not making a statement about his correctness) perhaps he was ignorantly incorrect. It's never good to start off with an arrogant, disrespectful tone without asking questions first. Ignorance is not the same as intentional deception.


I agree. It is pretty timely that this article was posted around the same time when almost half the front page is covering the same topic.


I think this would be very nice in an ebook or other long form writing where I need to backtrack to find some earlier reference. Where it doesn't work well is in hierarchical data like HN comments. I installed the chrome extension and used it to read the comments on this posting and it was nearly impossible to use. With things that are arranged hierarchically, such as comments, a single page works better than this, but I do think this will be nice on longer articles or with ebooks.


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

Search: