#if __GLASGOW_HASKELL__ >= 702
#endif
module Data.Semigroup.Alt
( Alter(..)
) where
import Data.Functor.Plus
#if __GLASGOW_HASKELL__ < 710
import Data.Monoid (Monoid(..))
#endif
import Data.Semigroup (Semigroup(..))
import Data.Semigroup.Reducer (Reducer(..))
newtype Alter f a = Alter { getAlter :: f a }
deriving (Functor,Plus)
instance Alt f => Alt (Alter f) where
Alter a <!> Alter b = Alter (a <!> b)
instance Alt f => Semigroup (Alter f a) where
Alter a <> Alter b = Alter (a <!> b)
instance Plus f => Monoid (Alter f a) where
mempty = zero
Alter a `mappend` Alter b = Alter (a <!> b)
instance Alt f => Reducer (f a) (Alter f a) where
unit = Alter