[Haskell-cafe] Compiler's bane

Neil Mitchell ndmitchell at gmail.com
Wed Aug 27 16:08:51 EDT 2008


> I'm writing a simple interpretter for a small extended-lambda-calculus sort
> of language. And I'd just like to say... RECURSIVE LET-BINDS! GAAAAH!!! >_<

Agreed :-)

> To illustrate:
>  let x = f x; y = 5 in x y
> A simple-minded interpretter might try to replace every occurrance of "x"
> with "f x". This yields
>  let y = 5 in (f x) y

That's wrong, its a two step transformation. You just substitute all
occurances of x for f x:

let x = f (f x); y = 5 in (f x) y

For the case let x = 5 in x, you do the same thing:

let x = 5 in 5

Now as a second step you hoover up unused let bindings and disguard:


You seem to be combining the substitution and the removing of dead let
bindings, if you separate them you should have more luck.



More information about the Haskell-Cafe mailing list