> Are ($) and (.) actually treated specially within ghc then
> and optimized
> away from the rules? If so then rule rewriting becomes more
> powerful than
> I'd thought, beacuse the one of the problems I thought was
> there was that
> the idea that `several maps can be be turned into a single
> map of several
> applied functions' has many syntactic realisations, of which
> (map f).(map
> g) = map (f.g) is what everyone remembers because it's the
> most elegant,
> whereas the compiler may see some subtle variation of expression which
> doesn't affect the basic idea but would be missed by a simple
> `textual'
> matching.
No they aren't. In my prototype implementation, GHC inlines *nothing*
that appears on the LHS of a rule, because once you have substituted
for something you can't match against it (given my simple minded
matching).
So if you write
RULES map f . map g = map (f.g)
this *won't* match the expression
map f (map g xs)
It will only match something written with explicit use of ".".
Well, not quite. It *will* match the expression
wibble f g xs
where wibble is defined:
wibble f g = map f . map g
because wibble will be inlined (it's small).
Good questions.
Simon