on master help sign in
With(out) generic flag
dff2dafAlexander V. Nikolaev
jrec.cabal+10−1
@@ -24,6 +24,13 @@ flag with-aeson
24 -- with instances by default
24 -- with instances by default
25 default: True
25 default: True
26
26
27+flag with-generics
28+ description: Enable GHC.Generics instances
29+ -- don't let the solver fiddle with the flag
30+ manual: True
31+ -- with instances by default
32+ default: True
33+
27-- A common stanza to share with tests, so that ghcid (bin/test) will reload
34-- A common stanza to share with tests, so that ghcid (bin/test) will reload
28-- instantly when the library sources change (without us having to restart it).
35-- instantly when the library sources change (without us having to restart it).
29common library-common
36common library-common
@@ -81,13 +88,15 @@ library
81 JRec.Field
88 JRec.Field
82 if flag(with-aeson)
89 if flag(with-aeson)
83 cpp-options: -DWITH_AESON
90 cpp-options: -DWITH_AESON
91+ if flag(with-generics)
92+ cpp-options: -DWITH_GENERICS
84
93
85test-suite jrec-test
94test-suite jrec-test
86 import: library-common
95 import: library-common
87 type: exitcode-stdio-1.0
96 type: exitcode-stdio-1.0
88 hs-source-dirs: test, src
97 hs-source-dirs: test, src
89 main-is: Spec.hs
98 main-is: Spec.hs
90− cpp-options: -DWITH_AESON
99+ cpp-options: -DWITH_AESON -DWITH_GENERICS
91 build-depends:
100 build-depends:
92 base,
101 base,
93 hspec,
102 hspec,
src/JRec.hs+3
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE GADTs #-}
2{-# LANGUAGE GADTs #-}
2{-# LANGUAGE PatternSynonyms #-}
3{-# LANGUAGE PatternSynonyms #-}
3{-# LANGUAGE TypeApplications #-}
4{-# LANGUAGE TypeApplications #-}
@@ -128,6 +129,7 @@ type RecordRep fields =
128 (Sels fields)
129 (Sels fields)
129 )
130 )
130
131
132+#ifdef WITH_GENERICS
131instance
133instance
132 (R.FromNative (RecordRep fields) fields, R.ToNative (RecordRep fields) fields) =>
134 (R.FromNative (RecordRep fields) fields, R.ToNative (RecordRep fields) fields) =>
133 Generic (Rec fields)
135 Generic (Rec fields)
@@ -137,6 +139,7 @@ instance
137 RecordRep fields
139 RecordRep fields
138 from r = R.toNative' r
140 from r = R.toNative' r
139 to rep = R.fromNative' rep
141 to rep = R.fromNative' rep
142+#endif
140
143
141----------------------------------------------------------------------------
144----------------------------------------------------------------------------
142-- generic-lens
145-- generic-lens