diff options
Diffstat (limited to 'users/Profpatsch/my-prelude/Label.hs')
-rw-r--r-- | users/Profpatsch/my-prelude/Label.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/users/Profpatsch/my-prelude/Label.hs b/users/Profpatsch/my-prelude/Label.hs index f869343a1e7a..0e339758ddbd 100644 --- a/users/Profpatsch/my-prelude/Label.hs +++ b/users/Profpatsch/my-prelude/Label.hs @@ -20,16 +20,24 @@ import Data.Data (Proxy (..)) import Data.Function ((&)) import Data.Typeable (Typeable) import GHC.Records (HasField (..)) -import GHC.TypeLits (Symbol) +import GHC.TypeLits (KnownSymbol, Symbol, symbolVal) -- | A labelled value. -- -- Use 'label'/'label'' to construct, -- then use dot-syntax to get the inner value. newtype Label (label :: Symbol) value = Label value - deriving stock (Show, Eq, Ord) + deriving stock (Eq, Ord) deriving newtype (Typeable) +instance (KnownSymbol label, Show value) => Show (Label label value) where + showsPrec d (Label val) = + showParen (d > 10) $ + showString "Label @" + . showsPrec 11 (symbolVal (Proxy @label)) + . showString " " + . showsPrec 11 val + -- | Attach a label to a value; should be used with a type application to name the label. -- -- @@ |