From 36c1dcc451b3b206b4b06376768e2fa82387a599 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Mon, 16 Nov 2020 09:56:30 -0800 Subject: [PATCH] Simplify definition of MaybeDefault The previous version of MaybeDefault stores pointers to the Eq, Show, and Read instances of the defaulted value. MaybeDefault is used with Style, Color, and Text. All of these types already have all of the necessary instances, and we never work with MaybeDefault generically. Defering the Show, Eq, and Read instances down to the SetTo case isn't helping us to work with types that don't have these instances. --- src/Graphics/Vty/Attributes.hs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Graphics/Vty/Attributes.hs b/src/Graphics/Vty/Attributes.hs index c818ad2..929f8aa 100644 --- a/src/Graphics/Vty/Attributes.hs +++ b/src/Graphics/Vty/Attributes.hs @@ -1,7 +1,4 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE RankNTypes #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} @@ -146,20 +143,14 @@ data FixedAttr = FixedAttr -- | The style and color attributes can either be the terminal defaults. -- Or be equivalent to the previously applied style. Or be a specific -- value. -data MaybeDefault v where - Default :: MaybeDefault v - KeepCurrent :: MaybeDefault v - SetTo :: forall v . ( Eq v, Show v, Read v ) => !v -> MaybeDefault v +data MaybeDefault v = Default | KeepCurrent | SetTo !v + deriving (Eq, Read, Show) instance (NFData v) => NFData (MaybeDefault v) where rnf Default = () rnf KeepCurrent = () rnf (SetTo v) = rnf v -deriving instance Eq v => Eq (MaybeDefault v) -deriving instance Eq v => Show (MaybeDefault v) -deriving instance (Eq v, Show v, Read v) => Read (MaybeDefault v) - instance Eq v => Semigroup (MaybeDefault v) where Default <> Default = Default Default <> KeepCurrent = Default