@@ -228,20 +228,22 @@ tail (Stream next0 s0 len) = Stream next (C0 s0) (len-1)
228228 Yield x s' -> Yield x (C1 s')
229229{-# INLINE [0] tail #-}
230230
231+data Init s = Init0 !s
232+ | Init1 {-# UNPACK #-} !Char !s
231233
232234-- | /O(1)/ Returns all but the last character of a Stream Char, which
233235-- must be non-empty.
234236init :: Stream Char -> Stream Char
235−init (Stream next0 s0 len) = Stream next (N :*: s0) (len-1)
237+init (Stream next0 s0 len) = Stream next (Init0 s0) (len-1)
236238 where
237− next (N :*: s) = case next0 s of
239+ next (Init0 s) = case next0 s of
238240 Done -> emptyError "init"
239− Skip s' -> Skip (N :*: s')
240− Yield x s' -> Skip (J x :*: s')
241− next (J x :*: s) = case next0 s of
241+ Skip s' -> Skip (Init0 s')
242+ Yield x s' -> Skip (Init1 x s')
243+ next (Init1 x s) = case next0 s of
242244 Done -> Done
243− Skip s' -> Skip (J x :*: s')
244− Yield x' s' -> Yield x (J x' :*: s')
245+ Skip s' -> Skip (Init1 x s')
246+ Yield x' s' -> Yield x (Init1 x' s')
245247{-# INLINE [0] init #-}
246248
247249-- | /O(1)/ Tests whether a Stream Char is empty or not.