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!