~ubuntu-branches/ubuntu/wily/agda/wily-proposed

« back to all changes in this revision

Viewing changes to src/compat/Data/Monoid/New.hs

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-08-05 06:38:12 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140805063812-io8e77niomivhd49
Tags: 2.4.0.2-1
* [6e140ac] Imported Upstream version 2.4.0.2
* [2049fc8] Update Build-Depends to match control
* [93dc4d4] Install the new primitives
* [e48f40f] Fix typo dev→doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
module Data.Monoid.New
3
 
    ( module Data.Monoid
4
 
    , Dual(..)
5
 
    , Endo(..)
6
 
    , All(..)
7
 
    , Any(..)
8
 
    , Sum(..)
9
 
    , Product(..)
10
 
    ) where
11
 
 
12
 
import Data.Monoid
13
 
 
14
 
newtype Dual a = Dual { getDual :: a }
15
 
 
16
 
instance Monoid a => Monoid (Dual a) where
17
 
        mempty = Dual mempty
18
 
        Dual x `mappend` Dual y = Dual (y `mappend` x)
19
 
 
20
 
newtype Endo a = Endo { appEndo :: a -> a }
21
 
 
22
 
instance Monoid (Endo a) where
23
 
        mempty = Endo id
24
 
        Endo f `mappend` Endo g = Endo (f . g)
25
 
 
26
 
newtype All = All { getAll :: Bool }
27
 
        deriving (Eq, Ord, Read, Show, Bounded)
28
 
 
29
 
instance Monoid All where
30
 
        mempty = All True
31
 
        All x `mappend` All y = All (x && y)
32
 
 
33
 
newtype Any = Any { getAny :: Bool }
34
 
        deriving (Eq, Ord, Read, Show, Bounded)
35
 
 
36
 
instance Monoid Any where
37
 
        mempty = Any False
38
 
        Any x `mappend` Any y = Any (x || y)
39
 
 
40
 
newtype Sum a = Sum { getSum :: a }
41
 
        deriving (Eq, Ord, Read, Show, Bounded)
42
 
 
43
 
instance Num a => Monoid (Sum a) where
44
 
        mempty = Sum 0
45
 
        Sum x `mappend` Sum y = Sum (x + y)
46
 
 
47
 
newtype Product a = Product { getProduct :: a }
48
 
        deriving (Eq, Ord, Read, Show, Bounded)
49
 
 
50
 
instance Num a => Monoid (Product a) where
51
 
        mempty = Product 1
52
 
        Product x `mappend` Product y = Product (x * y)