{-# LANGUAGE UndecidableInstances, FlexibleContexts, MultiParamTypeClasses, FlexibleInstances #-}
{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 710
{-# LANGUAGE Trustworthy #-}
#endif
module Data.Semigroup.Reducer.With
( WithReducer(..)
) where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
import Data.FingerTree
#if __GLASGOW_HASKELL__ < 710
import Data.Foldable
import Data.Traversable
#endif
import Data.Hashable
#if __GLASGOW_HASKELL__ < 710
import Data.Monoid
#endif
import Data.Semigroup.Reducer
import Data.Semigroup.Foldable
import Data.Semigroup.Traversable
import Data.Semigroup.Instances ()
newtype WithReducer m c = WithReducer { withoutReducer :: c }
deriving (Eq, Ord, Show, Read)
instance Hashable c => Hashable (WithReducer m c) where
hashWithSalt n = hashWithSalt n . withoutReducer
instance Functor (WithReducer m) where
fmap f = WithReducer . f . withoutReducer
instance Foldable (WithReducer m) where
foldMap f = f . withoutReducer
instance Traversable (WithReducer m) where
traverse f (WithReducer a) = WithReducer <$> f a
instance Foldable1 (WithReducer m) where
foldMap1 f = f . withoutReducer
instance Traversable1 (WithReducer m) where
traverse1 f (WithReducer a) = WithReducer <$> f a
instance Reducer c m => Reducer (WithReducer m c) m where
unit = unit . withoutReducer
instance (Monoid m, Reducer c m) => Measured m (WithReducer m c) where
measure = unit . withoutReducer