[Haskell-cafe] Language semantics
andrewcoppin at btinternet.com
Sun Jul 1 12:06:10 EDT 2007
Stefan O'Rear wrote:
> This is *much* easier expressed as a bottom-up traversal.
> compile = transform optimize . transform eliminate
> eliminate (Lam v e) = transform (abstract v) e
> eliminate x = x
> abstract v (Var v') | v == v' = I
> abstract v (a :@ b) = S :@ a :@ b
> abstract v x = x
> optimize (S :@ (K :@ x) :@ (K :@ y)) = K :@ (x :@ y)
> optimize (S :@ (K :@ x) :@ I) = x
> optimize x = x
> (Here using Uniplate, mostly because it is the freshest in my mind of
> all of them).
Um... shouldn't that read
abstract v (a :@ b) = S :@ (transform (abstract v) a) :@: (transform
(abstract v) b)
Or am I missing something?
More information about the Haskell-Cafe