This is an amazing book. I highly recommend it as the first Haskell book you read. After it, you can check out Real World Haskell.
To elaborate on why you shouldn't read (at least the online version of) Real World Haskell first: It has a lot of important topics that it covers that LYAH does not cover (like how to use cabal their package manager). But, it's not as good of a tutorial on the language and functional programming. It glosses over very complex topics, goes into a lot of depth on details that are not so important and worst of all, gives you some exercises that you aren't capable of answering yet. I tried learning Haskell three times from that book and gave up because it just killed my confidence.
Then I discovered LYAH. It explains things very simply and at a very good pace. If you want to learn Haskell and/or functional programming, I can't recommend it more. Imagine one of the Head First books without all the corny. The only thing I wish it had was exercises.
I started reading the online version, enjoyed it so much, I went ahead and boug ht the treeware version. And it's awesome.
I felt so loved as a customer of No Starch Press. They sent me the book, let me download the ebook in three free formats (no DRM), plus I got a bunch of freebie stickers.
The book itself is also quite remarkable to me in that I can read it and understand Haskell without needing a computer. I am used to reading mathematics books, and while I don't think Haskell is a programming language for all mathematicians as is so often advertised, the language does have a certain appeal to it in that you can treat its programs as abstract exercises that you can do independently of a machine. The statelessness of the whole thing doesn't need me typing stuff into a machine to see what a particular line of code. This makes it great for offline reading, away from the computer.
So yeah, get the treeware version. Support your favourite authors. :-)
What I find confusing with Haskell is that the keywords don't seem to be consistent with the concepts they're meant to express. As someone new to Haskell I learnt that the `class` keyword doesn't express the object-oriented concept of class, but the concept of type class, which is different. Fair enough. What about declaring types then? That must be `type`, right? Nope, `type` is for creating type aliases. OK, surely that must be `newtype` then? Wrong again, `newtype` is also for declaring aliases. All right, to declare a new type, you don't use `newtype` nor `type` you use `data`. But be careful, the part that has the `data` keyword is still called a type constructor, whereas the part that does not have the `data` keyword is called a data constructor.
OK so let's recap, you create a new type with `data`, which is formed of a type constructor that starts with the keyword `data` and a data constructor which doesn't start with `data`. To create aliases you use `type` and `newtype` and to create type classes you use `class`.
Now how do you call the type class of things that can be mapped over? Surely that must be something like `mappable`?
The designers of Haskell (and Haskell is one of the few successful design-by-committee languages,) were not doing things "your way" (where I assume you are a working programmer, with knowledge of some or even many traditional imperative languages.)
They were PL researchers. Used to ML, Common Lisp, Ada, and, most importantly, Mathematics and Category and Type Theory.
`data` introduces an algebraic data type, so it makes sense to use data as a keyword. `type` and `newtype`, on the other hand, are programmer's conveniences: both carry no runtime cost, they are not actually part of the semantics of the backend language.
`map` is a function that's really just a specialization of `fmap`. Now, my category theory is a bit weak, but if I'm thinking correctly here, `fmap f` is an endofunctor in the category of functors, and so it makes perfect sense to call "mappable" Functor. There's also "Traversable," which works pretty much like a fully-fledged "mappable" with all extras, but also requires a Functor instance.
Keywords, and idiosyncrasies of a syntactic nature are really just superficial. The actual elegance of the language is its type system. (The actual warts of the language are, for the most part, also in the type system; records for example.) The latter criticism about `mappable` is really just due to the fact that you haven't gotten used to the underlying theory (and I don't blame you, it's hard.) But getting used to it can be rewarding. I'm not saying it's going to make you a better programmer (I'm not necessarily of that opinion,) but it's rewarding in its own right.
Oh, and the difference between data constructors, type names, and, later, kind names (with promotion, since 7.4,) can be confusing. I sometimes find it an oversight that they are not distinguished syntactically, I think that would greatly help most newbies, and sometimes even make things easier to read and understand for veterans, too.
Haskell looks very interesting but I can't help but ask 'why do I need it?'. Currently I am learning Java since I want to get a jr.developer job later on and Ruby for some scripting and personal projects(maybe even Rails later). So Java is used in industry, Ruby is used in web and metasploit/ronin (something that I like to mess with), but what about Haskell? I am genuinely curious what Haskell can offer. I always see it mentioned on Reddit but I have yet to come across any notable project written with it. Could somebody with experience give me some reasons for me to learn it?
There are two very different types of arguments typically made as to why to learn the more esoteric languages (Haskell, Lisp, Forth, others).
The first is the more common: learning these languages exposes you to other ways of programming, which in turn makes you a better programmer no matter what language you're programming in. This is unquestionably true. Mainstream languages are constantly learning new things from these languages, which means you will be able to apply the techniques you learn from them to your code no matter what language you write in. I have the misfortune[1] of writing a lot of PHP at my day job, but it turns out even PHP has support for filter and map over arrays. If I hadn't learned functional programming, I would never have even looked for them.
The other argument, which is made less often, is that you can actually write great software in these languages. This argument is made less often because we can obviously look at the market and the TIOBE index and see that Haskell is way down at #30 with 0.323% of the market share. However, there are really great programs made in Haskell (xmonad, for one). There are also tons of great programs made in Lisps, especially Clojure of late. So, this second argument is not entirely a dead end either.
Revisiting something I mentioned in the first argument for a moment though, I would actually make a third argument that I rarely see. As I said, other languages are constantly learning new things from these languages. Haskell's community is full of PhDs studying at the intersection of programming and mathematics, and they are discovering the things that will revolutionize programming in the future. Haskell, for example, has been exploring strong static typing with algebraic datatypes[2], Hindley-Milner type inference, and typeclasses to support higher-kinded polymorphism[3]. Those concepts are turning out to be incredibly powerful, and you will inevitably see them in other programming languages in the future. We've seen this before with Lisp (garbage collection, recursion, first-class functions), and there's no reason not to expect the trend to continue.
So, why learn Haskell? It's the easiest way to see what tools you'll have available to you in industry 20 years from now when the other languages catch up.
For the same reasons you need any programming language—to write useful software in!
> Currently I am learning Java…and Ruby
These are both good ideas. Java is widely used, reliable, and well tested for developing large applications. Ruby is simply a lot of fun to use, and one of the things you’ll discover while using Ruby is that it places a lot of functional programming idioms in an object-oriented context.
The issue with many popular languages is that they fall into much the same paradigm, namely imperative and either procedural or object-oriented, with some functional features borrowed for working with lists. It’s worthwhile to see that not all languages are like this, and learning a new language is not just about new syntax and APIs.
> but what about Haskell? I am genuinely curious what Haskell can offer.
Haskell will teach you to think about structuring your program in terms of simple data and transformations on that data. Object-oriented programming is about coupling data with behaviour, whereas a big part of learning Haskell is learning how to recognise high-level patterns in data structures and functions separately. In doing so, you can avoid the work of reimplementing common operations yourself.
You begin to say, oh, this is a data structure I can map a function over; I’d better make it an instance of Functor. And hey, I could use this data structure to represent this kind of computation, maybe it should be an Applicative and a Monad so I get some nice syntax for dealing with it. This function has a type signature that looks an awful lot like that other type signature—I wonder if I could implement one in terms of the other? And so on.
The type system and succinct syntax also make it very easy to create new data types, and you learn how this can help avoid bugs—don’t use a Boolean here, use an enumeration with two values; then you can’t mess up. Java discourages this by requiring more syntactic effort to create a new datatype.
A useful and oft-cited example of this is in the context of web frameworks: if you have separate data types for strings and HTML, that one simple thing eliminates a whole class of injection attacks. If you represent your links in the type system, then you can statically ensure that your site does not have any broken links. Simply put, quite a lot of bad things can be caught at compile time if you have a type system expressive enough to talk about them.
> I have yet to come across any notable project written with it.
There are more notable projects out there, but here’s my self-promotion. At my old job[1] I maintained a compiler for ActionScript 3 in Haskell, as well as a build system that coordinated the compiler and other build tools to convert Flash games to iOS and Android applications.
Haskell is excellent at manipulating data structures—if that sounds ridiculously general, that’s because it is. The compiler is very nearly feature complete and, even with a certain amount of technical debt, was an order of magnitude smaller and easier to refactor than it would have been in an imperative language.
So there you go. From a recovering professional Haskeller, why you should learn Haskell. And, for that matter, the answer to “should I learn this language?” is always “yes”; but some languages should be higher on your list than others. ;)
You don't need it. If you are a Junior developer (or aiming at being one) Haskell is a language you most definitely don't need.
Now, once you have your feet wet, it's worth learning. Here's why:
- Pure(mostly) functional language. This is in opposition to Java & Ruby, which while having functional aspects are OO (Object Oriented).
- It's okay not to know what a functional language is. It's making functions first-class citizens, such that a function becomes a value like any other.
- Separates IO from computation. IO is inherently impure and unreliable, so functions are generally pure and instead wrap IO in containers. Obviously, programs would be less useful (still use in the compiler running!) without IO.
- All of these concepts (and more) will change how you think about programming and make you a better programmer in all languages.
Haskell can be found in some backend stacks, the more notable examples I can think of are Mailrank (acquihired by Facebook) and Bump.
Personally, I've only done a limited number of projects with Haskell (a Postgres-backed beer API & IRC bot) but I've grown to respect it as a language and through limited exposure has made me love FP.
From the perspective of "learn other languages to broaden your horizons":
Haskell is worth learning because it has an expressive, strong, static type system. Most other languages do not have that property (Java's type system is static, give or take null, and strong, but not expressive, and Ruby's is strong but neither expressive nor static). The Haskell type system lets you have conversations with the compiler about what your program should do.
You can declare a state type, and have the compiler tell you if you switch on the state and forget to handle one of the possible states (or if you add a state later and forget to update all the switches).
You can tell the compiler "I think this function is a generally useful utility function that I plan to extract out of this project and use elsewhere", and it will tell you whether there's some dependency on your project that you missed.
You can specify in a function's type "this function should have access to the database"; then the compiler can tell you if you're trying to access the database somewhere you didn't expect to. (A colleague has just spent a person-year of effort refactoring a Django web app, because all the database calls were happening in the view code, and they needed to abstract them out to scale.)
Of course there are ways to do some of those things in other languages, and of course there are also downsides to the static type system. But those sorts of abilities open up new programming techniques (even in languages with poorer type systems), and have shown me ways programming can be better.
If you want to look at an interesting functional language that has some very solid real world uses, have a look at Erlang, and its own "Learn you ..." here:
Which is a fantastic book, clearly written as a labor of love.
Erlang doesn't have Haskell's type system and doesn't seem to be of much interest for CS research types, but it's awesome for developing certain kinds of system.
I am curious about Haskell myself, and don't tend to need a lot of excuses to learn a language, but I don't perceive a "sweet spot" for it just yet, as in "I could go build X, and Haskell would be a great fit for it". Given how many smart people use it, I'm sure there are a lot of applications for it, but I also get a feeling that there's not one thing that really stands out.
It's a tiny detail but learning some functional ways of thinking gives you great alternatives to for/foreach loops when dealing with large lists/arrays/hashtables of data, even in other languages like Ruby or Java.
Haskell can offer absolutely nothing Java can offer, while Haskell can't offer even 0.001% of what Java offers.
You see, there's a very, very good reason why you won't see any (even remotely) serious and useful software made in Haskell and why you won't see it used by companies (which means that jobs are literally extremely close to zero)
Haskell is nothing more than an exercise of constructing a language based on certain mathematical concepts, mainly abstract stuff like category theory.
As a result it as cryptic, hard to understand and useless in practice as those theoretical concepts (though the theoretical stuff might serve as basis for some other stuff that might be useful - not so with functional languages and especially Haskell)
I'll reccomend Erik Meijer's videos on introductory Haskell.
I haven't gotten though them all but I appreciate his style and depth of knowledge on the matter; he also points out many things that a Java or C# dev would naturally be curious about how to interpret Haskell.
Now, you may think that implies that you could do something like this to print a string one character at a time:
rsoat (x:xs) = show x (rsoat xs)
Buy you can't. If you try that Haskell complains "The function 'show' is applied to two arguments, but its type 'a0 -> String' has only one...."
Fair enough, one might reason - you're just passing max two things when it wants one so we can do something like this:
rsoat [] = []
rsoat [x] = show x
rsoat (x:xs) = rsoat xs
But no, that just gets you the tail of your string because x:xs doesn't match x so it never prints the other bits.
What you may end up doing is something like this:
rsoat [] = []
rsoat [x] = [x]
rsoat (x:xs) = show x ++ (rsoat xs)
But that's still not really doing what you wanted to do in the first place. It's sticking all your characters into a string and then reading that string all at once. And it's not a particularly obvious solution either if you don't know the language.
This may seem a silly example. But what happens when, as is frequently the case, someone wants to retrieve the nth element of a list? (list !! n) Haskell, as learnt through Learn You a Haskell, can easily be expected to drive someone up the wall who starts asking such questions - it's not a whole bunch of fun to play with.
To be honest, it does not seem you did a very good job of reading the book. If you're rooted in imperative languages, it takes some effort. I read the book when I had already had some basic functional programming experience, so my experience might not be so representative, but I've heard quite a few positive reviews from people for whom it was the first introduction to FP.
You seem to start off from a wrong premise that the show function prints things. It doesn't - it simply converts whatever value (of type a) you give it to a String (provided a is an instance of the Show typeclass). So seeing that you already have a string, a function which converts things to strings will probably not be very useful.
> rsoat [] = []
> rsoat [x] = show x
> rsoat (x:xs) = rsoat xs
> But no, that just gets you the tail of your string because x:xs doesn't match x so it never prints the other bits.
Uh, no. It doesn't give you the tail of the string, it gives you a list containing just the last element of the argument (if the argument's not empty), or the empty list (if the argument is empty) - which you can read directly from your definition.
Furthermore, " x:xs doesn't match x" doesn't make a whole lot of sense - it's not supposed to match x, it's supposed to match a non-empty list. Which it does, and the first element of such a list gets bound to the parameter x - but you do not use the parameter in your right-hand side of the definition, so you effectively discard it.
Note that both pattern matching and the Show typeclass (and the corresponding function) are discussed in the book prior to the minimum example.
>Now, you may think that implies that you could do something like this to print a string one character at a time:
I'm not sure how far you got after this point, but the problem is easily solved with a higher-order function:
mapM_ print "blahblahblah"
Or if you don't like each character being quoted:
mapM_ (putStrLn . return) "hello one at a time"
Or did you not want the characters on their own lines? In that case, you can do this:
mapM_ putChar "horse raddish"
But why bother doing that when you can simply do this?:
putStr "egg freckles"
>But what happens when, as is frequently the case, someone wants to retrieve the nth element of a list?
If you are frequently wanting to do this, you are probably doing something wrong. Haskell's lists are intended to be used as control structures, not indexed data structures. For those, you'll want an Array, Vector, IntMap etc.
I really liked LYAH, but it only starts out good. Once you hit Chapter 9. I/O. Prepare to fall off the rails. It only gets worse and worse and worse from that point onwards.
I don't think that's really the books fault as much as it is Haskells. I also think it's why you hear ALOT of people swearing Haskell is actually very easy, because everything up to chapter 9 is not very complicated at all.
I'm sure there are some very tallented people where this isn't true, but I get the impression that the people who are saying it's easy haven't gotten to the point where you can actually do things with Haskell, or developed a program with Haskell, or inter-operate with other libraries using Haskell, or tested their metal against the Parsing Combinators in Haskell (let alone making your own set), or ect. ect. ect.
It is a joke, but not an inside joke as much as a joke that would be understood by people from Balkan countries (Serbia, Croatia, Bosnia). Miran (the author of LYAH) is, judging from his first and last name, from this region.
In the local language (Serbian, Croatian and Bosnian are basically the dialects of the same common language), the most commonly used word for teach and learn is the same word, uciti, although there are separate words for these activities. Basically, whether you speak of teaching someone, or learning something is judged by the context.
Then, Learn you a haskell vs. teach you haskell is a wordplay in that sense.
A similar joke from the region: "Can you translate me to the other page of the street?"
The author is a very funny/insane guy. Exhibit A is his twitter account (https://twitter.com/bonus500). I wouldn't call it an inside joke, but rather a general feature of good comedy where it feels familiar yet distant.
It is a gamer|anime|comic book joke. There is a lot of cheaply written entertainment with poorly defined motivations ascribed to the heroes and villains. So what battle cry is used by an overly generic hero? Why an overly generic cry of "For great justice!" of course. Throw in a joke a about poor translations and you get their title.
I believe the title is a riff off of "Learn You Some Erlang for Great Good!" Some other books or online tutorials have taken that form of title. I don't really know why, though I suppose the silliness offsets the otherwise heavy nature of the content. (Learning Erlang is probably easier than learning Haskell for most people, but it can still be a mind stretcher if you've never done a functional language before.)
[+] [-] tieTYT|13 years ago|reply
To elaborate on why you shouldn't read (at least the online version of) Real World Haskell first: It has a lot of important topics that it covers that LYAH does not cover (like how to use cabal their package manager). But, it's not as good of a tutorial on the language and functional programming. It glosses over very complex topics, goes into a lot of depth on details that are not so important and worst of all, gives you some exercises that you aren't capable of answering yet. I tried learning Haskell three times from that book and gave up because it just killed my confidence.
Then I discovered LYAH. It explains things very simply and at a very good pace. If you want to learn Haskell and/or functional programming, I can't recommend it more. Imagine one of the Head First books without all the corny. The only thing I wish it had was exercises.
[+] [-] jordigh|13 years ago|reply
I felt so loved as a customer of No Starch Press. They sent me the book, let me download the ebook in three free formats (no DRM), plus I got a bunch of freebie stickers.
The book itself is also quite remarkable to me in that I can read it and understand Haskell without needing a computer. I am used to reading mathematics books, and while I don't think Haskell is a programming language for all mathematicians as is so often advertised, the language does have a certain appeal to it in that you can treat its programs as abstract exercises that you can do independently of a machine. The statelessness of the whole thing doesn't need me typing stuff into a machine to see what a particular line of code. This makes it great for offline reading, away from the computer.
So yeah, get the treeware version. Support your favourite authors. :-)
[+] [-] pnathan|13 years ago|reply
[+] [-] rhizome31|13 years ago|reply
OK so let's recap, you create a new type with `data`, which is formed of a type constructor that starts with the keyword `data` and a data constructor which doesn't start with `data`. To create aliases you use `type` and `newtype` and to create type classes you use `class`.
Now how do you call the type class of things that can be mapped over? Surely that must be something like `mappable`?
[+] [-] adimitrov|13 years ago|reply
They were PL researchers. Used to ML, Common Lisp, Ada, and, most importantly, Mathematics and Category and Type Theory.
`data` introduces an algebraic data type, so it makes sense to use data as a keyword. `type` and `newtype`, on the other hand, are programmer's conveniences: both carry no runtime cost, they are not actually part of the semantics of the backend language.
`map` is a function that's really just a specialization of `fmap`. Now, my category theory is a bit weak, but if I'm thinking correctly here, `fmap f` is an endofunctor in the category of functors, and so it makes perfect sense to call "mappable" Functor. There's also "Traversable," which works pretty much like a fully-fledged "mappable" with all extras, but also requires a Functor instance.
Keywords, and idiosyncrasies of a syntactic nature are really just superficial. The actual elegance of the language is its type system. (The actual warts of the language are, for the most part, also in the type system; records for example.) The latter criticism about `mappable` is really just due to the fact that you haven't gotten used to the underlying theory (and I don't blame you, it's hard.) But getting used to it can be rewarding. I'm not saying it's going to make you a better programmer (I'm not necessarily of that opinion,) but it's rewarding in its own right.
Oh, and the difference between data constructors, type names, and, later, kind names (with promotion, since 7.4,) can be confusing. I sometimes find it an oversight that they are not distinguished syntactically, I think that would greatly help most newbies, and sometimes even make things easier to read and understand for veterans, too.
[+] [-] ikkyu|13 years ago|reply
[+] [-] nbouscal|13 years ago|reply
The first is the more common: learning these languages exposes you to other ways of programming, which in turn makes you a better programmer no matter what language you're programming in. This is unquestionably true. Mainstream languages are constantly learning new things from these languages, which means you will be able to apply the techniques you learn from them to your code no matter what language you write in. I have the misfortune[1] of writing a lot of PHP at my day job, but it turns out even PHP has support for filter and map over arrays. If I hadn't learned functional programming, I would never have even looked for them.
The other argument, which is made less often, is that you can actually write great software in these languages. This argument is made less often because we can obviously look at the market and the TIOBE index and see that Haskell is way down at #30 with 0.323% of the market share. However, there are really great programs made in Haskell (xmonad, for one). There are also tons of great programs made in Lisps, especially Clojure of late. So, this second argument is not entirely a dead end either.
Revisiting something I mentioned in the first argument for a moment though, I would actually make a third argument that I rarely see. As I said, other languages are constantly learning new things from these languages. Haskell's community is full of PhDs studying at the intersection of programming and mathematics, and they are discovering the things that will revolutionize programming in the future. Haskell, for example, has been exploring strong static typing with algebraic datatypes[2], Hindley-Milner type inference, and typeclasses to support higher-kinded polymorphism[3]. Those concepts are turning out to be incredibly powerful, and you will inevitably see them in other programming languages in the future. We've seen this before with Lisp (garbage collection, recursion, first-class functions), and there's no reason not to expect the trend to continue.
So, why learn Haskell? It's the easiest way to see what tools you'll have available to you in industry 20 years from now when the other languages catch up.
[1]: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-de...
[2]: https://www.youtube.com/watch?v=YScIPA8RbVE
[3]: http://www.haskell.org/haskellwiki/Typeclassopedia
[+] [-] evincarofautumn|13 years ago|reply
For the same reasons you need any programming language—to write useful software in!
> Currently I am learning Java…and Ruby
These are both good ideas. Java is widely used, reliable, and well tested for developing large applications. Ruby is simply a lot of fun to use, and one of the things you’ll discover while using Ruby is that it places a lot of functional programming idioms in an object-oriented context.
The issue with many popular languages is that they fall into much the same paradigm, namely imperative and either procedural or object-oriented, with some functional features borrowed for working with lists. It’s worthwhile to see that not all languages are like this, and learning a new language is not just about new syntax and APIs.
> but what about Haskell? I am genuinely curious what Haskell can offer.
Haskell will teach you to think about structuring your program in terms of simple data and transformations on that data. Object-oriented programming is about coupling data with behaviour, whereas a big part of learning Haskell is learning how to recognise high-level patterns in data structures and functions separately. In doing so, you can avoid the work of reimplementing common operations yourself.
You begin to say, oh, this is a data structure I can map a function over; I’d better make it an instance of Functor. And hey, I could use this data structure to represent this kind of computation, maybe it should be an Applicative and a Monad so I get some nice syntax for dealing with it. This function has a type signature that looks an awful lot like that other type signature—I wonder if I could implement one in terms of the other? And so on.
The type system and succinct syntax also make it very easy to create new data types, and you learn how this can help avoid bugs—don’t use a Boolean here, use an enumeration with two values; then you can’t mess up. Java discourages this by requiring more syntactic effort to create a new datatype.
A useful and oft-cited example of this is in the context of web frameworks: if you have separate data types for strings and HTML, that one simple thing eliminates a whole class of injection attacks. If you represent your links in the type system, then you can statically ensure that your site does not have any broken links. Simply put, quite a lot of bad things can be caught at compile time if you have a type system expressive enough to talk about them.
> I have yet to come across any notable project written with it.
There are more notable projects out there, but here’s my self-promotion. At my old job[1] I maintained a compiler for ActionScript 3 in Haskell, as well as a build system that coordinated the compiler and other build tools to convert Flash games to iOS and Android applications.
Haskell is excellent at manipulating data structures—if that sounds ridiculously general, that’s because it is. The compiler is very nearly feature complete and, even with a certain amount of technical debt, was an order of magnitude smaller and easier to refactor than it would have been in an imperative language.
So there you go. From a recovering professional Haskeller, why you should learn Haskell. And, for that matter, the answer to “should I learn this language?” is always “yes”; but some languages should be higher on your list than others. ;)
[1]: http://spaceport.io/
[+] [-] Xorlev|13 years ago|reply
Now, once you have your feet wet, it's worth learning. Here's why:
- Pure(mostly) functional language. This is in opposition to Java & Ruby, which while having functional aspects are OO (Object Oriented). - It's okay not to know what a functional language is. It's making functions first-class citizens, such that a function becomes a value like any other. - Separates IO from computation. IO is inherently impure and unreliable, so functions are generally pure and instead wrap IO in containers. Obviously, programs would be less useful (still use in the compiler running!) without IO. - All of these concepts (and more) will change how you think about programming and make you a better programmer in all languages.
Haskell can be found in some backend stacks, the more notable examples I can think of are Mailrank (acquihired by Facebook) and Bump.
Personally, I've only done a limited number of projects with Haskell (a Postgres-backed beer API & IRC bot) but I've grown to respect it as a language and through limited exposure has made me love FP.
[+] [-] samstokes|13 years ago|reply
Haskell is worth learning because it has an expressive, strong, static type system. Most other languages do not have that property (Java's type system is static, give or take null, and strong, but not expressive, and Ruby's is strong but neither expressive nor static). The Haskell type system lets you have conversations with the compiler about what your program should do.
You can declare a state type, and have the compiler tell you if you switch on the state and forget to handle one of the possible states (or if you add a state later and forget to update all the switches).
You can tell the compiler "I think this function is a generally useful utility function that I plan to extract out of this project and use elsewhere", and it will tell you whether there's some dependency on your project that you missed.
You can specify in a function's type "this function should have access to the database"; then the compiler can tell you if you're trying to access the database somewhere you didn't expect to. (A colleague has just spent a person-year of effort refactoring a Django web app, because all the database calls were happening in the view code, and they needed to abstract them out to scale.)
Of course there are ways to do some of those things in other languages, and of course there are also downsides to the static type system. But those sorts of abilities open up new programming techniques (even in languages with poorer type systems), and have shown me ways programming can be better.
[+] [-] davidw|13 years ago|reply
http://learnyousomeerlang.com/
Which is a fantastic book, clearly written as a labor of love.
Erlang doesn't have Haskell's type system and doesn't seem to be of much interest for CS research types, but it's awesome for developing certain kinds of system.
I am curious about Haskell myself, and don't tend to need a lot of excuses to learn a language, but I don't perceive a "sweet spot" for it just yet, as in "I could go build X, and Haskell would be a great fit for it". Given how many smart people use it, I'm sure there are a lot of applications for it, but I also get a feeling that there's not one thing that really stands out.
[+] [-] nilkn|13 years ago|reply
xmonad, one of the best tiling window managers for Linux, is written in Haskell (and is open source).
[+] [-] ianlevesque|13 years ago|reply
[+] [-] alexakarpov|13 years ago|reply
[+] [-] ccdan|13 years ago|reply
[+] [-] misframer|13 years ago|reply
Introduction to Haskell lecture slides - http://shuklan.com/haskell/
Real World Haskell - http://book.realworldhaskell.org/
[+] [-] gtani|13 years ago|reply
http://www.reddit.com/r/haskell/comments/1af3iw/9_best_free_...
http://www.linuxlinks.com/article/20130316105209238/BestFree...
[+] [-] ilaksh|13 years ago|reply
[+] [-] jamesbritt|13 years ago|reply
https://news.ycombinator.com/item?id=535675
https://news.ycombinator.com/item?id=336085
[+] [-] platz|13 years ago|reply
http://channel9.msdn.com/Series/C9-Lectures-Erik-Meijer-Func...
[+] [-] 6d0debc071|13 years ago|reply
Take this in p52 for instance:
maximum' :: (Ord a) => [a] -> a
maximum' [] = error "Maximum of empty list!"
maximum' [x] = x
maximum' (x:xs) = max x (maximum xs)
Now, you may think that implies that you could do something like this to print a string one character at a time:
rsoat (x:xs) = show x (rsoat xs)
Buy you can't. If you try that Haskell complains "The function 'show' is applied to two arguments, but its type 'a0 -> String' has only one...."
Fair enough, one might reason - you're just passing max two things when it wants one so we can do something like this:
rsoat [] = []
rsoat [x] = show x
rsoat (x:xs) = rsoat xs
But no, that just gets you the tail of your string because x:xs doesn't match x so it never prints the other bits.
What you may end up doing is something like this:
rsoat [] = []
rsoat [x] = [x]
rsoat (x:xs) = show x ++ (rsoat xs)
But that's still not really doing what you wanted to do in the first place. It's sticking all your characters into a string and then reading that string all at once. And it's not a particularly obvious solution either if you don't know the language.
This may seem a silly example. But what happens when, as is frequently the case, someone wants to retrieve the nth element of a list? (list !! n) Haskell, as learnt through Learn You a Haskell, can easily be expected to drive someone up the wall who starts asking such questions - it's not a whole bunch of fun to play with.
[+] [-] oggy|13 years ago|reply
You seem to start off from a wrong premise that the show function prints things. It doesn't - it simply converts whatever value (of type a) you give it to a String (provided a is an instance of the Show typeclass). So seeing that you already have a string, a function which converts things to strings will probably not be very useful.
> rsoat [] = [] > rsoat [x] = show x > rsoat (x:xs) = rsoat xs
> But no, that just gets you the tail of your string because x:xs doesn't match x so it never prints the other bits.
Uh, no. It doesn't give you the tail of the string, it gives you a list containing just the last element of the argument (if the argument's not empty), or the empty list (if the argument is empty) - which you can read directly from your definition.
Furthermore, " x:xs doesn't match x" doesn't make a whole lot of sense - it's not supposed to match x, it's supposed to match a non-empty list. Which it does, and the first element of such a list gets bound to the parameter x - but you do not use the parameter in your right-hand side of the definition, so you effectively discard it.
Note that both pattern matching and the Show typeclass (and the corresponding function) are discussed in the book prior to the minimum example.
[+] [-] chongli|13 years ago|reply
I'm not sure how far you got after this point, but the problem is easily solved with a higher-order function:
Or if you don't like each character being quoted: Or did you not want the characters on their own lines? In that case, you can do this: But why bother doing that when you can simply do this?: >But what happens when, as is frequently the case, someone wants to retrieve the nth element of a list?If you are frequently wanting to do this, you are probably doing something wrong. Haskell's lists are intended to be used as control structures, not indexed data structures. For those, you'll want an Array, Vector, IntMap etc.
[+] [-] GhotiFish|13 years ago|reply
I don't think that's really the books fault as much as it is Haskells. I also think it's why you hear ALOT of people swearing Haskell is actually very easy, because everything up to chapter 9 is not very complicated at all.
I'm sure there are some very tallented people where this isn't true, but I get the impression that the people who are saying it's easy haven't gotten to the point where you can actually do things with Haskell, or developed a program with Haskell, or inter-operate with other libraries using Haskell, or tested their metal against the Parsing Combinators in Haskell (let alone making your own set), or ect. ect. ect.
Chapters 1-8 aren't complicated in the slightest.
Chapter 9 is when it starts.
Haskell isn't easy.
[+] [-] dchuk|13 years ago|reply
[+] [-] dragandj|13 years ago|reply
[+] [-] ashika|13 years ago|reply
[+] [-] stonemetal|13 years ago|reply
[+] [-] burke|13 years ago|reply
[+] [-] jerf|13 years ago|reply
[+] [-] hawkw|13 years ago|reply