RE: RULES for SPECIALIZ(E)ations

| | I suppose I'm being bitten by User's Guide 7.8.2: | | "If more than one rule matches a call, GHC will choose one arbitrarily | to apply." | | even if a bit later it says: | | "So a rule only matches if the types match too." | | Am I understanding right and it's that so? I think so. After all, the types match for count/generic too. Maybe you want a rule genericLength = length which will replace a call to (genericLength at type Int) by a call to length? You can also use "phases" to control order of rule application (albeit it's crude). http://www.haskell.org/ghc/docs/latest/html/users_guide/pragmas.html#PHA SE-CONTROL Simon

On Mon, 20 Oct 2003 12:01:59 +0100
"Simon Peyton-Jones"
Maybe you want a rule
genericLength = length
which will replace a call to (genericLength at type Int) by a call to length?
That gave me the idea of making a module to contain general purpose rules, so I did: ----------------------------------------------------------------- module Local.Rules (genericLength) where import Data.List (genericLength) {-# RULES "generic/length" genericLength = length #-} ----------------------------------------------------------------- It works. (I was a bit puzzled to have to reexport genericLength, but on insight I suppose it's logical.) But I'm getting an error on recompilations that I don't understand. It happens only with -O (or -On), AFAICS. I have: ----------------------------------------------------------------- module Local.Test where import Local.Rules ----------------------------------------------------------------- Then: D:\lib\Local> del *.hi *.o Deleting D:\lib\Haskell\Local\Rules.hi Deleting D:\lib\Haskell\Local\Test.hi Deleting D:\lib\Haskell\Local\Rules.o Deleting D:\lib\Haskell\Local\Test.o 4 files deleted D:\lib\Local> ghc -fglasgow-exts --make -i.. Test.hs Chasing modules from: Test.hs Compiling Local.Rules ( ../Local/Rules.hs, ../Local/Rules.o ) Compiling Local.Test ( Test.hs, ./Test.o ) D:\lib\Local> ghc -fglasgow-exts --make -i.. Test.hs Chasing modules from: Test.hs Skipping Local.Rules ( ../Local/Rules.hs, ../Local/Rules.o ) Skipping Local.Test ( Test.hs, ./Test.o ) but, with -O: D:\lib\Local> ghc -O -fglasgow-exts --make -i.. Test.hs Chasing modules from: Test.hs Compiling Local.Rules ( ../Local/Rules.hs, ../Local/Rules.o ) Compiling Local.Test ( Test.hs, ./Test.o ) D:\lib\Local> ghc -O -fglasgow-exts --make -i.. Test.hs Chasing modules from: Test.hs Skipping Local.Rules ( ../Local/Rules.hs, ../Local/Rules.o ) tcLookupGlobal (id): `Data.List.genericLength' is not in scope When checking the transformation rule "generic/length" Is that a bug? Juanma

But I'm getting an error on recompilations that I don't understand. It happens only with -O (or -On), AFAICS.
On second (and less sleepy) thought, there's no mystery in it happening only with -O, as RULEs aren't used for non-optimizing compilations :) Still, it's weird to get an error on recompiling (and skipping) modules... Juanma

An even simpler example, with just one module: ------------------------------------------------------- module Test where import Data.List (genericLength) {-# RULES "genericLength/length" genericLength = length #-} ------------------------------------------------------- D:\...\hask> ghc -O -fglasgow-exts --make Test.hs Chasing modules from: Test.hs Compiling Test ( Test.hs, ./Test.o ) D:\...\hask> ghc -O -fglasgow-exts --make Test.hs Chasing modules from: Test.hs Skipping Test ( Test.hs, ./Test.o ) tcLookupGlobal (id): `Data.List.genericLength' is not in scope When checking the transformation rule "genericLength/length" Surely that *must* be a bug, mustn't? Juanma
participants (2)
-
Juanma Barranquero
-
Simon Peyton-Jones