Quick question re RULES

Manuel M. T. Chakravarty chak@cse.unsw.edu.au
Thu, 02 Nov 2000 19:08:25 +1100


PrelBase contains the appended code.  Am I correct in
assuming that the stuff is structured as it is, because the
"map" rule first `breaks' the map `open', which exposes it
to the various foldr/build rules, and if no foldr/build rule
matches, the "mapList" rule `closes' it again in a later
phase of optimisation - after build was inlined?  If so, it
seems like the whole thing depends a bit on the timing of
the various optimsations (the map might be closed again
before any of the foldr/build rules fires).  Is this maybe
the reason that build has an INLINE 2 pragma, which delays
its inlining, and thus, the closing of the map?

All very cunning, it seems ;-)

Cheers,
Manuel

-=-

map :: (a -> b) -> [a] -> [b]
map = mapList

-- Note eta expanded
mapFB ::  (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst
mapFB c f x ys = c (f x) ys

mapList :: (a -> b) -> [a] -> [b]
mapList _ []     = []
mapList f (x:xs) = f x : mapList f xs

{-# RULES
"map"	    forall f xs.	map f xs		= build (\c n -> foldr (mapFB c f) n xs)
"mapFB"	    forall c f g.	mapFB (mapFB c f) g	= mapFB c (f.g) 
"mapList"   forall f.		foldr (mapFB (:) f) []	= mapList f
 #-}