Skip to content

Commit 66046a3

Browse files
committed
move base instances into data-default-class (#7)
1 parent 3e060c2 commit 66046a3

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

data-default-class/Data/Default/Class.hs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3939

4040
module Data.Default.Class (
4141
-- | This module defines a class for types with a default value.
42+
-- It also defines 'Default' instances for the types 'Int', 'Int8',
43+
-- 'Int16', 'Int32', 'Int64', 'Word', 'Word8', 'Word16', 'Word32', 'Word64',
44+
-- 'Integer', 'Float', 'Double', 'Ratio', 'Complex', 'CShort', 'CUShort',
45+
-- 'CInt', 'CUInt', 'CLong', 'CULong', 'CLLong', 'CULLong', 'CPtrdiff',
46+
-- 'CSize', 'CSigAtomic', 'CIntPtr', 'CUIntPtr', 'CIntMax', 'CUIntMax',
47+
-- 'CClock', 'CTime', 'CUSeconds', 'CSUSeconds', 'CFloat', 'CDouble', '(->)',
48+
-- 'IO', 'Maybe', '()', '[]', 'Ordering', 'Any', 'All', 'Last', 'First', 'Sum',
49+
-- 'Product', 'Endo', 'Dual', and tuples.
4250
Default(..)
4351
) where
4452

53+
import Data.Int
54+
import Data.Word
55+
import Data.Monoid
56+
import Data.Ratio
57+
import Data.Complex
58+
import Foreign.C.Types
59+
4560
#if HAVE_GHC_GENERICS
4661
import GHC.Generics
4762

@@ -70,3 +85,67 @@ class Default a where
7085
default def :: (Generic a, GDefault (Rep a)) => a
7186
def = to gdef
7287
#endif
88+
89+
instance Default Int where def = 0
90+
instance Default Int8 where def = 0
91+
instance Default Int16 where def = 0
92+
instance Default Int32 where def = 0
93+
instance Default Int64 where def = 0
94+
instance Default Word where def = 0
95+
instance Default Word8 where def = 0
96+
instance Default Word16 where def = 0
97+
instance Default Word32 where def = 0
98+
instance Default Word64 where def = 0
99+
instance Default Integer where def = 0
100+
instance Default Float where def = 0
101+
instance Default Double where def = 0
102+
instance (Integral a) => Default (Ratio a) where def = 0
103+
instance (Default a, RealFloat a) => Default (Complex a) where def = def :+ def
104+
105+
instance Default CShort where def = 0
106+
instance Default CUShort where def = 0
107+
instance Default CInt where def = 0
108+
instance Default CUInt where def = 0
109+
instance Default CLong where def = 0
110+
instance Default CULong where def = 0
111+
instance Default CLLong where def = 0
112+
instance Default CULLong where def = 0
113+
instance Default CPtrdiff where def = 0
114+
instance Default CSize where def = 0
115+
instance Default CSigAtomic where def = 0
116+
instance Default CIntPtr where def = 0
117+
instance Default CUIntPtr where def = 0
118+
instance Default CIntMax where def = 0
119+
instance Default CUIntMax where def = 0
120+
instance Default CClock where def = 0
121+
instance Default CTime where def = 0
122+
#if MIN_VERSION_base(4, 4, 0)
123+
instance Default CUSeconds where def = 0
124+
instance Default CSUSeconds where def = 0
125+
#endif
126+
instance Default CFloat where def = 0
127+
instance Default CDouble where def = 0
128+
129+
instance (Default r) => Default (e -> r) where def = const def
130+
instance (Default a) => Default (IO a) where def = return def
131+
132+
instance Default (Maybe a) where def = Nothing
133+
134+
instance Default () where def = mempty
135+
instance Default [a] where def = mempty
136+
instance Default Ordering where def = mempty
137+
instance Default Any where def = mempty
138+
instance Default All where def = mempty
139+
instance Default (Last a) where def = mempty
140+
instance Default (First a) where def = mempty
141+
instance (Num a) => Default (Sum a) where def = mempty
142+
instance (Num a) => Default (Product a) where def = mempty
143+
instance Default (Endo a) where def = mempty
144+
145+
instance (Default a) => Default (Dual a) where def = Dual def
146+
instance (Default a, Default b) => Default (a, b) where def = (def, def)
147+
instance (Default a, Default b, Default c) => Default (a, b, c) where def = (def, def, def)
148+
instance (Default a, Default b, Default c, Default d) => Default (a, b, c, d) where def = (def, def, def, def)
149+
instance (Default a, Default b, Default c, Default d, Default e) => Default (a, b, c, d, e) where def = (def, def, def, def, def)
150+
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)
151+
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)

data-default-class/data-default-class.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: data-default-class
2-
Version: 0.1.1
2+
Version: 0.1.2.0
33
Cabal-Version: >= 1.6
44
Category: Data
55
Synopsis: A class for types with a default value

0 commit comments

Comments
 (0)