Skip to content
This repository
Browse code

Add Data and Typeable instances for many types exported by Cabal.

Note: this adds an orphan Data instance for Data.Version. A fix has been
proposed upstream.
  • Loading branch information...
commit 84ed9f27f1cdba33ba9d0c9c0dc46ca64c83531f 1 parent 7597a17
David Lazar authored
5  Cabal/Distribution/Compiler.hs
... ...
@@ -1,3 +1,4 @@
  1
+{-# LANGUAGE DeriveDataTypeable #-}
1 2
 -----------------------------------------------------------------------------
2 3
 -- |
3 4
 -- Module      :  Distribution.Compiler
@@ -63,6 +64,8 @@ module Distribution.Compiler (
63 64
   CompilerId(..),
64 65
   ) where
65 66
 
  67
+import Data.Data (Data)
  68
+import Data.Typeable (Typeable)
66 69
 import Data.Maybe (fromMaybe)
67 70
 import Distribution.Version (Version(..))
68 71
 
@@ -77,7 +80,7 @@ import Control.Monad (when)
77 80
 
78 81
 data CompilerFlavor = GHC | NHC | YHC | Hugs | HBC | Helium | JHC | LHC | UHC
79 82
                     | OtherCompiler String
80  
-  deriving (Show, Read, Eq, Ord)
  83
+  deriving (Show, Read, Eq, Ord, Typeable, Data)
81 84
 
82 85
 knownCompilerFlavors :: [CompilerFlavor]
83 86
 knownCompilerFlavors = [GHC, NHC, YHC, Hugs, HBC, Helium, JHC, LHC, UHC]
5  Cabal/Distribution/License.hs
... ...
@@ -1,3 +1,4 @@
  1
+{-# LANGUAGE DeriveDataTypeable #-}
1 2
 -----------------------------------------------------------------------------
2 3
 -- |
3 4
 -- Module      :  Distribution.License
@@ -59,6 +60,8 @@ import qualified Distribution.Compat.ReadP as Parse
59 60
 import qualified Text.PrettyPrint as Disp
60 61
 import Text.PrettyPrint ((<>))
61 62
 import qualified Data.Char as Char (isAlphaNum)
  63
+import Data.Data (Data)
  64
+import Data.Typeable (Typeable)
62 65
 
63 66
 -- |This datatype indicates the license under which your package is
64 67
 -- released.  It is also wise to add your license to each source file
@@ -106,7 +109,7 @@ data License =
106 109
     -- | Not a recognised license.
107 110
     -- Allows us to deal with future extensions more gracefully.
108 111
   | UnknownLicense String
109  
-  deriving (Read, Show, Eq)
  112
+  deriving (Read, Show, Eq, Typeable, Data)
110 113
 
111 114
 knownLicenses :: [License]
112 115
 knownLicenses = [ GPL  unversioned, GPL  (version [2]),   GPL  (version [3])
5  Cabal/Distribution/ModuleName.hs
... ...
@@ -1,3 +1,4 @@
  1
+{-# LANGUAGE DeriveDataTypeable #-}
1 2
 -----------------------------------------------------------------------------
2 3
 -- |
3 4
 -- Module      :  Distribution.ModuleName
@@ -50,6 +51,8 @@ module Distribution.ModuleName (
50 51
 import Distribution.Text
51 52
          ( Text(..) )
52 53
 
  54
+import Data.Data (Data)
  55
+import Data.Typeable (Typeable)
53 56
 import qualified Distribution.Compat.ReadP as Parse
54 57
 import qualified Text.PrettyPrint as Disp
55 58
 import qualified Data.Char as Char
@@ -62,7 +65,7 @@ import Data.List
62 65
 -- | A valid Haskell module name.
63 66
 --
64 67
 newtype ModuleName = ModuleName [String]
65  
-  deriving (Eq, Ord, Read, Show)
  68
+  deriving (Eq, Ord, Read, Show, Typeable, Data)
66 69
 
67 70
 instance Text ModuleName where
68 71
   disp (ModuleName ms) =
9  Cabal/Distribution/Package.hs
@@ -74,10 +74,11 @@ import Text.PrettyPrint ((<>), (<+>), text)
74 74
 import Control.DeepSeq (NFData(..))
75 75
 import qualified Data.Char as Char ( isDigit, isAlphaNum )
76 76
 import Data.List ( intercalate )
  77
+import Data.Data ( Data )
77 78
 import Data.Typeable ( Typeable )
78 79
 
79 80
 newtype PackageName = PackageName String
80  
-    deriving (Read, Show, Eq, Ord, Typeable)
  81
+    deriving (Read, Show, Eq, Ord, Typeable, Data)
81 82
 
82 83
 instance Text PackageName where
83 84
   disp (PackageName n) = Disp.text n
@@ -103,7 +104,7 @@ data PackageIdentifier
103 104
         pkgName    :: PackageName, -- ^The name of this package, eg. foo
104 105
         pkgVersion :: Version -- ^the version of this package, eg 1.2
105 106
      }
106  
-     deriving (Read, Show, Eq, Ord, Typeable)
  107
+     deriving (Read, Show, Eq, Ord, Typeable, Data)
107 108
 
108 109
 instance Text PackageIdentifier where
109 110
   disp (PackageIdentifier n v) = case v of
@@ -127,7 +128,7 @@ instance NFData PackageIdentifier where
127 128
 -- in a package database, or overlay of databases.
128 129
 --
129 130
 newtype InstalledPackageId = InstalledPackageId String
130  
- deriving (Read,Show,Eq,Ord)
  131
+ deriving (Read,Show,Eq,Ord,Typeable,Data)
131 132
 
132 133
 instance Text InstalledPackageId where
133 134
   disp (InstalledPackageId str) = text str
@@ -142,7 +143,7 @@ instance Text InstalledPackageId where
142 143
 -- | Describes a dependency on a source package (API)
143 144
 --
144 145
 data Dependency = Dependency PackageName VersionRange
145  
-                  deriving (Read, Show, Eq)
  146
+                  deriving (Read, Show, Eq, Typeable, Data)
146 147
 
147 148
 instance Text Dependency where
148 149
   disp (Dependency name ver) =
41  Cabal/Distribution/PackageDescription.hs
@@ -124,6 +124,7 @@ module Distribution.PackageDescription (
124 124
         knownRepoTypes,
125 125
   ) where
126 126
 
  127
+import Data.Data   (Data)
127 128
 import Data.List   (nub, intercalate)
128 129
 import Data.Maybe  (fromMaybe, maybeToList)
129 130
 import Data.Monoid (Monoid(mempty, mappend))
@@ -196,7 +197,7 @@ data PackageDescription
196 197
         extraTmpFiles  :: [FilePath],
197 198
         extraHtmlFiles :: [FilePath]
198 199
     }
199  
-    deriving (Show, Read, Eq)
  200
+    deriving (Show, Read, Eq, Typeable, Data)
200 201
 
201 202
 instance Package PackageDescription where
202 203
   packageId = package
@@ -274,7 +275,7 @@ data BuildType
274 275
                 --   be built. Doing it this way rather than just giving a
275 276
                 --   parse error means we get better error messages and allows
276 277
                 --   you to inspect the rest of the package description.
277  
-                deriving (Show, Read, Eq)
  278
+                deriving (Show, Read, Eq, Typeable, Data)
278 279
 
279 280
 knownBuildTypes :: [BuildType]
280 281
 knownBuildTypes = [Simple, Configure, Make, Custom]
@@ -300,7 +301,7 @@ data Library = Library {
300 301
         libExposed        :: Bool, -- ^ Is the lib to be exposed by default?
301 302
         libBuildInfo      :: BuildInfo
302 303
     }
303  
-    deriving (Show, Eq, Read)
  304
+    deriving (Show, Eq, Read, Typeable, Data)
304 305
 
305 306
 instance Monoid Library where
306 307
   mempty = Library {
@@ -348,7 +349,7 @@ data Executable = Executable {
348 349
         modulePath :: FilePath,
349 350
         buildInfo  :: BuildInfo
350 351
     }
351  
-    deriving (Show, Read, Eq)
  352
+    deriving (Show, Read, Eq, Typeable, Data)
352 353
 
353 354
 instance Monoid Executable where
354 355
   mempty = Executable {
@@ -402,7 +403,7 @@ data TestSuite = TestSuite {
402 403
         -- a better solution is waiting on the next overhaul to the
403 404
         -- GenericPackageDescription -> PackageDescription resolution process.
404 405
     }
405  
-    deriving (Show, Read, Eq)
  406
+    deriving (Show, Read, Eq, Typeable, Data)
406 407
 
407 408
 -- | The test suite interfaces that are currently defined. Each test suite must
408 409
 -- specify which interface it supports.
@@ -428,7 +429,7 @@ data TestSuiteInterface =
428 429
      -- the given reason (e.g. unknown test type).
429 430
      --
430 431
    | TestSuiteUnsupported TestType
431  
-   deriving (Eq, Read, Show)
  432
+   deriving (Eq, Read, Show, Typeable, Data)
432 433
 
433 434
 instance Monoid TestSuite where
434 435
     mempty = TestSuite {
@@ -484,7 +485,7 @@ testModules test = (case testInterface test of
484 485
 data TestType = TestTypeExe Version     -- ^ \"type: exitcode-stdio-x.y\"
485 486
               | TestTypeLib Version     -- ^ \"type: detailed-x.y\"
486 487
               | TestTypeUnknown String Version -- ^ Some unknown test type e.g. \"type: foo\"
487  
-    deriving (Show, Read, Eq)
  488
+    deriving (Show, Read, Eq, Typeable, Data)
488 489
 
489 490
 knownTestTypes :: [TestType]
490 491
 knownTestTypes = [ TestTypeExe (Version [1,0] [])
@@ -533,7 +534,7 @@ data Benchmark = Benchmark {
533 534
         benchmarkEnabled   :: Bool
534 535
         -- TODO: See TODO for 'testEnabled'.
535 536
     }
536  
-    deriving (Show, Read, Eq)
  537
+    deriving (Show, Read, Eq, Typeable, Data)
537 538
 
538 539
 -- | The benchmark interfaces that are currently defined. Each
539 540
 -- benchmark must specify which interface it supports.
@@ -555,7 +556,7 @@ data BenchmarkInterface =
555 556
      -- interfaces for the given reason (e.g. unknown benchmark type).
556 557
      --
557 558
    | BenchmarkUnsupported BenchmarkType
558  
-   deriving (Eq, Read, Show)
  559
+   deriving (Eq, Read, Show, Typeable, Data)
559 560
 
560 561
 instance Monoid Benchmark where
561 562
     mempty = Benchmark {
@@ -609,7 +610,7 @@ data BenchmarkType = BenchmarkTypeExe Version
609 610
                      -- ^ \"type: exitcode-stdio-x.y\"
610 611
                    | BenchmarkTypeUnknown String Version
611 612
                      -- ^ Some unknown benchmark type e.g. \"type: foo\"
612  
-    deriving (Show, Read, Eq)
  613
+    deriving (Show, Read, Eq, Typeable, Data)
613 614
 
614 615
 knownBenchmarkTypes :: [BenchmarkType]
615 616
 knownBenchmarkTypes = [ BenchmarkTypeExe (Version [1,0] []) ]
@@ -663,7 +664,7 @@ data BuildInfo = BuildInfo {
663 664
                                                 -- simple assoc-list.
664 665
         targetBuildDepends :: [Dependency] -- ^ Dependencies specific to a library or executable target
665 666
     }
666  
-    deriving (Show,Read,Eq)
  667
+    deriving (Show,Read,Eq,Typeable,Data)
667 668
 
668 669
 instance Monoid BuildInfo where
669 670
   mempty = BuildInfo {
@@ -837,7 +838,7 @@ data SourceRepo = SourceRepo {
837 838
   -- given the default is \".\" ie no subdirectory.
838 839
   repoSubdir   :: Maybe FilePath
839 840
 }
840  
-  deriving (Eq, Read, Show)
  841
+  deriving (Eq, Read, Show, Typeable, Data)
841 842
 
842 843
 -- | What this repo info is for, what it represents.
843 844
 --
@@ -853,7 +854,7 @@ data RepoKind =
853 854
   | RepoThis
854 855
 
855 856
   | RepoKindUnknown String
856  
-  deriving (Eq, Ord, Read, Show)
  857
+  deriving (Eq, Ord, Read, Show, Typeable, Data)
857 858
 
858 859
 -- | An enumeration of common source control systems. The fields used in the
859 860
 -- 'SourceRepo' depend on the type of repo. The tools and methods used to
@@ -862,7 +863,7 @@ data RepoKind =
862 863
 data RepoType = Darcs | Git | SVN | CVS
863 864
               | Mercurial | GnuArch | Bazaar | Monotone
864 865
               | OtherRepoType String
865  
-  deriving (Eq, Ord, Read, Show)
  866
+  deriving (Eq, Ord, Read, Show, Typeable, Data)
866 867
 
867 868
 knownRepoTypes :: [RepoType]
868 869
 knownRepoTypes = [Darcs, Git, SVN, CVS
@@ -945,7 +946,7 @@ data GenericPackageDescription =
945 946
         condTestSuites     :: [(String, CondTree ConfVar [Dependency] TestSuite)],
946 947
         condBenchmarks     :: [(String, CondTree ConfVar [Dependency] Benchmark)]
947 948
       }
948  
-    deriving (Show, Eq, Typeable)
  949
+    deriving (Show, Eq, Typeable, Data)
949 950
 
950 951
 instance Package GenericPackageDescription where
951 952
   packageId = packageId . packageDescription
@@ -960,11 +961,11 @@ data Flag = MkFlag
960 961
     , flagDefault     :: Bool
961 962
     , flagManual      :: Bool
962 963
     }
963  
-    deriving (Show, Eq)
  964
+    deriving (Show, Eq, Typeable, Data)
964 965
 
965 966
 -- | A 'FlagName' is the name of a user-defined configuration flag
966 967
 newtype FlagName = FlagName String
967  
-    deriving (Eq, Ord, Show, Read)
  968
+    deriving (Eq, Ord, Show, Read, Typeable, Data)
968 969
 
969 970
 -- | A 'FlagAssignment' is a total or partial mapping of 'FlagName's to
970 971
 -- 'Bool' flag values. It represents the flags chosen by the user or
@@ -978,7 +979,7 @@ data ConfVar = OS OS
978 979
              | Arch Arch
979 980
              | Flag FlagName
980 981
              | Impl CompilerFlavor VersionRange
981  
-    deriving (Eq, Show)
  982
+    deriving (Eq, Show, Typeable, Data)
982 983
 
983 984
 --instance Text ConfVar where
984 985
 --    disp (OS os) = "os(" ++ display os ++ ")"
@@ -993,7 +994,7 @@ data Condition c = Var c
993 994
                  | CNot (Condition c)
994 995
                  | COr (Condition c) (Condition c)
995 996
                  | CAnd (Condition c) (Condition c)
996  
-    deriving (Show, Eq)
  997
+    deriving (Show, Eq, Typeable, Data)
997 998
 
998 999
 --instance Text c => Text (Condition c) where
999 1000
 --  disp (Var x) = text (show x)
@@ -1009,7 +1010,7 @@ data CondTree v c a = CondNode
1009 1010
                               , CondTree v c a
1010 1011
                               , Maybe (CondTree v c a))]
1011 1012
     }
1012  
-    deriving (Show, Eq)
  1013
+    deriving (Show, Eq, Typeable, Data)
1013 1014
 
1014 1015
 --instance (Text v, Text c) => Text (CondTree v c a) where
1015 1016
 --  disp (CondNode _dat cs ifs) =
9  Cabal/Distribution/System.hs
... ...
@@ -1,3 +1,4 @@
  1
+{-# LANGUAGE DeriveDataTypeable #-}
1 2
 -----------------------------------------------------------------------------
2 3
 -- |
3 4
 -- Module      :  Distribution.System
@@ -31,6 +32,8 @@ module Distribution.System (
31 32
 import qualified System.Info (os, arch)
32 33
 import qualified Data.Char as Char (toLower, isAlphaNum)
33 34
 
  35
+import Data.Data (Data)
  36
+import Data.Typeable (Typeable)
34 37
 import Data.Maybe (fromMaybe, listToMaybe)
35 38
 import Distribution.Text (Text(..), display)
36 39
 import qualified Distribution.Compat.ReadP as Parse
@@ -66,7 +69,7 @@ data OS = Linux | Windows | OSX        -- tier 1 desktop OSs
66 69
         | HaLVM                        -- bare metal / VMs / hypervisors
67 70
         | IOS                          -- iOS
68 71
         | OtherOS String
69  
-  deriving (Eq, Ord, Show, Read)
  72
+  deriving (Eq, Ord, Show, Read, Typeable, Data)
70 73
 
71 74
 --TODO: decide how to handle Android and iOS.
72 75
 -- They are like Linux and OSX but with some differences.
@@ -116,7 +119,7 @@ data Arch = I386  | X86_64 | PPC | PPC64 | Sparc
116 119
           | Alpha | Hppa   | Rs6000
117 120
           | M68k  | Vax
118 121
           | OtherArch String
119  
-  deriving (Eq, Ord, Show, Read)
  122
+  deriving (Eq, Ord, Show, Read, Typeable, Data)
120 123
 
121 124
 knownArches :: [Arch]
122 125
 knownArches = [I386, X86_64, PPC, PPC64, Sparc
@@ -157,7 +160,7 @@ buildArch = classifyArch Permissive System.Info.arch
157 160
 -- ------------------------------------------------------------
158 161
 
159 162
 data Platform = Platform Arch OS
160  
-  deriving (Eq, Ord, Show, Read)
  163
+  deriving (Eq, Ord, Show, Read, Typeable, Data)
161 164
 
162 165
 instance Text Platform where
163 166
   disp (Platform arch os) = disp arch <> Disp.char '-' <> disp os
8  Cabal/Distribution/Version.hs
... ...
@@ -1,4 +1,4 @@
1  
-{-# LANGUAGE DeriveDataTypeable #-}
  1
+{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
2 2
 -----------------------------------------------------------------------------
3 3
 -- |
4 4
 -- Module      :  Distribution.Version
@@ -92,6 +92,7 @@ module Distribution.Version (
92 92
 
93 93
  ) where
94 94
 
  95
+import Data.Data        ( Data )
95 96
 import Data.Typeable    ( Typeable )
96 97
 import Data.Version     ( Version(..) )
97 98
 
@@ -118,7 +119,10 @@ data VersionRange
118 119
   | UnionVersionRanges     VersionRange VersionRange
119 120
   | IntersectVersionRanges VersionRange VersionRange
120 121
   | VersionRangeParens     VersionRange -- just '(exp)' parentheses syntax
121  
-  deriving (Show,Read,Eq,Typeable)
  122
+  deriving (Show,Read,Eq,Typeable,Data)
  123
+
  124
+-- TODO orphan
  125
+deriving instance Data Version
122 126
 
123 127
 {-# DEPRECATED AnyVersion "Use 'anyVersion', 'foldVersionRange' or 'asVersionIntervals'" #-}
124 128
 {-# DEPRECATED ThisVersion "use 'thisVersion', 'foldVersionRange' or 'asVersionIntervals'" #-}
9  Cabal/Language/Haskell/Extension.hs
... ...
@@ -1,3 +1,4 @@
  1
+{-# LANGUAGE DeriveDataTypeable #-}
1 2
 -----------------------------------------------------------------------------
2 3
 -- |
3 4
 -- Module      :  Language.Haskell.Extension
@@ -53,6 +54,8 @@ import qualified Distribution.Compat.ReadP as Parse
53 54
 import qualified Text.PrettyPrint as Disp
54 55
 import qualified Data.Char as Char (isAlphaNum)
55 56
 import Data.Array (Array, accumArray, bounds, Ix(inRange), (!))
  57
+import Data.Data (Data)
  58
+import Data.Typeable (Typeable)
56 59
 
57 60
 -- ------------------------------------------------------------
58 61
 -- * Language
@@ -75,7 +78,7 @@ data Language =
75 78
 
76 79
   -- | An unknown language, identified by its name.
77 80
   | UnknownLanguage String
78  
-  deriving (Show, Read, Eq)
  81
+  deriving (Show, Read, Eq, Typeable, Data)
79 82
 
80 83
 knownLanguages :: [Language]
81 84
 knownLanguages = [Haskell98, Haskell2010]
@@ -123,7 +126,7 @@ data Extension =
123 126
   -- pragma.
124 127
   | UnknownExtension String
125 128
 
126  
-  deriving (Show, Read, Eq)
  129
+  deriving (Show, Read, Eq, Typeable, Data)
127 130
 
128 131
 data KnownExtension =
129 132
 
@@ -654,7 +657,7 @@ data KnownExtension =
654 657
   -- * <http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell>
655 658
   | ParallelArrays
656 659
 
657  
-  deriving (Show, Read, Eq, Enum, Bounded)
  660
+  deriving (Show, Read, Eq, Enum, Bounded, Typeable, Data)
658 661
 
659 662
 {-# DEPRECATED knownExtensions
660 663
    "KnownExtension is an instance of Enum and Bounded, use those instead." #-}

0 notes on commit 84ed9f2

Please sign in to comment.
Something went wrong with that request. Please try again.