GaloisInc / GaloisInc/parameterized-utils

Discrepancies between derived Show instances and `structuralShowsPrec`

Open
#116 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Haskell
Stars
59
Forks
14
Avg merge
45m
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Haskell reproduction and inspect the implementation of structuralShowsPrec. Compare its output with derived Show for the record and infix constructors shown in the example. Done means both forms use the same formatting as deriving Show, with regression coverage for these cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.