@@ -1,5 +1,7 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE DeriveDataTypeable #-}
3+{-# LANGUAGE DeriveGeneric #-}
4+{-# LANGUAGE DeriveTraversable #-}
35{-# LANGUAGE FlexibleContexts #-}
46{-# LANGUAGE MultiParamTypeClasses #-}
57{-# LANGUAGE RecursiveDo #-}
@@ -24,12 +26,14 @@ import Control.Monad
2426import Control.Monad.Fix
2527import Control.Monad.IO.Class
2628import Data.Align
29+import Data.Data (Data)
2730import Data.Fixed
2831import Data.Sequence (Seq, (|>))
2932import qualified Data.Sequence as Seq
3033import Data.These
3134import Data.Time.Clock
3235import Data.Typeable
36+import GHC.Generics (Generic)
3337import System.Random
3438
3539data TickInfo
@@ -269,16 +273,20 @@ throttle t e = do
269273data ThrottleState b
270274 = Immediate
271275 | Buffered (ThrottleBuffer b)
276+ deriving (Eq, Ord, Show, Functor, Foldable, Traversable, Generic, Data, Typeable)
272277
273278data ThrottleBuffer b
274279 = BEmpty -- Empty conflicts with lens, and hiding it would require turning
275280 -- on PatternSynonyms
276281 | Full b
282+ deriving (Eq, Ord, Show, Functor, Foldable, Traversable, Generic, Data, Typeable)
277283
278284instance Semigroup b => Semigroup (ThrottleBuffer b) where
279− BEmpty <> x = x
280− x@(Full _) <> BEmpty = x
281− Full b1 <> Full b2 = Full $ b1 <> b2
285+ x <> y = case x of
286+ BEmpty -> y
287+ Full b1 -> case y of
288+ BEmpty -> x
289+ Full b2 -> Full $ b1 <> b2
282290 {-# INLINE (<>) #-}
283291
284292instance Semigroup b => Monoid (ThrottleBuffer b) where