Skip to content

Haskell vs. Scheme: learning the syntax

by Stephen Mann on January 30th, 2010

I think scheme would be a more eye-opening experience if I hadn’t already spent time learning haskell. I’m not into the advanced features of scheme yet (though I suspect there aren’t many), but I have noticed something about basic syntax differences: haskell uses more syntactical constructs and relies on more symbols, whereas scheme uses only a single syntactial construct, and uses almost no symbols.

I apprciate scheme for its purity, and haskell for its conciseness. Ultimately, I think the more concise language is the one I’d prefer to work in.

Here’s a concrete example: the functions below are functionally identical.

Scheme:

(define (my-map f lst)
    (cond
     [(empty? lst) empty]
     [else (cons (f (first lst))
                 (my-map f (rest lst)))]))

Haskell:

map f []     = []
map f (x:xs) = f x : map f xs

Not only are these functions functionally identical (they do the same thing), they’re functionally identical (they do it in exactly the same way). The tokens line up almost one-to-one. The only differences are:

  • haskell doesn’t require a keyword to define a function or value
  • haskell uses pattern matching instead of “cond”
  • haskell uses pattern matching (x:xs) to separate out the first element of the list and the rest

That, I think, should give you an idea of why I don’t think it’s going to be a problem to move from one to the other.

From → tech

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS