Arrows and GHC rewrite rules
simonpj at microsoft.com
Fri Mar 30 10:37:53 EDT 2007
Well observed. There are two difficulties here.
First is a persistent bug-bear: GHC compiles
foo :: SF (Int,Int) (Int,Int)
foo = first (arr (+1)) >>> first (arr (+2) >>> arr (+3))
dsf :: Arrow SF
dsf = ...
first_1 = Control.Arrow.first SF dsf
arr_1 = Control.Arrow.arr SF dsf
foo = first_1 (arr_1 (+1)) ...etc...
GHC is trying to get more sharing by sharing the computation for selecting the 'first' method of dsf. But getting this sharing (which is worth little) defeats the rule, since there is no occurrence of the pattern the rule looks for.
You can switch off this (dubious) sharing optimisation with -fno-method-sharing.
Would someone care to document this at
The second is a plain bug: RULES for class methods are not being exported at all. So they aren't getting outside of Control.Arrow at the moment. I'm committing a patch right now.
| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-bounces at haskell.org] On
| Behalf Of Eric Cheng
| Sent: 30 March 2007 03:35
| To: glasgow-haskell-users at haskell.org
| Subject: Arrows and GHC rewrite rules
| In GHC's Control.Arrow implementation, there are several rewrite rules
| which exploit some properties of arrows. For example,
| > "compose/arr" forall f g . arr f >>> arr g = arr (f >>> g)
| > "first/arr" forall f . first (arr f) = arr (first f)
| > "second/arr" forall f . second (arr f) = arr (second f)
| ... and so forth.
| Now say I have a simple arrow instance:
| > newtype SF a b = SF ([a] -> [b])
| > instance Arrow SF where
| > arr f = SF (map f)
| > first (SF f) = SF g
| > where g l = let (x, y) = unzip l
| > in zip (f x) y
| > (SF f) >>> (SF g) = SF (g . f)
| and some arrow composition:
| > foo :: SF (Int,Int) (Int,Int)
| > foo = first (arr (+1)) >>> first (arr (+2) >>> arr (+3))
| I was expecting that ghc would at least make use of compose/arr or
| even first/arr, but it didn't appear to be the case. I was using
| ghc-6.6, and -ddump-simpl-stats showed a bunch of list-specific rules
| were fired (map, mapFB, fold/build, etc), but I did not see any
| arrow-related rules being applied.
| Were the rewrite rules subsumed by inlining or beta-reduction? Am I
| missing something here?
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
More information about the Glasgow-haskell-users