on master help sign in
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.

commit36c1dcc451b3b206b4b06376768e2fa82387a599 authorEric Mertens <emertens@galois.com> dateMon 16 Nov 2020, 09:56 (6 years ago) parentd470f5f
1 file changed+2−11
src/Graphics/Vty/Attributes.hs+2−11
src/Graphics/Vty/Attributes.hs+2−11
@@ -1,7 +1,4 @@
11{-# LANGUAGE CPP #-}
2−{-# LANGUAGE StandaloneDeriving #-}
3−{-# LANGUAGE GADTs #-}
4−{-# LANGUAGE RankNTypes #-}
52{-# LANGUAGE DeriveGeneric #-}
63{-# LANGUAGE DeriveAnyClass #-}
74
@@ -146,20 +143,14 @@ data FixedAttr = FixedAttr
146143-- | The style and color attributes can either be the terminal defaults.
147144-- Or be equivalent to the previously applied style. Or be a specific
148145-- value.
149−data MaybeDefault v where
150− Default :: MaybeDefault v
151− KeepCurrent :: MaybeDefault v
152− SetTo :: forall v . ( Eq v, Show v, Read v ) => !v -> MaybeDefault v
146+data MaybeDefault v = Default | KeepCurrent | SetTo !v
147+ deriving (Eq, Read, Show)
153148
154149instance (NFData v) => NFData (MaybeDefault v) where
155150 rnf Default = ()
156151 rnf KeepCurrent = ()
157152 rnf (SetTo v) = rnf v
158153
159−deriving instance Eq v => Eq (MaybeDefault v)
160−deriving instance Eq v => Show (MaybeDefault v)
161−deriving instance (Eq v, Show v, Read v) => Read (MaybeDefault v)
162−
163154instance Eq v => Semigroup (MaybeDefault v) where
164155 Default <> Default = Default
165156 Default <> KeepCurrent = Default