Skip to content
This repository
Browse code

Split Contains out from Ixed.

  • Loading branch information...
commit 32697f3d7f752a5540ca0842b428ae5c56ec49aa 1 parent 6cf61dd
Edward Kmett authored January 19, 2013
279  src/Control/Lens/At.hs
@@ -27,22 +27,27 @@
27 27
 ----------------------------------------------------------------------------
28 28
 module Control.Lens.At
29 29
   (
30  
-  -- * Indexed Lens
31  
-    At(at)
32  
-  , ixAt
33  
-  , ixEach
34  
-  -- * Indexed Traversal
  30
+  -- * Keys
  31
+    Key
  32
+  -- * Contains
  33
+  , Contains(..)
  34
+  , containsIx, containsAt, containsLength, containsN, containsTest, containsLookup
  35
+  -- * Ixed
  36
+  , Value
35 37
   , Ixed(ix)
36  
-  , IxKey, IxValue
  38
+  , ixAt, ixEach
  39
+  -- * At
  40
+  , At(at)
37 41
   -- * Deprecated
38 42
   , _at
39  
-  , contains
40 43
   , resultAt
41 44
   ) where
42 45
 
43 46
 import Control.Applicative
44 47
 import Control.Lens.Combinators
45 48
 import Control.Lens.Each
  49
+import Control.Lens.Fold
  50
+import Control.Lens.Getter
46 51
 import Control.Lens.Indexed as Lens
47 52
 import Control.Lens.Type
48 53
 import Control.Lens.Traversal
@@ -51,9 +56,11 @@ import Data.Array.Unboxed
51 56
 import Data.Hashable
52 57
 import Data.HashMap.Lazy as HashMap
53 58
 import Data.HashSet as HashSet
54  
-import Data.IntMap as IntMap
  59
+import Data.IntMap as IntMap hiding (Key)
55 60
 import Data.IntSet as IntSet
56 61
 import Data.Map as Map
  62
+import Data.Maybe
  63
+import Data.Monoid
57 64
 import Data.Set as Set
58 65
 import Data.Sequence as Seq
59 66
 import Data.Vector as Vector hiding (indexed)
@@ -68,18 +75,175 @@ import Data.Vector.Storable as Storable
68 75
 -- >>> let g :: Expr -> Expr; g = Debug.SimpleReflect.Vars.g
69 76
 
70 77
 -- | A deprecated alias for 'ix'.
71  
-contains, _at, resultAt :: Ixed f m => IxKey m -> IndexedLensLike' (IxKey m) f m (IxValue m)
72  
-contains = ix
  78
+_at, resultAt :: Ixed f m => Key m -> IndexedLensLike' (Key m) f m (Value m)
73 79
 _at      = ix
74 80
 resultAt = ix
75  
-{-# DEPRECATED _at, contains, resultAt "use 'ix'. This function will be removed in version 3.9" #-}
  81
+{-# DEPRECATED _at, resultAt "use 'ix'. This function will be removed in version 3.9" #-}
76 82
 
77  
-type family IxKey (m :: *) :: *
78  
-type family IxValue (m :: *) :: *
  83
+type family Key (m :: *) :: *
  84
+
  85
+class Functor f => Contains f m where
  86
+  -- |
  87
+  -- This simple 'IndexedTraversal' lets you view (and sometimes modify) whether
  88
+  -- or not a map (or set) contains a given key.
  89
+  --
  90
+  -- >>> IntSet.fromList [1,2,3,4] ^. contains 3
  91
+  -- True
  92
+  --
  93
+  -- >>> IntSet.fromList [1,2,3,4] ^. contains 5
  94
+  -- False
  95
+  --
  96
+  -- >>> IntSet.fromList [1,2,3,4] & contains 3 .~ False
  97
+  -- fromList [1,2,4]
  98
+  contains :: Key m -> IndexedLensLike' (Key m) f m Bool
  99
+#ifdef DEFAULT_SIGNATURES
  100
+  default contains :: (Gettable f, At m) => Key m -> IndexedLensLike' (Key m) f m Bool
  101
+  contains = containsAt
  102
+#endif
  103
+
  104
+-- | A definition of 'ix' for types with an 'At' instance. This is the default
  105
+-- if you don't specify a definition for 'ix'.
  106
+containsIx :: (Gettable f, Ixed (Accessor Any) m) => Key m -> IndexedLensLike' (Key m) f m Bool
  107
+containsIx i f = coerce . indexed f i . has (ix i)
  108
+{-# INLINE containsIx #-}
  109
+
  110
+-- | A definition of 'ix' for types with an 'At' instance. This is the default
  111
+-- if you don't specify a definition for 'ix'.
  112
+containsAt :: (Gettable f, At m) => Key m -> IndexedLensLike' (Key m) f m Bool
  113
+containsAt i f = coerce . indexed f i . views (at i) isJust
  114
+{-# INLINE containsAt #-}
  115
+
  116
+containsLength :: forall i s. (Ord i, Num i) => (s -> i) -> i -> IndexedGetter i s Bool
  117
+containsLength sn = \ i pafb s -> coerce $ indexed pafb (i :: i) (0 <= i && i < sn s)
  118
+{-# INLINE containsLength #-}
  119
+
  120
+containsN :: Int -> Int -> IndexedGetter Int s Bool
  121
+containsN n = \ i pafb _ -> coerce $ indexed pafb (i :: Int) (0 <= i && i < n)
  122
+{-# INLINE containsN #-}
  123
+
  124
+containsTest :: forall i s. (i -> s -> Bool) -> i -> IndexedGetter i s Bool
  125
+containsTest isb = \i pafb s -> coerce $ indexed pafb (i :: i) (isb i s)
  126
+{-# INLINE containsTest #-}
  127
+
  128
+containsLookup :: forall i s a. (i -> s -> Maybe a) -> i -> IndexedGetter i s Bool
  129
+containsLookup isb = \i pafb s -> coerce $ indexed pafb (i :: i) (isJust (isb i s))
  130
+{-# INLINE containsLookup #-}
  131
+
  132
+type instance Key (e -> a) = e
  133
+instance Gettable f => Contains f (e -> a) where
  134
+  contains i f _ = coerce (indexed f i True)
  135
+  {-# INLINE contains #-}
  136
+
  137
+type instance Key IntSet = Int
  138
+instance Functor f => Contains f IntSet where
  139
+  contains k f s = indexed f k (IntSet.member k s) <&> \b ->
  140
+    if b then IntSet.insert k s else IntSet.delete k s
  141
+  {-# INLINE contains #-}
  142
+
  143
+type instance Key (Set a) = a
  144
+instance (Functor f, Ord a) => Contains f (Set a) where
  145
+  contains k f s = indexed f k (Set.member k s) <&> \b ->
  146
+    if b then Set.insert k s else Set.delete k s
  147
+  {-# INLINE contains #-}
  148
+
  149
+type instance Key (HashSet a) = a
  150
+instance (Functor f, Eq a, Hashable a) => Contains f (HashSet a) where
  151
+  contains k f s = indexed f k (HashSet.member k s) <&> \b ->
  152
+    if b then HashSet.insert k s else HashSet.delete k s
  153
+  {-# INLINE contains #-}
  154
+
  155
+type instance Key [a] = Int
  156
+instance Gettable f => Contains f [a] where
  157
+  contains = containsLength Prelude.length
  158
+  {-# INLINE contains #-}
  159
+
  160
+type instance Key (Seq a) = Int
  161
+instance Gettable f => Contains f (Seq a) where
  162
+  contains = containsLength Seq.length
  163
+  {-# INLINE contains #-}
  164
+
  165
+type instance Key (a,b) = Int
  166
+instance Gettable k => Contains k (a,b) where
  167
+  contains = containsN 2
  168
+  {-# INLINE contains #-}
  169
+
  170
+type instance Key (a,b,c) = Int
  171
+instance Gettable k => Contains k (a,b,c) where
  172
+  contains = containsN 3
  173
+  {-# INLINE contains #-}
  174
+
  175
+type instance Key (a,b,c,d) = Int
  176
+instance Gettable k => Contains k (a,b,c,d) where
  177
+  contains = containsN 4
  178
+  {-# INLINE contains #-}
  179
+
  180
+type instance Key (a,b,c,d,e) = Int
  181
+instance Gettable k => Contains k (a,b,c,d,e) where
  182
+  contains = containsN 5
  183
+  {-# INLINE contains #-}
  184
+
  185
+type instance Key (a,b,c,d,e,f) = Int
  186
+instance Gettable k => Contains k (a,b,c,d,e,f) where
  187
+  contains = containsN 6
  188
+  {-# INLINE contains #-}
  189
+
  190
+type instance Key (a,b,c,d,e,f,g) = Int
  191
+instance Gettable k => Contains k (a,b,c,d,e,f,g) where
  192
+  contains = containsN 7
  193
+  {-# INLINE contains #-}
  194
+
  195
+type instance Key (a,b,c,d,e,f,g,h) = Int
  196
+instance Gettable k => Contains k (a,b,c,d,e,f,g,h) where
  197
+  contains = containsN 8
  198
+  {-# INLINE contains #-}
  199
+
  200
+type instance Key (a,b,c,d,e,f,g,h,i) = Int
  201
+instance Gettable k => Contains k (a,b,c,d,e,f,g,h,i) where
  202
+  contains = containsN 9
  203
+  {-# INLINE contains #-}
  204
+
  205
+type instance Key (IntMap a) = Int
  206
+instance Gettable k => Contains k (IntMap a) where
  207
+  contains = containsLookup IntMap.lookup
  208
+  {-# INLINE contains #-}
  209
+
  210
+type instance Key (Map k a) = k
  211
+instance (Gettable f, Ord k) => Contains f (Map k a) where
  212
+  contains = containsLookup Map.lookup
  213
+  {-# INLINE contains #-}
  214
+
  215
+type instance Key (HashMap k a) = k
  216
+instance (Gettable f, Eq k, Hashable k) => Contains f (HashMap k a) where
  217
+  contains = containsLookup HashMap.lookup
  218
+  {-# INLINE contains #-}
  219
+
  220
+type instance Key (Array i e) = i
  221
+instance (Gettable f, Ix i) => Contains f (Array i e) where
  222
+  contains = containsTest $ \i s -> inRange (bounds s) i
  223
+  {-# INLINE contains #-}
  224
+
  225
+type instance Key (UArray i e) = i
  226
+instance (Gettable f, IArray UArray e, Ix i) => Contains f (UArray i e) where
  227
+  contains = containsTest $ \i s -> inRange (bounds s) i
  228
+  {-# INLINE contains #-}
  229
+
  230
+type instance Key (Vector.Vector a) = Int
  231
+instance Gettable f => Contains f (Vector.Vector a) where
  232
+  contains = containsLength Vector.length
  233
+
  234
+type instance Key (Prim.Vector a) = Int
  235
+instance (Gettable f, Prim a) => Contains f (Prim.Vector a) where
  236
+  contains = containsLength Prim.length
  237
+
  238
+type instance Key (Storable.Vector a) = Int
  239
+instance (Gettable f, Storable a) => Contains f (Storable.Vector a) where
  240
+  contains = containsLength Storable.length
  241
+
  242
+type family Value (m :: *) :: *
79 243
 
80 244
 -- | This simple 'IndexedTraversal' lets you 'traverse' the value at a given
81 245
 -- key in a 'Map' or element at an ordinal position in a list or 'Seq'.
82  
-class Ixed f m where
  246
+class Contains (Accessor (Value m)) m => Ixed f m where
83 247
   -- | This simple 'IndexedTraversal' lets you 'traverse' the value at a given
84 248
   -- key in a 'Map' or element at an ordinal position in a list or 'Seq'.
85 249
   --
@@ -99,34 +263,24 @@ class Ixed f m where
99 263
   --
100 264
   -- >>> Seq.fromList [] ^? ix 2
101 265
   -- Nothing
102  
-  --
103  
-  -- >>> IntSet.fromList [1,2,3,4] & ix 3 .~ False
104  
-  -- fromList [1,2,4]
105  
-  --
106  
-  -- >>> IntSet.fromList [1,2,3,4] ^. ix 3
107  
-  -- True
108  
-
109  
-  -- >>> IntSet.fromList [1,2,3,4] ^. ix 5
110  
-  -- False
111  
-  ix :: IxKey m -> IndexedLensLike' (IxKey m) f m (IxValue m)
  266
+  ix :: Key m -> IndexedLensLike' (Key m) f m (Value m)
112 267
 #ifdef DEFAULT_SIGNATURES
113  
-  default ix :: (Applicative f, At m) => IxKey m -> IndexedLensLike' (IxKey m) f m (IxValue m)
  268
+  default ix :: (Applicative f, At m) => Key m -> IndexedLensLike' (Key m) f m (Value m)
114 269
   ix = ixAt
115 270
 #endif
116 271
 
117 272
 -- | A definition of 'ix' for types with an 'At' instance. This is the default
118 273
 -- if you don't specify a definition for 'ix'.
119  
-ixAt :: (Applicative f, At m) => IxKey m -> IndexedLensLike' (IxKey m) f m (IxValue m)
  274
+ixAt :: (Applicative f, At m) => Key m -> IndexedLensLike' (Key m) f m (Value m)
120 275
 ixAt i = at i <. traverse
121 276
 {-# INLINE ixAt #-}
122 277
 
123 278
 -- | A definition of 'ix' for types with an 'Each' instance.
124  
-ixEach :: (Applicative f, Eq (IxKey m), Each (IxKey m) f m m (IxValue m) (IxValue m)) => IxKey m -> IndexedLensLike' (IxKey m) f m (IxValue m)
  279
+ixEach :: (Applicative f, Eq (Key m), Each (Key m) f m m (Value m) (Value m)) => Key m -> IndexedLensLike' (Key m) f m (Value m)
125 280
 ixEach i = each . Lens.index i
126 281
 {-# INLINE ixEach #-}
127 282
 
128  
-type instance IxKey [a] = Int
129  
-type instance IxValue [a] = a
  283
+type instance Value [a] = a
130 284
 instance Applicative f => Ixed f [a] where
131 285
   ix k f xs0 = go xs0 k where
132 286
     go [] _ = pure []
@@ -134,40 +288,35 @@ instance Applicative f => Ixed f [a] where
134 288
     go (a:as) i = (a:) <$> (go as $! i - 1)
135 289
   {-# INLINE ix #-}
136 290
 
137  
-type instance IxKey (Seq a) = Int
138  
-type instance IxValue (Seq a) = a
  291
+type instance Value (Seq a) = a
139 292
 instance Applicative f => Ixed f (Seq a) where
140 293
   ix i f m
141 294
     | 0 <= i && i < Seq.length m = indexed f i (Seq.index m i) <&> \a -> Seq.update i a m
142 295
     | otherwise                  = pure m
143 296
   {-# INLINE ix #-}
144 297
 
145  
-type instance IxKey (IntMap a) = Int
146  
-type instance IxValue (IntMap a) = a
  298
+type instance Value (IntMap a) = a
147 299
 instance Applicative f => Ixed f (IntMap a) where
148 300
   ix k f m = case IntMap.lookup k m of
149 301
      Just v -> indexed f k v <&> \v' -> IntMap.insert k v' m
150 302
      Nothing -> pure m
151 303
   {-# INLINE ix #-}
152 304
 
153  
-type instance IxKey (Map k a) = k
154  
-type instance IxValue (Map k a) = a
  305
+type instance Value (Map k a) = a
155 306
 instance (Applicative f, Ord k) => Ixed f (Map k a) where
156 307
   ix k f m = case Map.lookup k m of
157 308
      Just v  -> indexed f k v <&> \v' -> Map.insert k v' m
158 309
      Nothing -> pure m
159 310
   {-# INLINE ix #-}
160 311
 
161  
-type instance IxKey (HashMap k a) = k
162  
-type instance IxValue (HashMap k a) = a
  312
+type instance Value (HashMap k a) = a
163 313
 instance (Applicative f, Eq k, Hashable k) => Ixed f (HashMap k a) where
164 314
   ix k f m = case HashMap.lookup k m of
165 315
      Just v  -> indexed f k v <&> \v' -> HashMap.insert k v' m
166 316
      Nothing -> pure m
167 317
   {-# INLINE ix #-}
168 318
 
169  
-type instance IxKey (Array i e) = i
170  
-type instance IxValue (Array i e) = e
  319
+type instance Value (Array i e) = e
171 320
 -- |
172 321
 -- @
173 322
 -- arr '!' i ≡ arr 'Control.Lens.Getter.^.' 'ix' i
@@ -179,8 +328,7 @@ instance (Applicative f, Ix i) => Ixed f (Array i e) where
179 328
     | otherwise              = pure arr
180 329
   {-# INLINE ix #-}
181 330
 
182  
-type instance IxKey (UArray i e) = i
183  
-type instance IxValue (UArray i e) = e
  331
+type instance Value (UArray i e) = e
184 332
 -- |
185 333
 -- @
186 334
 -- arr '!' i ≡ arr 'Control.Lens.Getter.^.' 'ix' i
@@ -192,101 +340,88 @@ instance (Applicative f, IArray UArray e, Ix i) => Ixed f (UArray i e) where
192 340
     | otherwise              = pure arr
193 341
   {-# INLINE ix #-}
194 342
 
195  
-type instance IxKey (Vector.Vector a) = Int
196  
-type instance IxValue (Vector.Vector a) = a
  343
+type instance Value (Vector.Vector a) = a
197 344
 instance Applicative f => Ixed f (Vector.Vector a) where
198 345
   ix i f v
199 346
     | 0 <= i && i < Vector.length v = indexed f i (v Vector.! i) <&> \a -> v Vector.// [(i, a)]
200 347
     | otherwise                     = pure v
201 348
   {-# INLINE ix #-}
202 349
 
203  
-type instance IxKey (Prim.Vector a) = Int
204  
-type instance IxValue (Prim.Vector a) = a
  350
+type instance Value (Prim.Vector a) = a
205 351
 instance (Applicative f, Prim a) => Ixed f (Prim.Vector a) where
206 352
   ix i f v
207 353
     | 0 <= i && i < Prim.length v = indexed f i (v Prim.! i) <&> \a -> v Prim.// [(i, a)]
208 354
     | otherwise                   = pure v
209 355
   {-# INLINE ix #-}
210 356
 
211  
-type instance IxKey (Storable.Vector a) = Int
212  
-type instance IxValue (Storable.Vector a) = a
  357
+type instance Value (Storable.Vector a) = a
213 358
 instance (Applicative f, Storable a) => Ixed f (Storable.Vector a) where
214 359
   ix i f v
215 360
     | 0 <= i && i < Storable.length v = indexed f i (v Storable.! i) <&> \a -> v Storable.// [(i, a)]
216 361
     | otherwise                       = pure v
217 362
   {-# INLINE ix #-}
218 363
 
219  
-type instance IxKey IntSet = Int
220  
-type instance IxValue IntSet = Bool
  364
+{-
  365
+type instance Value IntSet = Bool
221 366
 instance Functor f => Ixed f IntSet where
222 367
   ix k f s = indexed f k (IntSet.member k s) <&> \b ->
223 368
     if b then IntSet.insert k s else IntSet.delete k s
224 369
   {-# INLINE ix #-}
225 370
 
226  
-type instance IxKey (Set a) = a
227  
-type instance IxValue (Set a) = Bool
  371
+type instance Value (Set a) = Bool
228 372
 instance (Functor f, Ord a) => Ixed f (Set a) where
229 373
   ix k f s = indexed f k (Set.member k s) <&> \b ->
230 374
     if b then Set.insert k s else Set.delete k s
231 375
   {-# INLINE ix #-}
232 376
 
233  
-type instance IxKey (HashSet a) = a
234  
-type instance IxValue (HashSet a) = Bool
  377
+type instance Value (HashSet a) = Bool
235 378
 instance (Functor f, Eq a, Hashable a) => Ixed f (HashSet a) where
236 379
   ix k f s = indexed f k (HashSet.member k s) <&> \b ->
237 380
     if b then HashSet.insert k s else HashSet.delete k s
238 381
   {-# INLINE ix #-}
  382
+-}
239 383
 
240  
-type instance IxKey (k -> a) = k
241  
-type instance IxValue (k -> a) = a
  384
+type instance Value (k -> a) = a
242 385
 instance (Functor f, Eq k) => Ixed f (k -> a) where
243 386
   ix e g f = indexed g e (f e) <&> \a' e' -> if e == e' then a' else f e'
244 387
   {-# INLINE ix #-}
245 388
 
246  
-type instance IxKey (a,a) = Int
247  
-type instance IxValue (a,a) = a
  389
+type instance Value (a,a) = a
248 390
 instance (Applicative f, a ~ b) => Ixed f (a,b) where
249 391
   ix = ixEach
250 392
   {-# INLINE ix #-}
251 393
 
252  
-type instance IxKey (a,a,a) = Int
253  
-type instance IxValue (a,a,a) = a
  394
+type instance Value (a,a,a) = a
254 395
 instance (Applicative f, a ~ b, b ~ c) => Ixed f (a,b,c) where
255 396
   ix = ixEach
256 397
   {-# INLINE ix #-}
257 398
 
258  
-type instance IxKey (a,a,a,a) = Int
259  
-type instance IxValue (a,a,a,a) = a
  399
+type instance Value (a,a,a,a) = a
260 400
 instance (Applicative f, a ~ b, b ~ c, c ~ d) => Ixed f (a,b,c,d) where
261 401
   ix = ixEach
262 402
   {-# INLINE ix #-}
263 403
 
264  
-type instance IxKey (a,a,a,a,a) = Int
265  
-type instance IxValue (a,a,a,a,a) = a
  404
+type instance Value (a,a,a,a,a) = a
266 405
 instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e) => Ixed f (a,b,c,d,e) where
267 406
   ix = ixEach
268 407
   {-# INLINE ix #-}
269 408
 
270  
-type instance IxKey (a,a,a,a,a,a) = Int
271  
-type instance IxValue (a,a,a,a,a,a) = a
  409
+type instance Value (a,a,a,a,a,a) = a
272 410
 instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f') => Ixed f (a,b,c,d,e,f') where
273 411
   ix = ixEach
274 412
   {-# INLINE ix #-}
275 413
 
276  
-type instance IxKey (a,a,a,a,a,a,a) = Int
277  
-type instance IxValue (a,a,a,a,a,a,a) = a
  414
+type instance Value (a,a,a,a,a,a,a) = a
278 415
 instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f', f' ~ g) => Ixed f (a,b,c,d,e,f',g) where
279 416
   ix = ixEach
280 417
   {-# INLINE ix #-}
281 418
 
282  
-type instance IxKey (a,a,a,a,a,a,a,a) = Int
283  
-type instance IxValue (a,a,a,a,a,a,a,a) = a
  419
+type instance Value (a,a,a,a,a,a,a,a) = a
284 420
 instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f', f' ~ g, g ~ h) => Ixed f (a,b,c,d,e,f',g,h) where
285 421
   ix = ixEach
286 422
   {-# INLINE ix #-}
287 423
 
288  
-type instance IxKey (a,a,a,a,a,a,a,a,a) = Int
289  
-type instance IxValue (a,a,a,a,a,a,a,a,a) = a
  424
+type instance Value (a,a,a,a,a,a,a,a,a) = a
290 425
 instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f', f' ~ g, g ~ h, h ~ i) => Ixed f (a,b,c,d,e,f',g,h,i) where
291 426
   ix = ixEach
292 427
   {-# INLINE ix #-}
@@ -308,7 +443,7 @@ class At m where
308 443
   --
309 444
   -- /Note:/ 'Map'-like containers form a reasonable instance, but not 'Array'-like ones, where
310 445
   -- you cannot satisfy the 'Lens' laws.
311  
-  at :: IxKey m -> IndexedLens' (IxKey m) m (Maybe (IxValue m))
  446
+  at :: Key m -> IndexedLens' (Key m) m (Maybe (Value m))
312 447
 
313 448
 instance At (IntMap a) where
314 449
   at k f m = indexed f k mv <&> \r -> case r of
26  src/Control/Lens/TH.hs
@@ -98,49 +98,49 @@ data LensFlag
98 98
 
99 99
 -- | Only Generate valid 'Control.Lens.Type.Simple' lenses.
100 100
 simpleLenses      :: Lens' LensRules Bool
101  
-simpleLenses       = lensFlags.ix SimpleLenses
  101
+simpleLenses       = lensFlags.contains SimpleLenses
102 102
 
103 103
 -- | Enables the generation of partial lenses, generating runtime errors for
104 104
 -- every constructor that does not have a valid definition for the 'Lens'. This
105 105
 -- occurs when the constructor lacks the field, or has multiple fields mapped
106 106
 -- to the same 'Lens'.
107 107
 partialLenses     :: Lens' LensRules Bool
108  
-partialLenses      = lensFlags.ix PartialLenses
  108
+partialLenses      = lensFlags.contains PartialLenses
109 109
 
110 110
 -- | In the situations that a 'Lens' would be partial, when 'partialLenses' is
111 111
 -- used, this flag instead causes traversals to be generated. Only one can be
112 112
 -- used, and if neither are, then compile-time errors are generated.
113 113
 buildTraversals   :: Lens' LensRules Bool
114  
-buildTraversals    = lensFlags.ix BuildTraversals
  114
+buildTraversals    = lensFlags.contains BuildTraversals
115 115
 
116 116
 -- | Handle singleton constructors specially.
117 117
 handleSingletons  :: Lens' LensRules Bool
118  
-handleSingletons   = lensFlags.ix HandleSingletons
  118
+handleSingletons   = lensFlags.contains HandleSingletons
119 119
 
120 120
 -- | When building a singleton 'Iso' (or 'Lens') for a record constructor, build
121 121
 -- both the 'Iso' (or 'Lens') for the record and the one for the field.
122 122
 singletonAndField :: Lens' LensRules Bool
123  
-singletonAndField  = lensFlags.ix SingletonAndField
  123
+singletonAndField  = lensFlags.contains SingletonAndField
124 124
 
125 125
 -- | Use 'Iso' for singleton constructors.
126 126
 singletonIso      :: Lens' LensRules Bool
127  
-singletonIso       = lensFlags.ix SingletonIso
  127
+singletonIso       = lensFlags.contains SingletonIso
128 128
 
129 129
 -- | Expect a single constructor, single field newtype or data type.
130 130
 singletonRequired :: Lens' LensRules Bool
131  
-singletonRequired  = lensFlags.ix SingletonRequired
  131
+singletonRequired  = lensFlags.contains SingletonRequired
132 132
 
133 133
 -- | Create the class if the constructor is 'Control.Lens.Type.Simple' and the 'lensClass' rule matches.
134 134
 createClass       :: Lens' LensRules Bool
135  
-createClass        = lensFlags.ix CreateClass
  135
+createClass        = lensFlags.contains CreateClass
136 136
 
137 137
 -- | Create the instance if the constructor is 'Control.Lens.Type.Simple' and the 'lensClass' rule matches.
138 138
 createInstance    :: Lens' LensRules Bool
139  
-createInstance     = lensFlags.ix CreateInstance
  139
+createInstance     = lensFlags.contains CreateInstance
140 140
 
141 141
 -- | Die if the 'lensClass' fails to match.
142 142
 classRequired     :: Lens' LensRules Bool
143  
-classRequired      = lensFlags.ix ClassRequired
  143
+classRequired      = lensFlags.contains ClassRequired
144 144
 
145 145
 -- | Indicate whether or not to supply the signatures for the generated
146 146
 -- lenses.
@@ -148,7 +148,7 @@ classRequired      = lensFlags.ix ClassRequired
148 148
 -- Disabling this can be useful if you want to provide a more restricted type
149 149
 -- signature or if you want to supply hand-written haddocks.
150 150
 generateSignatures :: Lens' LensRules Bool
151  
-generateSignatures = lensFlags.ix GenerateSignatures
  151
+generateSignatures = lensFlags.contains GenerateSignatures
152 152
 
153 153
 -- | This configuration describes the options we'll be using to make
154 154
 -- isomorphisms or lenses.
@@ -390,7 +390,7 @@ makePrismForCon ctx tyConName args canModifyTypeVar allCons con = do
390 390
   where
391 391
     (dataConName, fieldTypes) = ctrNameAndFieldTypes con
392 392
     conArgs = setOf typeVars fieldTypes
393  
-    isAltArg arg = canModifyTypeVar arg && conArgs^.ix(arg^.name)
  393
+    isAltArg arg = canModifyTypeVar arg && conArgs^.contains(arg^.name)
394 394
 
395 395
 ctrNameAndFieldTypes :: Con -> (Name, [Type])
396 396
 ctrNameAndFieldTypes (NormalC n ts) = (n, snd <$> ts)
@@ -591,7 +591,7 @@ makeFieldLenses cfg ctx tyConName tyArgs0 cons = do
591 591
         dty = substTypeVars m cty
592 592
 
593 593
         s = setOf folded m
594  
-        relevantBndr b = s^.ix (b^.name)
  594
+        relevantBndr b = s^.contains (b^.name)
595 595
         relevantCtx = not . Set.null . Set.intersection s . setOf typeVars
596 596
         tvs = tyArgs' ++ filter relevantBndr (substTypeVars m tyArgs')
597 597
         ps = filter relevantCtx (substTypeVars m ctx)
4  src/Language/Haskell/TH/Lens.hs
@@ -67,12 +67,12 @@ class HasTypeVars t where
67 67
 
68 68
 instance HasTypeVars TyVarBndr where
69 69
   typeVarsEx s f b
70  
-    | s^.ix (b^.name) = pure b
  70
+    | s^.contains (b^.name) = pure b
71 71
     | otherwise             = name f b
72 72
 
73 73
 instance HasTypeVars Name where
74 74
   typeVarsEx s f n
75  
-    | s^.ix n = pure n
  75
+    | s^.contains n = pure n
76 76
     | otherwise     = f n
77 77
 
78 78
 instance HasTypeVars Type where

0 notes on commit 32697f3

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