Live data from Hacker News

Haskell tutorial for C programmers

haskell.org

11–20 of 56 posts

Re: Haskell tutorial for C programmers

#13
This makes for very good reading indeed. I started reading it and just now realised that I'd spent the last couple of hours on it. It's written well, approachable and very pragmatic. I spent a short while on Haskell a few years back and stopped after 3 or 4 chapters of Learn You A Haskell due to time constraints. I think I'm going to make this my evening reading and finally pick up the language.

Thanks for posting this.

EDIT: typos

Re: Haskell tutorial for C programmers

#14

Earlier quoted context omitted.

How do you express the Ordinality constraint in C++?

Multiple inheritance from a purely virtual class. In Java, they're called interfaces; Comparable is the analogue to Ord. The advantage that Haskell's typeclasses have over either Java or C++ is that the types aren't closed. I can define a new typeclass and tell the compiler that a type you defined is a member of that class at any point. In Java, if you don't define that your type is Comparable, there's nothing that I…

Yeah, though you will want to be the owner of either the type class or the type itself. Instances which are neither are called orphan instances and they are generally frowned upon. Luckily, it's trivial to create a newtype wrapper which gives you a whole new set of hooks for writing instances of a type.

Re: Haskell tutorial for C programmers

#17
post #14

Earlier quoted context omitted.

Multiple inheritance from a purely virtual class. In Java, they're called interfaces; Comparable is the analogue to Ord. The advantage that Haskell's typeclasses have over either Java or C++ is that the types aren't closed. I can define a new typeclass and tell the compiler that a type you defined is a member of that class at any point. In Java, if you don't define that your type is Comparable, there's nothing that I…

Yeah, though you will want to be the owner of either the type class or the type itself. Instances which are neither are called orphan instances and they are generally frowned upon. Luckily, it's trivial to create a newtype wrapper which gives you a whole new set of hooks for writing instances of a type.

Orphan instances in libraries are frowned upon. In an application they are more palatable, though a newtype might still be a better choice, depending.

Re: Haskell tutorial for C programmers

#18
post #16

Chris Allen / coolsunglasses maintains a great gist of a learning path for haskell: https://gist.github.com/bitemyapp/8739525 The current intro course looks really nice: http://www.seas.upenn.edu/~cis194/lectures.html

That gist is a fantastic resource, strongly endorsed.

Re: Haskell tutorial for C programmers

#19
post #14

Earlier quoted context omitted.

Multiple inheritance from a purely virtual class. In Java, they're called interfaces; Comparable is the analogue to Ord. The advantage that Haskell's typeclasses have over either Java or C++ is that the types aren't closed. I can define a new typeclass and tell the compiler that a type you defined is a member of that class at any point. In Java, if you don't define that your type is Comparable, there's nothing that I…

Yeah, though you will want to be the owner of either the type class or the type itself. Instances which are neither are called orphan instances and they are generally frowned upon. Luckily, it's trivial to create a newtype wrapper which gives you a whole new set of hooks for writing instances of a type.

That makes sense, but again, in Java you can't do it if you're just the owner of the typeclass, and in order to make a wrapper you'd have to make a subclass, which mucks with all kinds of other things.

Re: Haskell tutorial for C programmers

#20
post #4

>What this means is that existing sort functions such as mergeSort and quickSort would need to be rewritten to sort values of the new type. In constrast, here is the type of mergeSort in Haskell mergeSort :: Ord a => [a] -> [a] Er, you could define mergesort using templates in c++ and it would work pretty much the same.

Yeah, I don't get why that's superior to something like std::sort : http://en.cppreference.com/w/cpp/algorithm/sort (or a similar approach however you like).
Post reply on HN