Skip to content

Commit 0802ed8

Browse files
authored
Share code between Show (Stream f m r) and Show1 (Stream f m) (#113)
1 parent 0721e4b commit 0802ed8

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

src/Streaming/Internal.hs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,26 @@ instance (Monad m, Functor f, Ord1 m, Ord1 f) => Ord1 (Stream f m) where
194194
-- like producing @m String@, except that a @ShowSWrapper@ can be
195195
-- shown at any precedence. So the 'Show' instance for @m@ can show
196196
-- the contents at the correct precedence.
197-
instance (Monad m, Show r, Show (m ShowSWrapper), Show (f (Stream f m r)))
197+
instance (Monad m, Functor f, Show (m ShowSWrapper), Show (f ShowSWrapper), Show r)
198198
=> Show (Stream f m r) where
199-
showsPrec p xs = showParen (p > 10) $
200-
showString "Effect " . (showsPrec 11 $
201-
flip fmap (inspect xs) $ \front ->
202-
SS $ \d -> showParen (d > 10) $
203-
case front of
204-
Left r -> showString "Return " . showsPrec 11 r
205-
Right f -> showString "Step " . showsPrec 11 f)
199+
showsPrec = liftShowsPrec' showsPrec showList
206200

207201
#if MIN_VERSION_base(4,9,0)
208202

209203
instance (Monad m, Functor f, Show (m ShowSWrapper), Show (f ShowSWrapper))
210204
=> Show1 (Stream f m) where
211-
liftShowsPrec sp sl p xs = showParen (p > 10) $
205+
liftShowsPrec = liftShowsPrec'
206+
207+
#endif
208+
209+
liftShowsPrec'
210+
:: (Monad m, Functor f, Show (m ShowSWrapper), Show (f ShowSWrapper))
211+
=> (Int -> a -> ShowS)
212+
-> ([a] -> ShowS)
213+
-> Int
214+
-> Stream f m a
215+
-> ShowS
216+
liftShowsPrec' sp sl p xs = showParen (p > 10) $
212217
showString "Effect " . (showsPrec 11 $
213218
flip fmap (inspect xs) $ \front ->
214219
SS $ \d -> showParen (d > 10) $
@@ -217,8 +222,6 @@ instance (Monad m, Functor f, Show (m ShowSWrapper), Show (f ShowSWrapper))
217222
Right f -> showString "Step " .
218223
showsPrec 11 (fmap (SS . (\str i -> liftShowsPrec sp sl i str)) f))
219224

220-
#endif
221-
222225
newtype ShowSWrapper = SS (Int -> ShowS)
223226
instance Show ShowSWrapper where
224227
showsPrec p (SS s) = s p

0 commit comments

Comments
 (0)