Skip to content

Commit 4ff6a67

Browse files
committed
Make package buildable with ghc 7.10.3
1 parent 60a31f3 commit 4ff6a67

3 files changed

Lines changed: 50 additions & 36 deletions

File tree

src/Data/Functor/Of.hs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{-# LANGUAGE CPP, DeriveDataTypeable, DeriveTraversable, DeriveFoldable,
22
DeriveGeneric #-}
3-
module Data.Functor.Of where
3+
module Data.Functor.Of (Of(..)) where
44
import Data.Monoid (Monoid (..))
55
import Data.Semigroup (Semigroup (..))
66
import Control.Applicative
77
import Data.Traversable (Traversable)
88
import Data.Foldable (Foldable)
99
import Data.Bifunctor
1010
import Data.Data
11-
import Data.Typeable
12-
import GHC.Generics (Generic, Generic1)
11+
#if MIN_VERSION_base(4,9,0)
1312
import Data.Functor.Classes
13+
import Data.Foldable (Foldable)
14+
import Data.Traversable (Traversable)
15+
#endif
16+
import GHC.Generics (Generic, Generic1)
1417

1518
-- | A left-strict pair; the base functor for streams of individual elements.
1619
data Of a b = !a :> b
@@ -64,25 +67,28 @@ instance Monoid a => Monad (Of a) where
6467
m :> x >>= f = let m' :> y = f x in mappend m m' :> y
6568
{-#INLINE (>>=) #-}
6669

70+
#if MIN_VERSION_base(4,9,0)
6771
instance Show a => Show1 (Of a) where
6872
liftShowsPrec = liftShowsPrec2 showsPrec showList
6973

74+
instance Eq a => Eq1 (Of a) where
75+
liftEq = liftEq2 (==)
76+
77+
instance Ord a => Ord1 (Of a) where
78+
liftCompare = liftCompare2 compare
79+
7080
instance Show2 Of where
7181
liftShowsPrec2 spa _sla spb _slb p (a :> b) =
7282
showParen (p > 5) $
7383
spa 6 a .
7484
showString " :> " .
7585
spb 6 b
7686

77-
instance Eq a => Eq1 (Of a) where
78-
liftEq = liftEq2 (==)
79-
80-
instance Ord a => Ord1 (Of a) where
81-
liftCompare = liftCompare2 compare
82-
8387
instance Eq2 Of where
84-
liftEq2 eq1 eq2 (x :> y) (z :> w) = eq1 x z && eq2 y w
88+
liftEq2 f g (x :> y) (z :> w) = f x z && g y w
8589

8690
instance Ord2 Of where
8791
liftCompare2 comp1 comp2 (x :> y) (z :> w) =
8892
comp1 x z `mappend` comp2 y w
93+
#endif
94+

src/Streaming/Internal.hs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

8989
import 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+
203209
instance (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+
214222
newtype ShowSWrapper = SS (Int -> ShowS)
215223
instance 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

232240
instance (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
276284
instance (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

332340
instance 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+
350358
instance (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
@@ -717,7 +725,7 @@ c
717725
-}
718726
takes :: (Monad m, Functor f) => Int -> Stream f m r -> Stream f m ()
719727
takes 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.
749757
repeats :: (Monad m, Functor f) => f () -> Stream f m r
750758
repeats 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
979987
zips = 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
10011009
interleaves = 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+
13481356
cutoff :: (Monad m, Functor f) => Int -> Stream f m r -> Stream f m (Maybe r)
13491357
cutoff = loop where
13501358
loop 0 _ = return Nothing

streaming.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ library
218218
, mtl >=2.1 && <2.3
219219
, mmorph >=1.0 && <1.2
220220
, semigroups >= 0.18 && <0.19
221-
, transformers >=0.5 && <0.6
221+
, transformers >=0.4 && <0.6
222222
, transformers-base < 0.5
223223
, ghc-prim
224224
, containers

0 commit comments

Comments
 (0)