[Haskell-cafe] [ANN] text-display A typeclass for user-facing output

Hécate hecate at glitchbra.in
Tue Nov 2 20:06:22 UTC 2021

Hi everyone, I am proud to release the first version of text-display¹, a 
typeclass for user-facing output.

`Display` is a typeclass that doesn't abide by the rules of `Show` & 
`Read`, and brings with it a nice and ergonomic way to derive instances 
through `DerivingVia` when they already have a `Show` instance:

{-# LANGUAGE DerivingVia #-}
data AutomaticallyDerived = AD
   -- We derive 'Show'
   deriving Show
   -- We take advantage of the 'Show' instance to derive 'Display' from it
   deriving Display
     via (ShowInstance AutomaticallyDerived)

But let's say you want to redact an instance of `Display`? You can do it 
locally, through
the `OpaqueInstance` helper. It is most useful to hide tokens or passwords:

data UserToken = UserToken UUID
  deriving Display
    via (OpaqueInstance "[REDACTED]" UserToken)

display $ UserToken "7a01d2ce-31ff-11ec-8c10-5405db82c3cd"
-- => "[REDACTED]"

I hope you will have fun with this library!


¹ https://hackage.haskell.org/package/text-display-

Hécate ✨
🐦: @TechnoEmpress
IRC: Hecate
WWW: https://glitchbra.in

More information about the Haskell-Cafe mailing list