Fun with GHC's optimiser

Manuel M. T. Chakravarty
Fri, 22 Dec 2000 17:13:07 +1100


> But I think the way to handle
> it is this.  Suppose we have
> 	f x y = ....(f ex (C a b))...
> where C is a constructor, and where y is scrutinised by a 
> case expression somewhere in f's body.  Then, in this recursive
> call to f, we know what y will be, and we could save the case in 
> the recursive call.  So make a specialised version of f, thus:
> 	fs x a b = let y = C a b in (...original body of f...)
> Now add a RULE to f, saying
> 	f x (C a b) ===> fs x a b
> This is very much the way type specialisation works.  Now every
> call to f that has a (C a b) argument will benefit.  Including
> the recursive call to f in fs's RHS, so fs will become the self-recursive
> tight loop you want, leaving f as a sort of 'impedence matcher' for
> callers elsewhere.

Sounds like a good idea to me :-)