1

I'm trying to learn the differences between imperative and functional languages.
And also, I want to learn about closures and how garbage collectors are implemented. So I decided to try to implement an interpreter for a functional language.

Since I'm not familiar with functional languages, it's too difficult for me to design one. Are there some resources about the syntax and semantics of a simple functional language? A tutorial on how to do this would be very helpful.

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
haipeng31
  • 635
  • 1
  • 7
  • 16
  • 2
    You've got it way backwards. You need to understand functional languages first before you think you're going to interpret one, by definition. Simply pick one and learn one, way better direction for you. Anyway, closing as not a real question; far too broad. – GManNickG Feb 22 '13 at 01:26
  • Better look for a _simple_ functional programming implementation that you can study. Trying to do it on your own is a _huge_ undertaking. – vonbrand Feb 22 '13 at 01:27
  • 1
    Syntax has absolutely nothing to do with whether a language is functional, except perhaps providing "anonymous function" syntax. – Dan Burton Feb 22 '13 at 02:24
  • *And also,I want to get used to clousure* do you mean *Clojure*? – Ingo Feb 22 '13 at 09:35
  • Here's something you might find useful: [a Scheme implementation tutorial](http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours). I'd love to add this as an answer if it weren't closed!!! – Matt Fenwick Feb 22 '13 at 11:17

3 Answers3

8

Please consider:

Implementing functional languages: a tutorial
Simon Peyton Jones and David Lester. Published by Prentice Hall, 1992.

Available online, which covers increasingly sophisticated approaches to implementing compiled lazy functional languages.

The follow up with the STG machine paper, describing the core of the GHC runtime.

Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
Don Stewart
  • 137,316
  • 36
  • 365
  • 468
6

Oddly enough, there is. The Structure and Interpretation of Computer Programs book has exercises where Scheme is implemented in Scheme. But the preparatory material cannot be skipped. You're going to need to know it (and how to program in a functional language), especially when you go to implement the interpreter in the interpreter.

ldav1s
  • 15,885
  • 2
  • 53
  • 56
1

You could do worse than reading John Allen's the Anatomy of Lisp. For lazy languages.

Theodore Norvell
  • 15,366
  • 6
  • 31
  • 45