Usage of rewrite rule specialization in Hackage

I'm looking for "real" code that uses the kind of GHC rewrite rule that specializes a polymorphic function with another one, as described here <http://www.haskell.org/ghc/docs/latest/html/users_guide/rewrite- rules.html#rule-spec>. Can anyone point me to any popular packages in Hackage that make use of this? Thanks, Scott

On Thu, May 5, 2011 at 10:36 AM, Scott Kilpatrick
I'm looking for "real" code that uses the kind of GHC rewrite rule that specializes a polymorphic function with another one, as described here <http://www.haskell.org/ghc/docs/latest/html/users_guide/rewrite- rules.html#rule-spec>. Can anyone point me to any popular packages in Hackage that make use of this?
I can't or rather won't go so far as point out specific Hackage packages. What I can give you is the output of grepping my 111k corpus, which resulted in 744 hits for RULES. Attached is the output of `find ~/bin -name "*.lhs" -exec grep -l "{-# RULES " {} \; -exec grep --after-context=3 "{-# RULES " {} \;`. Sample output: /home/gwern/bin/jaspervdj/blaze-builder/benchmarks/LazyByteString.hs {-# RULES "fromWriteReplicated/writeWord8" fromWriteReplicated writeWord8 = fromReplicateWord8 #-} /home/gwern/bin/bloomfilter/Data/BloomFilter.hs {-# RULES "Bloom insertB . insertB" forall a b u. insertB b (insertB a u) = insertListB [a,b] u #-} {-# RULES "Bloom insertListB . insertB" forall x xs u. insertListB xs (insertB x u) = insertListB (x:xs) u #-} {-# RULES "Bloom insertB . insertListB" forall x xs u. insertB x (insertListB xs u) = insertListB (x:xs) u #-} {-# RULES "Bloom insertListB . insertListB" forall xs ys u. insertListB xs (insertListB ys u) = insertListB (xs++ys) u #-} {-# RULES "Bloom insertListB . emptyB" forall h n xs. insertListB xs (emptyB h n) = fromListB h n xs #-} {-# RULES "Bloom insertListB . singletonB" forall h n x xs. insertListB xs (singletonB h n x) = fromListB h n (x:xs) #-} /home/gwern/bin/batterseapower/haskell-kata/DeforestFree.hs {-# RULES "reify/interpret" forall xs. interpret (reify xs) = xs #-} /home/gwern/bin/altaic/testsuite/tests/ghc-regress/simplCore/should_run/simplrun002.hs {-# RULES "foo" forall v . fst (sndSnd v) = trace "Yes" (fst v) #-} main :: IO () main = print (fst (sndSnd (True, (False,True)))) -- gwern http://www.gwern.net

On 5/5/11 10:36 AM, Scott Kilpatrick wrote:
I'm looking for "real" code that uses the kind of GHC rewrite rule that specializes a polymorphic function with another one, as described here<http://www.haskell.org/ghc/docs/latest/html/users_guide/rewrite- rules.html#rule-spec>. Can anyone point me to any popular packages in Hackage that make use of this?
Perhaps not the easiest example to look through, but just check out the base package. In particular, there are a number of functions which get specialized implementations for Int, Int#, Word, etc. -- Live well, ~wren
participants (3)
-
Gwern Branwen
-
Scott Kilpatrick
-
wren ng thornton