Rewrite rules in Core
Guilherme Avelino
gavelino at gmail.com
Fri Mar 7 22:25:35 EST 2008
When I compile the follow code
main :: IO()
main = print ((iterate anyFunc 3)!!8)
is generated, in the core representation, a call to iterateFB1 instead of
iterate. Does this happen due to rule described below?
{-# RULES
"iterate" [~1] forall f x. iterate f x = build (\c _n -> iterateFB c f
x)
"iterateFB" [1] iterateFB (:) = iterate
#-}
Thanks.
2008/3/7, Tim Chevalier <catamorphism at gmail.com>:
>
> On 3/7/08, Guilherme Avelino <gavelino at gmail.com> wrote:
> > Hi,
> >
> > I´m using the flag -fext-core to obtain the core of a program. But,
> rewrite
> > rules not changed this code. Are there any way to observe the changes
> cause
> > by rewrite rules on Core language?
> >
> > For sample:
> >
> > iterate :: (a -> a) -> a -> [a]
> > iterate f x = x : iterate f (f x)
> >
> > iterateFB c f x = x `c` iterateFB c f (f x)
> >
> >
> > {-# RULES
> > "iterate" [~1] forall f x. iterate f x = build (\c _n ->
> iterateFB c
> > f x)
> > "iterateFB" [1] iterateFB (:) = iterate
> > #-}
> >
> > generates the same core representation with or without the rules.
> >
>
>
> Be sure you're compiling with the -O or -O2 flag. By default,
> optimization is off, which means GHC doesn't try to apply rewrite
> rules (among other things.)
>
> If you do have optimization on, there are interactions between rules
> and other optimizations that can keep rules from firing. So, let us
> know in that case, and we can try to help more.
>
> Cheers,
> Tim
>
>
> --
> Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
> "It may be true that the law cannot make a man love me, but it can
> stop him from lynching me, and I think that's pretty important." --
> Martin Luther King, Jr.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/cvs-ghc/attachments/20080308/77c7fa34/attachment.htm
More information about the Cvs-ghc
mailing list