
Haskell tutorial for C programmers - foulas
http://www.haskell.org/haskellwiki/Haskell_Tutorial_for_C_Programmers
======
cnvogel
Oh my, another tutorial. I've looked at many of them, trying to learn
something from the Haskell way. And I think I get the fundamental advantages
of the type systems, the lazy evaluation enabled by the languages purity, I
think I can somehow make sense of the Monads even. I have the "learn you a
haskell for good" on a pile of books where I have a glimpse from time to time.

Most tutorials and books are very enthusiastic in how they can detect that I
try to zip two lists of different cardinality during compile time, or how they
can lazily calculate the Fibbonacci sequence. And that's really nice and
fine...

But nevertheless, I use C all of the time, and I learnt how to make use of a
myriad of libraries, combine connections to a SQL database, embedd a
webserver, talk to USB,... Must have been 20 years ago that I wrote code to
calculate the Fibbonacci sequence.

So, where are tutorials that showcase all the wonderful "high-level"
functionality that has already been written for Haskell, so that I, after
reading through the text, will be thrilled how much work I can avoid, or how
much security I can gain when switching over from my "almost bare-matel not-
much-more-like-an-assembler C" to Haskell? Not in calculating the Fibunacci
sequency, but in writing a backend for my web-app, or talk to a USB
peripheral? Do 3D graphics?...

~~~
nbouscal
If all you've done is looked at tutorials and glimpsed at a book, I think it's
very unlikely that you actually get the advantages or really understand any of
the patterns like Monads. _Write some code._ The only way that you'll actually
grok the language and get any of the benefits from learning it is if you
actually write code in it.

------
cgag
Chris Allen / coolsunglasses maintains a great gist of a learning path for
haskell:
[https://gist.github.com/bitemyapp/8739525](https://gist.github.com/bitemyapp/8739525)

The current intro course looks really nice:
[http://www.seas.upenn.edu/~cis194/lectures.html](http://www.seas.upenn.edu/~cis194/lectures.html)

~~~
nardi
This gist was what helped me finally learn Haskell, after failing on my first
two tries.

------
rfrey
@kissthblade: Your comment (dead) below is very sad. You've been hell-banned
for more than a year and a half. It doesn't just _seem_ like nobody is seeing
your comments, it's true.

For those without showdead on:

"I posted about the same comment as the parent hours ago. I don't know if
anybody even sees my posts, never gotten a response, and my "karma" or
something has always been 15. And posting and reading the forum is very slow.
What gives?"

Looking through your comments, I don't see an obvious reason you were
hellbanned.

~~~
consz
This happened to me, too. I spent about a year replying before finally seeing
someone mention I was hell banned. I also wondered why the forum was _so_
slow, but it's not particularly well coded so I just assumed its always been
like that.

------
vendakka
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

~~~
Peaker
That's great!

Don't expect to "pick up the language" in an evening :)

Haskell takes a few evenings at the very least!

------
austinz
This is great, and I've bookmarked it for reference while reading LYAH. Thanks
for writing it.

For anyone who needs a refresher on DFA, Stanford's CS143 compilers class
course materials are up on Coursera
([https://www.coursera.org/course/compilers](https://www.coursera.org/course/compilers)),
and pretty helpful.

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

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

~~~
GeneralMayhem
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, as a
consumer of your type, can do about it.

~~~
Peaker
The advantage you mention is one of many (over OOP interfaces), I'll repeat it
as (A).

(A) Ability to instantiate old types with new classes

(B) Conditional instantiation: "Maybe a" is an instance of "Show" iff "a" is
an instance of "Show"

(C) Can do return-type polymorphism, or polymorphism on any part of the
signature

(D) Objects do not need to pay for the interface vtable pointer. Large array
of some type-class instance can be much smaller than an array of an OOP
interface subclass.

(E) When comparing two Ord instance values, there is only one Ord dictionary,
rather than 2 to choose from. No false dilemma.

~~~
judk
E) you do get a dilemma if you add two elements in a sorted structure ,
lexically in two different files, where two different Ord instances arr in
scope, respectively. this function-is-instance problem is dual to OO's
-object-is-instance problem.

~~~
Peaker
A homogenous list is guaranteed to only have one instance unless you enable
incoherent instances (a known bad extension) or confuse the compiler with
orphan instances (though I've never encountered this and think it should be
detectable at link time anyway).

One type -> at most one instance for any class, in Haskell.

------
kahaw
This is great, now I just need a similar tutorial but for LISP.

~~~
CyberShadow
Here's an interactive one:

[http://www.eblong.com/zarf/zweb/lists/](http://www.eblong.com/zarf/zweb/lists/)

Bit dated, though :)

------
Kiro
Great! A Haskell tutorial for JS or PHP programmers would be awesome.

~~~
tinco
How would it be different? JS and PHP are near identical to C.

~~~
judk
How do I port closure-heavy prototype-based objects from JS to Haskell? This
isn't near identical to C.

------
giuscri
Uhm ...great perspective!

