Skip to content

Commit 3128445

Browse files
committed
split code into separate class/instances packages
1 parent e73e0f2 commit 3128445

File tree

32 files changed

+646
-38
lines changed

32 files changed

+646
-38
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
*.hi
22
*.o
33
dist/
4-
t/*.t
5-
/Setup
4+
*.t
5+
Setup
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{-
2+
3+
Copyright (c) 2013 Lukas Mai
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of the author nor the names of his contributors
16+
may be used to endorse or promote products derived from this software
17+
without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY LUKAS MAI AND CONTRIBUTORS "AS IS" AND ANY
20+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
23+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+
-}
31+
32+
module Data.Default.Class (
33+
-- | This module defines a class for types with a default value.
34+
Default(..)
35+
) where
36+
37+
-- | A class for types with a default value.
38+
class Default a where
39+
-- | The default value for this type.
40+
def :: a

LICENSE renamed to data-default-class/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010, 2012 Lukas Mai
1+
Copyright (c) 2013 Lukas Mai
22

33
All rights reserved.
44

File renamed without changes.
File renamed without changes.

data-default.cabal renamed to data-default-class/data-default-class.cabal

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Name: data-default
2-
Version: 0.5.1
1+
Name: data-default-class
2+
Version: 0.0.1
33
Cabal-Version: >= 1.6
44
Category: Data
55
Synopsis: A class for types with a default value
@@ -14,6 +14,5 @@ source-repository head
1414
location: https://github.com/mauke/data-default
1515

1616
Library
17-
Build-Depends: base >=2 && <5, containers, dlist, old-locale
18-
Exposed-Modules: Data.Default
19-
Ghc-Options: -Wall -O2
17+
Build-Depends: base >=2 && <5
18+
Exposed-Modules: Data.Default.Class

Data/Default.hs renamed to data-default-instances-base/Data/Default/Instances/Base.hs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-
22
3-
Copyright (c) 2010, 2012 Lukas Mai
3+
Copyright (c) 2013 Lukas Mai
44
55
All rights reserved.
66
@@ -29,38 +29,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
3030
-}
3131

32-
module Data.Default (
33-
-- | This module defines a class for types with a default value. Instances are
34-
-- provided for '()', 'S.Set', 'M.Map', 'Int', 'Integer', 'Float', 'Double',
35-
-- and many others (see below).
36-
Default(..)
32+
module Data.Default.Instances.Base (
33+
-- | This module defines 'Default' instances for the types 'Int', 'Int8',
34+
-- 'Int16', 'Int32', 'Int64', 'Word', 'Word8', 'Word16', 'Word32', 'Word64',
35+
-- 'Integer', 'Float', 'Double', 'Ratio', 'Complex', '(->)', 'IO', 'Maybe',
36+
-- '()', '[]', 'Ordering', 'Any', 'All', 'Last', 'First', 'Sum', 'Product',
37+
-- 'Endo', 'Dual', and tuples.
3738
) where
3839

40+
import Data.Default.Class
3941
import Data.Int
4042
import Data.Word
4143
import Data.Monoid
4244
import Data.Ratio
4345
import Data.Complex
44-
import qualified Data.Set as S
45-
import qualified Data.Map as M
46-
import Data.IntMap (IntMap)
47-
import Data.IntSet (IntSet)
48-
import Data.Sequence (Seq)
49-
import Data.Tree (Tree(..))
50-
import Data.DList (DList)
51-
import System.Locale
52-
53-
-- | A class for types with a default value.
54-
class Default a where
55-
-- | The default value for this type.
56-
def :: a
57-
58-
instance Default (S.Set v) where def = S.empty
59-
instance Default (M.Map k v) where def = M.empty
60-
instance Default (IntMap v) where def = mempty
61-
instance Default IntSet where def = mempty
62-
instance Default (Seq a) where def = mempty
63-
instance (Default a) => Default (Tree a) where def = Node def def
6446

6547
instance Default Int where def = 0
6648
instance Default Int8 where def = 0
@@ -94,14 +76,10 @@ instance (Num a) => Default (Sum a) where def = mempty
9476
instance (Num a) => Default (Product a) where def = mempty
9577
instance Default (Endo a) where def = mempty
9678

97-
instance Default (DList a) where def = mempty
98-
9979
instance (Default a) => Default (Dual a) where def = Dual def
10080
instance (Default a, Default b) => Default (a, b) where def = (def, def)
10181
instance (Default a, Default b, Default c) => Default (a, b, c) where def = (def, def, def)
10282
instance (Default a, Default b, Default c, Default d) => Default (a, b, c, d) where def = (def, def, def, def)
10383
instance (Default a, Default b, Default c, Default d, Default e) => Default (a, b, c, d, e) where def = (def, def, def, def, def)
10484
instance (Default a, Default b, Default c, Default d, Default e, Default f) => Default (a, b, c, d, e, f) where def = (def, def, def, def, def, def)
10585
instance (Default a, Default b, Default c, Default d, Default e, Default f, Default g) => Default (a, b, c, d, e, f, g) where def = (def, def, def, def, def, def, def)
106-
107-
instance Default TimeLocale where def = defaultTimeLocale
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2013 Lukas Mai
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification,
6+
are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
* Neither the name of the author nor the names of his contributors
14+
may be used to endorse or promote products derived from this software
15+
without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY LUKAS MAI AND CONTRIBUTORS "AS IS" AND ANY
18+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
TESTS = $(wildcard t/*.hs)
2+
3+
.PHONY: config build install docs dist test clean
4+
.PHONY: build-test clean-test
5+
6+
build: dist/setup-config
7+
cabal build
8+
9+
config: dist/setup-config
10+
11+
dist/setup-config: *.cabal
12+
cabal configure
13+
14+
install: build
15+
cabal install
16+
17+
docs: dist/setup-config
18+
cabal haddock
19+
20+
dist: build
21+
cabal sdist
22+
23+
clean: clean-test
24+
cabal clean
25+
26+
test: build-test
27+
prove
28+
29+
build-test: $(TESTS:.hs=.t)
30+
31+
clean-test:
32+
rm -f $(TESTS:.hs=.t) $(TESTS:.hs=.hi) $(TESTS:.hs=.o)
33+
34+
t/%.t: t/%.hs build
35+
ghc -idist/build -Wall -O --make $< -o $@
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env runhaskell
2+
> import Distribution.Simple
3+
> main :: IO ()
4+
> main = defaultMain

0 commit comments

Comments
 (0)