27 Aug 22:08
Re: Compiler's bane
Neil Mitchell <ndmitchell <at> gmail.com>
2008-08-27 20:08:51 GMT
2008-08-27 20:08:51 GMT
Hi > 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: 5 You seem to be combining the substitution and the removing of dead let bindings, if you separate them you should have more luck. Thanks Neil
> 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:
5
You seem to be combining the substitution and the removing of dead let
bindings, if you separate them you should have more luck.
Thanks
Neil
RSS Feed