X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FMonoid.hs;h=aaefd42169c7bdc85ba028ddd1d1df4aeda4089b;hb=HEAD;hp=d7bb20da32e679352406ce18b23e69d359c1ea52;hpb=fd73317876a8b474b8ffa75443efda76cf1a1636;p=ghc-base.git diff --git a/Data/Monoid.hs b/Data/Monoid.hs index d7bb20d..aaefd42 100644 --- a/Data/Monoid.hs +++ b/Data/Monoid.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP, NoImplicitPrelude #-} + ----------------------------------------------------------------------------- -- | -- Module : Data.Monoid @@ -9,13 +11,8 @@ -- Stability : experimental -- Portability : portable -- --- The Monoid class with various general-purpose instances. --- --- Inspired by the paper --- /Functional Programming with Overloading and --- Higher-Order Polymorphism/, --- Mark P Jones () --- Advanced School of Functional Programming, 1995. +-- A class for monoids (types with an associative binary operation that +-- has an identity) with various general-purpose instances. ----------------------------------------------------------------------------- module Data.Monoid ( @@ -35,7 +32,17 @@ module Data.Monoid ( Last(..) ) where +-- Push down the module in the dependency hierarchy. +#if defined(__GLASGOW_HASKELL__) +import GHC.Base hiding (Any) +import GHC.Enum +import GHC.Num +import GHC.Read +import GHC.Show +import Data.Maybe +#else import Prelude +#endif {- -- just for testing @@ -44,9 +51,26 @@ import Test.QuickCheck -- -} -- --------------------------------------------------------------------------- --- | The monoid class. --- A minimal complete definition must supply 'mempty' and 'mappend', --- and these should satisfy the monoid laws. +-- | The class of monoids (types with an associative binary operation that +-- has an identity). Instances should satisfy the following laws: +-- +-- * @mappend mempty x = x@ +-- +-- * @mappend x mempty = x@ +-- +-- * @mappend x (mappend y z) = mappend (mappend x y) z@ +-- +-- * @mconcat = 'foldr' mappend mempty@ +-- +-- The method names refer to the monoid of lists under concatenation, +-- but there are many other instances. +-- +-- Minimal complete definition: 'mempty' and 'mappend'. +-- +-- Some types can be viewed as a monoid in more than one way, +-- e.g. both addition and multiplication on numbers. +-- In such cases we often define @newtype@s and make those instances +-- of 'Monoid', e.g. 'Sum' and 'Product'. class Monoid a where mempty :: a