47

I currently code with C, C++, and Python. I'm wanting to pick up a functional programming language, and right now I'm leaning toward Haskell. I do NOT want to start a "Haskell vs Lisp" war here; what I want to know is this: if I learn Haskell primarily for exposure to functional programming, what benefits, if any, will I gain from later learning Lisp?

1
  • 1
    And F# and Clojure.
    – cnd
    Feb 13, 2012 at 11:45

7 Answers 7

64

I suggest learning both, Haskell first, then Common Lisp. My experience with Haskell was that the static typing seemed to be a restricting annoyance at first, but once I got used to it, I noticed that most of my type errors had logic errors hiding behind them. When you get to this point, and the next milestone, which is learning to think in types and define your own types as a means of expressing your solution, you'll be ready for Common Lisp.

With Common Lisp, you can add monads, currying, and everything you liked from Haskell, but you also get multiple inheritance like Frank Shearar mentioned, and generic functions with multiple dispatch, and an advanced exception handling system.

So why not just learn Common Lisp first? Coming from a procedural and OOP background, my experience has been that I didn't really understand functional programming until I had to use it exclusively. Once functional programming is comfortable, you can add the rest of the tools that Common Lisp makes available, and use whatever tool is best at the task at hand.

3
  • 7
    I think you nailed it - what makes Haskell and Smalltalk so useful for learning is their purity. Nov 14, 2010 at 11:44
  • 5
    I agree with the purity makes learning a language a lot easier. I couldn't understand functional language itself with LISP because everything are possible in the language and I have too much imperative, OO background. But in Haskell, there is no such concepts which disrupt learning.
    – Eonil
    Feb 16, 2011 at 2:09
  • 1
    It's funny, I've had the opposite experience. I picked up the main points of functional programming through Scheme, my first language. I occasionally hack in Haskell and I inevitably find that I have to relearn 90%+ of the stuff that I knew whenever I leave Haskell for a while. That being said, Haskell is an incredibly rich language, with a huge amount to teach you (very forcibly.) Types Types Types Types! Follow the types! Apr 1, 2012 at 4:59
33

AND please.

Haskell teaches you the purest of FP, as far as I'm aware at least, just like Smalltalk teaches the purest of OO. (I mention this not to suggest that OO and FP can't marry, but because both these languages are "gem" languages - a core idea taken to extremes.)

Lisp is really a family of languages, so I'll talk about Common Lisp because that's the particular member of the family I use.

Lisp will still have lots to teach you:

  • It's multiparadigm, so as dsimcha points out it'll show you how to integrate FP with other paradigms.
  • Lisp will teach you that "code-is-data, data-is-code", for example through its macros.
  • CLOS is a very interesting brand of OO, with multiple inheritance that works, and generic functions.
12

Learning Lisp later will allow you to customize Emacs which arguably is the most advanced text editor available. You can't do that in Haskell.

8
  • 16
    [Sharpens his parentheses]
    – Inaimathi
    Nov 13, 2010 at 20:35
  • 6
    Maybe someone can write a text editor for it. I hear the Emacs operating system doesn't come with one. (I kid. I know you can get Viper mode. :)
    – greyfade
    Nov 13, 2010 at 23:04
  • 16
    Actually, there is an Emacs-clone called Yi, which uses Haskell in exactly the same way as Emacs uses Lisp. In fact, compared to (GNU) Emacs, Yi is even purer, because its kernel is also written in Haskell, whereas Emacs kernels generally tend not to be written in Lisp. GNU Emacs' kernel is written in C, JEmacs' is written in Java, for example. Nov 13, 2010 at 23:09
  • 2
    @Jörg, if it is a partial reimplementation instead of a full clone of GNU Emacs or XEmacs, it is not the same thing. Similar to comparing Word to Wordpad or Notepad.
    – user1249
    Nov 13, 2010 at 23:26
  • 1
    @Thorbjørn Ravn Andersen: Yes, but not quite that bad. :)
    – greyfade
    Nov 14, 2010 at 4:27
12

Haskell and Lisp are two totally different beasts.

Haskell is kindof "pure functional programming in an ivory tower"

Lisp is kindof "code-is-data / data-is-code / make your own language constructs". You can manipulate your code in whatever way you can imagine.

They are very different. Both share the "functional programming" aspect, but that's really a tiny little common point compared to their differences. Just try them out and you will see how different they are!

1
  • +1: Good point. I know some Haskell and some Lisp. Even though I am not an expert in either of them, I think you are right that they are very different. In Haskell you do not have the idea of using data as code. In Lisp you do not have (AFAIK) pattern matching. Probably the list (!) of differences is longer.
    – Giorgio
    Jul 3, 2012 at 5:35
8

The main benefit I see from learning Lisp is learning how to integrate FP into a real-world oriented multiparadigm language, rather than only learning it in the context of an academic language that emphasizes purity.

4
  • 5
    I guess you do want a "Haskell vs Lisp" war!
    – Don Roby
    Nov 13, 2010 at 17:59
  • 3
    Haskell is an academic language that emphasises purity... and lots of people use it in the real world. Smalltalk's in that camp too. Nov 13, 2010 at 18:06
  • Lots of people use Haskell in the real world?
    – J D
    Dec 27, 2010 at 19:28
  • 1
    @Jon Harrop: Well, I do use Haskell in the real world (and it works really fine for certain applications), maybe I am one of the few (?)
    – Giorgio
    Aug 2, 2012 at 8:38
5

I also come from a C/C++/Python background and have tried out FP a couple of times in the last few years. Initially I looked at Haskell and couldn't make head or tail of it, then tried Ocaml but didn't get much further with that. Finally I started hearing good things about Scala, tried it, and found it suited me very well (I had also done a bit of Java in the past), to the point that after a year of so of dabbling in Scala (and dispatching 161 Project Euler problems with it), Haskell seems to make much more sense. In fact I just ordered a couple of books on Haskell and want to give it another go, although this is largely motivated by the existence of Scalaz.

So I found using a multi-paradigm language (ie Scala, but Lisp would probably fit the bill too) a good way into FP. But if you're happy diving into Haskell (I wasn't), go for it.

3
  • Interesting that you got further with Scala than OCaml. How come?
    – J D
    Dec 27, 2010 at 19:32
  • @Jon: Good question; hard to say. Maybe I just wasn't ready to "get into" functional at the time. Maybe I just happened to find a Scala tutorial pitched at the right level. Maybe Scala's C/C++/Java lineage just made it a bit less alien. Given any rational bet these days would be on F# rather than Scala, I'll probably revisit the OCaml domain at some point, although since I dabble in this stuff just for the sheer joy of getting into a different "programming mindset" to my C++ dayjob, I have a perverse inclination to retry Haskell again next.
    – timday
    Dec 27, 2010 at 20:37
  • Smooth moving approach :)
    – Eonil
    Feb 16, 2011 at 2:41
2

I originally came from a C/C++/Ruby background and I used FP concepts in Ruby whenever I could. State just kinda hurt my brain. One of my buddies called me up one day, and he asked me to write something in Haskell (my first - and hopefully not last - Haskell job!). I quickly learned the language and I threw together something that worked. It wasn't beautiful or anything, but it worked.

I took a month break from Haskell because I didn't have anything to use it for. But when I decided I needed to write my own blog software, I used Haskell (https://symer.io). Haskell is really cool because you can break a problem into parts and implement these parts differently based on input. Haskell also handles failure extremely well through intelligent boxing of values. There are so many tools to work with these boxes that you simply forget they exist.

My experience with lisp (Scheme) was completely negative. Not only did the language lack these intelligent, simple tools, it felt as dangerously loose as Ruby or JavaScript. It was a horrible experience and it offers nothing new beyond Ruby or Python.

C++ can't hold a candle to Haskell, outside of memory management. Haskell is just as fast (if not faster), significantly more terse, and much more safe. But Haskell's safety never gets in the way.

TL;TR Haskell is a breath of fresh air, and Lisp is a slightly more functional Ruby.

Not the answer you're looking for? Browse other questions tagged or ask your own question.