GHC rewrite rules pragma

Jan Jakubuv jakubuv at
Tue May 27 13:00:00 EDT 2008


I'm trying to find out how the GHC rewrite rules pragma work, but I'm
not able to make it working. I have this simple example, where I would
like to specialize the function gen to spec on strings:

{-# OPTIONS -O2 -fglasgow-exts #-}

gen :: [a] -> a
gen = head

{-# RULES "gen/Char" gen=spec #-}
spec :: [Char] -> Char
spec x = 'x'

main :: IO ()
main = putStr (gen "aaa":"\n")

-- EOF

I compile it as:
   ghc -O2 -fglasgow-exts spec.hs

but as a result, is always prints 'a' while I expect 'x'. Is it right?
What is the problem here? I would be glad for any answer. I'm using
GHC 6.8.2.


More information about the Glasgow-haskell-users mailing list