shithub: MicroHs

ref: a4229eb282ca32bc14103a33092e94382c3c7ca0
dir: /lib/Data/Monoid.hs/

View raw version
module Data.Monoid(
  Monoid(..),
  Endo(..),
  Dual(..),
  Sum(..),
  Product(..),
  All(..),
  Any(..),
  Arg(..),
  Alt(..),
  First(..),
  Last(..),
  ) where
import Prelude()
import Data.Maybe_Type
import Data.Monoid.Internal
import Data.Records

-- First and Last are different in Monoid and Semigroup,
-- so put them here.

newtype First a = First { getFirst :: Maybe a }

instance forall a . Semigroup (First a) where
  a@(First (Just _)) <> _ = a
  First Nothing      <> a = a

instance forall a . Monoid (First a) where
  mempty = First Nothing


newtype Last a = Last { getLast :: Maybe a }

instance forall a . Semigroup (Last a) where
  _ <> a@(Last (Just _)) = a
  a <>    Last Nothing   = a

instance forall a . Monoid (Last a) where
  mempty = Last Nothing