HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduletext-display-0.0.5.2Haskell2010

Data.Text.Display.Generic

Generic machinery for automatically deriving display instances for record types

  • 2 types
  • 2 classes
  • 1 value
classclass GDisplay1 (f :: Type -> Type) where
#

Generic typeclass machinery for inducting on the structure of the type, such that we can thread Display instances through the structure of the type. The primary use case is for implementing RecordInstance, which does this "threading" for record fields. This machinery does, crucially, depend on child types (i.e. the type of a record field) having a Display instance.

Methods

Instances8GDisplay1, …
newtypenewtype RecordInstance a
#

This wrapper allows you to create an Display instance for a record, so long as all the record fields have a Display instance as well.

Example
data Password = Password
 deriving Display
   via (OpaqueInstance "[REDACTED]" Password)
data MyRecord =
   MyRecord
     { fieldA :: String
     , fieldB :: Maybe String
     , fieldC :: Int
     , pword :: Password
     }
     deriving stock (Generic)
     deriving (Display) via (RecordInstance MyRecord)
putStrLn . Data.Text.unpack . display $ MyRecord "hello" (Just "world") 22 Password
MyRecord
  { fieldA = hello
  , fieldB = Just world
  , fieldC = 22
  , pword = [REDACTED]
  }
Instances3Generic, Display, Rep
typetype AssertNoSumRecordInstance (constraint :: Type -> Constraint) a = Assert (Not (HasSum (Rep a))) ((((('Text "\128683 Cannot derive " ':<>: 'ShowType constraint) ':<>: 'Text " instance for ") ':<>: 'ShowType a) ':<>: 'Text " via RecordInstance due to sum type") ':$$: 'Text "\128161 Sum types should use a manual instance or derive one via ShowInstance.")
#

Constraint to prevent misuse of RecordInstance deriving via mechanism.

Example
data MySum = A | B | C deriving stock (Generic) deriving (Display) via (RecordInstance MySum)
   • 🚫 Cannot derive Display instance for MySum via RecordInstance due to sum type
     💡 Sum types should use a manual instance or derive one via ShowInstance.
   • When deriving the instance for (Display MySum)