Why I recommend Scheme

I like to hang around on a French-speaking, programming IRC channel. I’m known there as “the language guy” because of my hobby of trying all sorts of different and weird languages. I’m also known as being the guy that touts the merits of functional programming and Haskell from time to time.

Some of the guys over there have asked me which language I recommend they use to learn functional programming. Despite my liking Haskell very much, my answer is always the same: Scheme.

Haskell is a very nice language, it has a plethora of desirable features and it will positively influence other languages. However, Haskell is also a very complex language, there are many things in the language that stump people who want to pick it up (I had to try four separate times before I finally “clicked” with Haskell!) I do not find that it is suitable for someone who just wants to see what functional programming is about.

Let’s look at both languages side by side:

  Haskell Scheme
Typing Static typing. Though I am now convinced that a solid static typing system such as Haskell’s is a definite advantage when building software, it introduces a lot of complexity too. Inference, type classes, algebraic data types, existential types, phantom types, etc. That’s a lot of scary words and complexity for a newcomer, and static typing has nothing to do with learning the functional paradigm. Dynamic typing. It doesn’t catch type mismatch problems before accepting to compile your program, but it’s very simple to use and has a very low mental requirement. Ideal for learning about something other than type systems. The error messages given at run-time by Scheme on type errors are simpler than Haskell’s often cryptic compile-time error messages.
Syntax Haskell has a very beautiful syntax, but it’s a more complex one than Scheme’s. You need to be wary of operator precedence, layout rules (Haskell can be indentation-dependant) and other syntactic sugars which make Haskell nice to use when you know them, but can be a stumbling block when learning the language. Scheme has one of the simplest syntax of any programming language. The rules can be explained in minutes. The syntax is unlike what most people are used to, especially if they come from a C-syntax background, but it’s easy to pick up and use.
Laziness Haskell has lazy evaluation. Lazy evaluation has its benefits, which I will not discuss here, but it is harder to understand when something will happen. Scheme has eager evaluation, which is what most programmers are used to and is easier to reason about.
Environment The REPL of Haskell does not expose the entire language, it has limitations: for example, you can’t define functions or types as you would in your editor. So it can sometimes be little painful to test things interactively in GHCi. DrScheme is an easy, friendly and free environment for Scheme that is ideal for learning. You can type anything you like in the REPL and Scheme will happily execute it. It also features an editing pane to write code and at the press of a button, the code in the pane is compiled. DrScheme also offers nice debugging and profiling tools.
Literature Before “Real World Haskell”, there were not a lot of free, easily accessible books for Haskell on the Internet. Some of the newbie-oriented tutorials were actually quite daunting, making it hard to suggest reading material to somebody who wanted to learn functional programming. Scheme has more books freely available on the Internet: “How To Design Programs” for people new to programming, Scheme and/or functional programming or the grand classic “Structure and Interpretation of Computer Programs” for the more serious and advanced students. “Teach Yourself Scheme in Fixnum Days” is somewhere in between. All books are of great quality and great value.
About these ads

9 thoughts on “Why I recommend Scheme

  1. You are wrong about ghci not being able to define functions.
    Prelude> let double x = 2 * x
    Prelude> double 5

    It is true that you can’t define types, but to me it never mattered.
    However, DrScheme is actually superior to ghci in the editing capabilities of REPL. Someone (maybe me? :) ) should one day write a similar thing for haskell; should not be too hard to attach an editor to ghci. Maybe the emacs mode for haskell does that, dunno, I don’t use emacs.

  2. One big problem is that these days there is a lot more haskell hype than scheme hype. Personally though I failed to learn Haskell.

    I am too stupid :) I however came from the other side, starting with perl, php and ruby, so the functional programming world is still somewhat alien to me

  3. jkff, the quote from the article was “you can’t define functions or types as you would in your editor”. This much is true — you are forced to use the let construct rather than just type “double x = 2 * x” into GHCi. The syntax of GHCi input is more similar to that of an IO do-block (with magic return-ing for nonmonadic values).

  4. jfkk: You can define simple functions, but you can’t do something pattern matching such as:

    fact :: Integral a => a -> a
    fact 1 = 1
    fact n
    | n > 1 = n * fact (n – 1)
    | otherwise = error “Positive integer required”

    As for defining types, I’m pretty sure that I’m not the only this has bothered before.

    markus: I don’t think that’s a problem: Scheme exists, works and is a great education tool. If Haskell’s hype and success can entice new people to learn functional programming, that’s great too.

  5. gnuvince: You can define functions that pattern match in ghci:

    Prelude> let fact :: Integral a => a -> a; fact 1 = 1; fact n | n > 1 = n * fact (n – 1) | otherwise = error “Positive integer required”
    Prelude> fact 10

    Types are a different matter, you can only define those outside of ghci.

  6. To use an editor with ghci: “:set editor vi”
    Then launch it with “:e”.

    Perhaps not as user friendly as an editor pane, but anyway…

  7. Pingback: links for 2008-08-24 « Mike Does Tech

  8. I dont like lazzines is more trouble than benefits, in the other side PLT-Scheme is the only free out the box for multiplatform gui programming.

  9. @markus:
    Well, if you do come from a perl background, or ruby background, you will be quickly overwhelmed by the sheer /math/ and /types/ of the haskell language. I myself learned to program in haskell, at the same as my friend. The difference being, that haskell was my first language, and my friend was coming from a Python/C/C++ background. I picked it up much quicker than said friend, because I didn’t have a preconception of what “programming” was like. It was a new concept, and everything made sense because of that. In addition, I understand better the constructs of languages like Java, Python, C++ in terms of mathematics; arguably I occaisionally write better Java/C++/Python code, than my counterparts who didn’t know haskell. My advice is try to “forget” how to program, and pick up Learn You A Haskell For Great Good (google for it).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s