syntax of RULES pragmas?

Janis Voigtlaender voigt@orchid.inf.tu-dresden.de
Thu, 16 May 2002 15:48:38 +0200


Hi,

I was trying to play with GHC 5.02's RULES pragmas, but failed due to
syntax problems.

When trying:

  {-# RULES "map/map" forall f g xs. map f (map g xs) = map (f.g) xs #-}

  main = print (map id (map id "Hello"))

I get:

  ghc5 test.hs -O
  test.hs:1: Variable not in scope: `forall'

  test.hs:1: Variable not in scope: `f'

  test.hs:1: Variable not in scope: `g'

  test.hs:1: Variable not in scope: `xs'

  test.hs:1: Variable not in scope: `f'

  test.hs:1: Variable not in scope: `g'

  test.hs:1: Variable not in scope: `xs'

  test.hs:1: Variable not in scope: `f'

  test.hs:1: Variable not in scope: `g'

  test.hs:1: Variable not in scope: `xs'
  Exit 1


With:

  {-# RULES "map/map" forall f g xs. 
  map f (map g xs) = map (f.g) xs #-}

  main = print (map id (map id "Hello"))

I get:

  test.hs:2: parse error (possibly incorrect indentation)
  Exit 1


In the user's doc on http://www.haskell.org/ghc/ I also saw the syntax:

  {-# RULES "map/map" forall f,g,xs. map f (map g xs) = map (f.g) xs #-}

  main = print (map id (map id "Hello"))

which fails with:

  test.hs:1: parse error on input `,'
  Exit 1


So how exactly do I have to specify a rewrite rule? Any hints
appreciated.

Thanks, Janis.


--
Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:voigt@tcs.inf.tu-dresden.de