Skip to content

Commit 05fc62a

Browse files
committed
Add defaultGshowsPrec using showsPrec
`GShow t` is isomorphic to `forall a. Show (t a)`, but we don't need the quantified constraint to write a function to be used to define the method. The more specific type should make a nicer error if one didn't derive the necessary polymorphic `Show` instance.
1 parent 6efbd3b commit 05fc62a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Data/GADT/Internal.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ type GShow :: (k -> Type) -> Constraint
5555
class GShow t where
5656
gshowsPrec :: Int -> t a -> ShowS
5757

58+
-- |If 'f' has a 'Show (f a)' instance, this function makes a suitable default
59+
-- implementation of 'gshowsPrec'.
60+
defaultGshowsPrec :: Show (t a) => Int -> t a -> ShowS
61+
defaultGshowsPrec = showsPrec
62+
5863
gshows :: GShow t => t a -> ShowS
5964
gshows = gshowsPrec (-1)
6065

src/Data/GADT/Show.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
module Data.GADT.Show (
88
-- * Showing
99
GShow (..),
10+
defaultGshowsPrec,
1011
gshows,
1112
gshow,
1213
-- * Reading

0 commit comments

Comments
 (0)