Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancies between derived Show instances and structuralShowsPrec #116

Open
RyanGlScott opened this issue Jun 29, 2021 · 0 comments
Open
Labels

Comments

@RyanGlScott
Copy link
Contributor

In certain cases, the output of structuralShowsPrec will differ from what deriving Show produces. Here is a test case which illustrates this:

{-# LANGUAGE TemplateHaskell #-}
module Bug where

import Data.Parameterized.TH.GADT

data T
  = MkRec { unRec :: Int }
  | Int :@@: Int
  deriving Show

$(return [])

puShowT :: T -> String
puShowT t = $(structuralShowsPrec [t| T |]) 0 t ""

main :: IO ()
main = do
  let r   = MkRec 42
      inf = 42 :@@: 42
  putStrLn $ "MkRec (derived):\t\t" ++ show r
  putStrLn $ "MkRec (parameterized-utils):\t" ++ puShowT r
  putStrLn $ "(:@@:) (derived):\t\t" ++ show inf
  putStrLn $ "(:@@:) (parameterized-utils):\t" ++ puShowT inf

This will output:

MkRec (derived):                MkRec {unRec = 42}
MkRec (parameterized-utils):    MkRec 42
(:@@:) (derived):               42 :@@: 42
(:@@:) (parameterized-utils):   :@@: 42 42

This shows that structuralShowsPrec ignores record and infix data constructors, which deriving Show is aware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant