partial evaluation

D. Tweed
Mon, 4 Feb 2002 12:03:10 +0000 (GMT)

On Mon, 4 Feb 2002, Simon Peyton-Jones wrote:

> If you say {-# INLINE f #-} on a fn defn for f, it'll get inlined at
> all its call sites, which is sort of what you want.  Just saying 
> 'evaluate this CAF to WHNF' might only inline the outer combinator.
> Generally, some precise way of controlling what gets evaluated
> at compile time, a bit less heavyweight than MetaML, would be a fine
> thing.    After all that's what C++ templates are. 
> But the details of a workable design aren't clear to me.   Ideas?

This is from a rank amateur, so take it with a pinch of salt...

It would be useful to see typical examples of CAFs for which this would be
expected to be useful. In my (limited) programming I haven't come across
that many, with the dominant example being `symbol table' type things, for
which I've generally had a script write out a Haskell module containing
the defs. Other than being slightly more work, the only hassle is that it
forces an otherwise unecessary Show into the type. What other examples
are there where normal evaluation at compile time would be useful?

As far as I know the principal advantage of templates functions in C++
(which I think you're talking about) is that they can be seen as
generating further code (probably in the form of abstract syntax tree
nodes) which is then exposed to the usual _compiler_ optimizations
(abstract evaluation and rewriting is I guess the formal terms) such as
hoisting loop invariants, collapsing addressing arithmetic, etc. It's not
totally clear to me that analogous Haskell stuff can be done using
`standard Haskell evaluation' as opposed to compiler optimizations.

___cheers,_dave_________________________________________________________|`...heat generated by its microprocessors will|slope upward exponentially, reaching the power
work tel:(0117) 954-5250 |density of a nuclear reactor before 2010'-Intel