@@ -14,7 +14,7 @@ module Streaming.Internal (
1414 -- * The free monad transformer
1515 -- $stream
1616 Stream (.. )
17-
17+
1818 -- * Introducing a stream
1919 , unfold
2020 , replicates
@@ -28,18 +28,18 @@ module Streaming.Internal (
2828 , delays
2929 , never
3030 , untilJust
31-
31+
3232 -- * Eliminating a stream
3333 , intercalates
3434 , concats
3535 , iterT
3636 , iterTM
3737 , destroy
3838 , streamFold
39-
39+
4040 -- * Inspecting a stream wrap by wrap
4141 , inspect
42-
42+
4343 -- * Transforming streams
4444 , maps
4545 , mapsM
@@ -52,15 +52,15 @@ module Streaming.Internal (
5252 , distribute
5353 , groups
5454-- , groupInL
55-
55+
5656 -- * Splitting streams
5757 , chunksOf
5858 , splitsAt
5959 , takes
6060 , cutoff
6161 -- , period
6262 -- , periods
63-
63+
6464 -- * Zipping and unzipping streams
6565 , zipsWith
6666 , zipsWith'
@@ -72,18 +72,18 @@ module Streaming.Internal (
7272 , expand
7373 , expandPost
7474
75-
75+
7676 -- * Assorted Data.Functor.x help
7777 , switch
78-
78+
7979 -- * For use in implementation
8080 , unexposed
8181 , hoistExposed
8282 , hoistExposedPost
8383 , mapsExposed
8484 , mapsMExposed
8585 , destroyExposed
86-
86+
8787 ) where
8888
8989import Control.Applicative
@@ -158,6 +158,8 @@ instance (Monad m, Ord (m (Either r (f (Stream f m r)))))
158158 (<=) = (<=) `on` inspect
159159 (>=) = (>=) `on` inspect
160160
161+ #if MIN_VERSION_base(4,9,0)
162+
161163-- We could avoid a Show1 constraint for our Show1 instance by sneakily
162164-- mapping everything to a single known type, but there's really no way
163165-- to do that for Eq1 or Ord1.
@@ -179,6 +181,8 @@ instance (Monad m, Functor f, Ord1 m, Ord1 f) => Ord1 (Stream f m) where
179181 liftCmpExposed _ (Return _) = GT
180182 liftCmpExposed _ _ = error " liftCmpExposed: stream was exposed!"
181183
184+ #endif
185+
182186-- We could get a much less scary implementation using Show1, but
183187-- Show1 instances aren't nearly as common as Show instances.
184188--
@@ -200,6 +204,8 @@ instance (Monad m, Show r, Show (m ShowSWrapper), Show (f (Stream f m r)))
200204 Left r -> showString " Return " . showsPrec 11 r
201205 Right f -> showString " Step " . showsPrec 11 f)
202206
207+ #if MIN_VERSION_base(4,9,0)
208+
203209instance (Monad m , Functor f , Show (m ShowSWrapper ), Show (f ShowSWrapper ))
204210 => Show1 (Stream f m ) where
205211 liftShowsPrec sp sl p xs = showParen (p > 10 ) $
@@ -211,6 +217,8 @@ instance (Monad m, Functor f, Show (m ShowSWrapper), Show (f ShowSWrapper))
211217 Right f -> showString " Step " .
212218 showsPrec 11 (fmap (SS . (\ str i -> liftShowsPrec sp sl i str)) f))
213219
220+ #endif
221+
214222newtype ShowSWrapper = SS (Int -> ShowS )
215223instance Show ShowSWrapper where
216224 showsPrec p (SS s) = s p
@@ -227,7 +235,7 @@ instance (Functor f, Monad m) => Functor (Stream f m) where
227235 Return _ -> Return a
228236 Effect m -> Effect (do {stream' <- m; return (loop stream')})
229237 Step f -> Step (fmap loop f)
230- {-# INLINABLE (<$) #-}
238+ {-# INLINABLE (<$) #-}
231239
232240instance (Functor f , Monad m ) => Monad (Stream f m ) where
233241 return = Return
@@ -243,7 +251,7 @@ instance (Functor f, Monad m) => Monad (Stream f m) where
243251 Step fstr -> Step (fmap loop fstr)
244252 Effect m -> Effect (fmap loop m)
245253 Return r -> f r
246- {-# INLINABLE (>>=) #-}
254+ {-# INLINABLE (>>=) #-}
247255
248256 fail = lift . fail
249257 {-# INLINE fail #-}
@@ -276,8 +284,8 @@ instance (Functor f, Monad m) => Monad (Stream f m) where
276284instance (Functor f , Monad m ) => Applicative (Stream f m ) where
277285 pure = Return
278286 {-# INLINE pure #-}
279- streamf <*> streamx = do {f <- streamf; x <- streamx; return (f x)}
280- {-# INLINE (<*>) #-}
287+ streamf <*> streamx = do {f <- streamf; x <- streamx; return (f x)}
288+ {-# INLINE (<*>) #-}
281289 stream1 *> stream2 = loop stream1 where
282290 loop stream = case stream of
283291 Return _ -> stream2
@@ -326,7 +334,7 @@ instance Functor f => MFunctor (Stream f) where
326334 Return r -> Return r
327335 Effect m -> Effect (trans (fmap loop m))
328336 Step f -> Step (fmap loop f)
329- {-# INLINABLE hoist #-}
337+ {-# INLINABLE hoist #-}
330338
331339
332340instance Functor f => MMonad (Stream f ) where
@@ -346,7 +354,7 @@ instance (Functor f, MonadReader r m) => MonadReader r (Stream f m) where
346354 {-# INLINE ask #-}
347355 local f = hoist (local f)
348356 {-# INLINE local #-}
349-
357+
350358instance (Functor f , MonadState s m ) => MonadState s (Stream f m ) where
351359 get = lift get
352360 {-# INLINE get #-}
@@ -449,7 +457,7 @@ inspect = loop where
449457 Effect m -> m >>= loop
450458 Step fs -> return (Right fs)
451459{-# INLINABLE inspect #-}
452-
460+
453461{-| Build a @Stream@ by unfolding steps starting from a seed. See also
454462 the specialized 'Streaming.Prelude.unfoldr' in the prelude.
455463
717725-}
718726takes :: (Monad m , Functor f ) => Int -> Stream f m r -> Stream f m ()
719727takes n = void . splitsAt n
720- {-# INLINE takes #-}
728+ {-# INLINE takes #-}
721729
722730{-| Break a stream into substreams each with n functorial layers.
723731
@@ -732,7 +740,7 @@ chunksOf n0 = loop where
732740 Return r -> Return r
733741 Effect m -> Effect (fmap loop m)
734742 Step fs -> Step (Step (fmap (fmap loop . splitsAt (n0- 1 )) fs))
735- {-# INLINABLE chunksOf #-}
743+ {-# INLINABLE chunksOf #-}
736744
737745{- | Make it possible to \'run\' the underlying transformed monad.
738746-}
@@ -744,7 +752,7 @@ distribute = loop where
744752 Effect tmstr -> hoist lift tmstr >>= loop
745753 Step fstr -> join (lift (Step (fmap (Return . loop) fstr)))
746754{-# INLINABLE distribute #-}
747-
755+
748756-- | Repeat a functorial layer (a \"command\" or \"instruction\") forever.
749757repeats :: (Monad m , Functor f ) => f () -> Stream f m r
750758repeats f = loop where
@@ -861,7 +869,7 @@ unexposed = Effect . loop where
861869 Return r -> return (Return r)
862870 Effect m -> m >>= loop
863871 Step f -> return (Step (fmap (Effect . loop) f))
864- {-# INLINABLE unexposed #-}
872+ {-# INLINABLE unexposed #-}
865873
866874
867875{-| Wrap a new layer of a stream. So, e.g.
@@ -978,7 +986,7 @@ zips :: (Monad m, Functor f, Functor g)
978986 => Stream f m r -> Stream g m r -> Stream (Compose f g ) m r
979987zips = zipsWith' go where
980988 go p fx gy = Compose (fmap (\ x -> fmap (\ y -> p x y) gy) fx)
981- {-# INLINE zips #-}
989+ {-# INLINE zips #-}
982990
983991
984992
@@ -999,7 +1007,7 @@ interleaves
9991007 :: (Monad m , Applicative h ) =>
10001008 Stream h m r -> Stream h m r -> Stream h m r
10011009interleaves = zipsWith' liftA2
1002- {-# INLINE interleaves #-}
1010+ {-# INLINE interleaves #-}
10031011
10041012
10051013{-| Swap the order of functors in a sum of functors.
@@ -1158,7 +1166,7 @@ groups = loop
11581166 Right (InL fstr) -> return (wrap (InL fstr))
11591167 Right (InR gstr) -> wrap (fmap go gstr)
11601168{-# INLINABLE groups #-}
1161-
1169+
11621170-- groupInL :: (Monad m, Functor f, Functor g)
11631171-- => Stream (Sum f g) m r
11641172-- -> Stream (Sum (Stream f m) g) m r
@@ -1343,8 +1351,8 @@ untilJust act = loop where
13431351 case m of
13441352 Nothing -> return $ Step $ pure loop
13451353 Just a -> return $ Return a
1346-
1347-
1354+
1355+
13481356cutoff :: (Monad m , Functor f ) => Int -> Stream f m r -> Stream f m (Maybe r )
13491357cutoff = loop where
13501358 loop 0 _ = return Nothing
0 commit comments