git.iko.soy/typeable/servant
on master help sign in
servant-foreign: Derive Data for all types
335e30bOllie Charles
servant-foreign/servant-foreign.cabal−1
@@ -55,7 +55,6 @@ library
55 , GeneralizedNewtypeDeriving
55 , GeneralizedNewtypeDeriving
56 , MultiParamTypeClasses
56 , MultiParamTypeClasses
57 , ScopedTypeVariables
57 , ScopedTypeVariables
58− , StandaloneDeriving
59 , TemplateHaskell
58 , TemplateHaskell
60 , TypeFamilies
59 , TypeFamilies
61 , TypeOperators
60 , TypeOperators
servant-foreign/src/Servant/Foreign/Internal.hs+12−24
@@ -1,4 +1,5 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DeriveDataTypeable #-}
2#if !MIN_VERSION_base(4,8,0)
3#if !MIN_VERSION_base(4,8,0)
3{-# LANGUAGE NullaryTypeClasses #-}
4{-# LANGUAGE NullaryTypeClasses #-}
4#endif
5#endif
@@ -9,6 +10,7 @@ module Servant.Foreign.Internal where
9
10
10import Control.Lens (makePrisms, makeLenses, Getter, (&), (<>~), (%~),
11import Control.Lens (makePrisms, makeLenses, Getter, (&), (<>~), (%~),
11 (.~))
12 (.~))
13+import Data.Data
12#if !MIN_VERSION_base(4,8,0)
14#if !MIN_VERSION_base(4,8,0)
13import Data.Monoid
15import Data.Monoid
14#endif
16#endif
@@ -24,21 +26,19 @@ import Servant.API.TypeLevel
24
26
25
27
26newtype FunctionName = FunctionName { unFunctionName :: [Text] }
28newtype FunctionName = FunctionName { unFunctionName :: [Text] }
27− deriving (Show, Eq, Monoid)
29+ deriving (Data, Show, Eq, Monoid)
28
30
29makePrisms ''FunctionName
31makePrisms ''FunctionName
30
32
31newtype PathSegment = PathSegment { unPathSegment :: Text }
33newtype PathSegment = PathSegment { unPathSegment :: Text }
32− deriving (Show, Eq, IsString, Monoid)
34+ deriving (Data, Show, Eq, IsString, Monoid)
33
35
34makePrisms ''PathSegment
36makePrisms ''PathSegment
35
37
36data Arg f = Arg
38data Arg f = Arg
37 { _argName :: PathSegment
39 { _argName :: PathSegment
38 , _argType :: f }
40 , _argType :: f }
39−
40−deriving instance Eq f => Eq (Arg f)
41+ deriving (Data, Eq, Show)
41−deriving instance Show f => Show (Arg f)
42
42
43makeLenses ''Arg
43makeLenses ''Arg
44
44
@@ -50,16 +50,12 @@ data SegmentType f
50 -- ^ a static path segment. like "/foo"
50 -- ^ a static path segment. like "/foo"
51 | Cap (Arg f)
51 | Cap (Arg f)
52 -- ^ a capture. like "/:userid"
52 -- ^ a capture. like "/:userid"
53−
53+ deriving (Data, Eq, Show)
54−deriving instance Eq f => Eq (SegmentType f)
55−deriving instance Show f => Show (SegmentType f)
56
54
57makePrisms ''SegmentType
55makePrisms ''SegmentType
58
56
59newtype Segment f = Segment { unSegment :: SegmentType f }
57newtype Segment f = Segment { unSegment :: SegmentType f }
60−
61−deriving instance Eq f => Eq (Segment f)
58+ deriving (Data, Eq, Show)
62−deriving instance Show f => Show (Segment f)
63
59
64makePrisms ''Segment
60makePrisms ''Segment
65
61
@@ -77,7 +73,7 @@ data ArgType
77 = Normal
73 = Normal
78 | Flag
74 | Flag
79 | List
75 | List
80− deriving (Eq, Show)
76+ deriving (Data, Eq, Show)
81
77
82makePrisms ''ArgType
78makePrisms ''ArgType
83
79
@@ -85,9 +81,7 @@ data QueryArg f = QueryArg
85 { _queryArgName :: Arg f
81 { _queryArgName :: Arg f
86 , _queryArgType :: ArgType
82 , _queryArgType :: ArgType
87 }
83 }
88−
89−deriving instance Eq f => Eq (QueryArg f)
84+ deriving (Data, Eq, Show)
90−deriving instance Show f => Show (QueryArg f)
91
85
92makeLenses ''QueryArg
86makeLenses ''QueryArg
93
87
@@ -97,9 +91,7 @@ data HeaderArg f = HeaderArg
97 { _headerArg :: Arg f
91 { _headerArg :: Arg f
98 , _headerPattern :: Text
92 , _headerPattern :: Text
99 }
93 }
100−
101−deriving instance Eq f => Eq (HeaderArg f)
94+ deriving (Data, Eq, Show)
102−deriving instance Show f => Show (HeaderArg f)
103
95
104makeLenses ''HeaderArg
96makeLenses ''HeaderArg
105
97
@@ -109,9 +101,7 @@ data Url f = Url
109 { _path :: Path f
101 { _path :: Path f
110 , _queryStr :: [QueryArg f]
102 , _queryStr :: [QueryArg f]
111 }
103 }
112−
113−deriving instance Eq f => Eq (Url f)
104+ deriving (Data, Eq, Show)
114−deriving instance Show f => Show (Url f)
115
105
116defUrl :: Url f
106defUrl :: Url f
117defUrl = Url [] []
107defUrl = Url [] []
@@ -126,9 +116,7 @@ data Req f = Req
126 , _reqReturnType :: Maybe f
116 , _reqReturnType :: Maybe f
127 , _reqFuncName :: FunctionName
117 , _reqFuncName :: FunctionName
128 }
118 }
129−
130−deriving instance Eq f => Eq (Req f)
119+ deriving (Data, Eq, Show)
131−deriving instance Show f => Show (Req f)
132
120
133makeLenses ''Req
121makeLenses ''Req
134
122