Skip to content

Commit

Permalink
Add defaultGshowsPrec using showsPrec
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
Ericson2314 committed Apr 8, 2022
1 parent 6efbd3b commit 05fc62a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Data/GADT/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ type GShow :: (k -> Type) -> Constraint
class GShow t where
gshowsPrec :: Int -> t a -> ShowS

-- |If 'f' has a 'Show (f a)' instance, this function makes a suitable default
-- implementation of 'gshowsPrec'.
defaultGshowsPrec :: Show (t a) => Int -> t a -> ShowS
defaultGshowsPrec = showsPrec

gshows :: GShow t => t a -> ShowS
gshows = gshowsPrec (-1)

Expand Down
1 change: 1 addition & 0 deletions src/Data/GADT/Show.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
module Data.GADT.Show (
-- * Showing
GShow (..),
defaultGshowsPrec,
gshows,
gshow,
-- * Reading
Expand Down

0 comments on commit 05fc62a

Please sign in to comment.