Scheme vs Haskell (Programming Languages)

From Spivey's Corner
Jump to: navigation, search

Scheme, the language used in the book by Friedman and Wand, is a dialect of Lisp, and like all dialects of Lisp has a syntax like this:

(define (fac n)
  (if (= n 0) 
      1 
      (* n (fac (- n 1)))))

It looks frightening at first, and is impossible to type if your editor doesn't give help with matching of parentheses. But good editors for Lisp (such as Emacs, which is itself written in another dialect of Lisp) help with that and with indenting the lines nicely, so that one can soon get over the apparent unforgivingness of the concrete syntax.

Syntax aside, the main differences between Scheme and Haskell for our purposes are these:

  • Scheme uses eager evaluation in place of lazy evaluation.
  • Scheme is not purely functional: there are updateable cells, and Friedman and Wand use these to some advantage. For example, they avoid threading a memory state through their interpreters for languages with memory by storing the memory state in a mutable, global variable.
  • Scheme encourages an uncurried style. A curried style is possible: instead of (f x y z) for calling a function f with three arguments x, y and z, you can make f curried and write (((f x) y) z). But as you can see, this becomes painful. Unlike most Lisps, Scheme does allow the function that is being called to be itself the result of a function call, and this is what makes the curried style possible at all.