@@ -97,7 +97,7 @@ singleton c = putChar c
9797--
9898append :: Builder -> Builder -> Builder
9999append (Builder f) (Builder g) = Builder (f . g)
100−{-# INLINE append #-}
100+{-# INLINE [1] append #-}
101101
102102-- TODO: Experiment to find the right threshold.
103103copyLimit :: Int
@@ -201,13 +201,13 @@ ensureFree !n = withSize $ \ l ->
201201 if n <= l
202202 then empty
203203 else flush `append` withBuffer (const (newBuffer (max n defaultChunkSize)))
204−{-# INLINE ensureFree #-}
204+{-# INLINE [1] ensureFree #-}
205205
206206-- | Ensure that @n@ many elements are available, and then use @f@ to
207207-- write some elements into the memory.
208208writeN :: Int -> (forall s. A.MArray s Word16 -> Int -> ST s ()) -> Builder
209209writeN n f = ensureFree 1 `append` withBuffer (writeNBuffer n f)
210−{-# INLINE writeN #-}
210+{-# INLINE [1] writeN #-}
211211
212212writeNBuffer :: Int -> (A.MArray s Word16 -> Int -> ST s ()) -> (Buffer s)
213213 -> ST s (Buffer s)
@@ -235,3 +235,21 @@ unsafeCopy src sidx dest didx count =
235235 | otherwise = do A.unsafeWrite dest j (A.unsafeIndex src i)
236236 copy_loop (i+1) (j+1) (c+1)
237237{-# INLINE unsafeCopy #-}
238+
239+------------------------------------------------------------------------
240+-- Some nice rules for Builder
241+
242+{-# RULES
243+
244+"writeN/combine" forall a b (f::forall s. A.MArray s Word16 -> Int -> ST s ())
245+ (g::forall s. A.MArray s Word16 -> Int -> ST s ()).
246+ append (writeN a f) (writeN b g) =
247+ (writeN (a+b) (\marr o -> f marr o >> g marr (o+a)))
248+
249+"ensureFree/combine" forall a b .
250+ append (ensureFree a) (ensureFree b) = ensureFree (max a b)
251+
252+"flush/combine"
253+ append flush flush = flush
254+
255+ #-}