@@ -21,8 +21,9 @@ module Data.Mutable.Class
21
21
, MutableRef (.. )
22
22
, MutableAtomicRef (.. )
23
23
, MutableCollection (.. )
24
- , MutableInitialSizedCollection (.. )
25
- , MutableIndexing (.. )
24
+ , MutableAllocatedCollection (.. )
25
+ , CollIndex
26
+ , MutableIndexingWrite (.. )
26
27
, MutablePushFront (.. )
27
28
, MutablePushBack (.. )
28
29
, MutablePopFront (.. )
@@ -229,90 +230,85 @@ instance Monoid w => MutableCollection (MutVar s w) where
229
230
instance MutableCollection (MV. MVector s a ) where
230
231
type CollElement (MV. MVector s a ) = a
231
232
newColl = MV. new 0
232
- {-# INLINE newColl #-}
233
233
instance MPV. Prim a => MutableCollection (MPV. MVector s a ) where
234
234
type CollElement (MPV. MVector s a ) = a
235
235
newColl = MPV. new 0
236
- {-# INLINE newColl #-}
237
236
instance Storable a => MutableCollection (MSV. MVector s a ) where
238
237
type CollElement (MSV. MVector s a ) = a
239
238
newColl = MSV. new 0
240
- {-# INLINE newColl #-}
241
239
instance MUV. Unbox a => MutableCollection (MUV. MVector s a ) where
242
240
type CollElement (MUV. MVector s a ) = a
243
241
newColl = MUV. new 0
244
- {-# INLINE newColl #-}
245
242
instance (GHC.Arr. Ix i , Num i ) => MutableCollection (GHC.Arr. STArray s i e ) where
246
243
type CollElement (GHC.Arr. STArray s i e ) = e
247
244
newColl = primToPrim $ GHC.Arr. newSTArray (0 ,0 ) undefined
248
- {-# INLINE newColl #-}
249
245
instance Storable a => MutableCollection (Ptr a ) where
250
246
type CollElement (Ptr a ) = a
251
247
newColl = primToPrim $ Foreign. mallocArray 0
252
- {-# INLINE newColl #-}
253
248
254
249
-- | Containers that can be initialized with n elements.
255
- class MutableCollection c => MutableInitialSizedCollection c where
256
- type CollIndex c
250
+ type family CollIndex c
251
+
252
+ class MutableCollection c => MutableAllocatedCollection c where
257
253
newCollOfSize :: (PrimMonad m , PrimState m ~ MCState c )
258
254
=> CollIndex c
259
255
-> m c
260
- instance MutableInitialSizedCollection (MV. MVector s a ) where
261
- type CollIndex (MV. MVector s a ) = Int
256
+ type instance CollIndex (MV. MVector s a ) = Int
257
+ instance MutableAllocatedCollection (MV. MVector s a ) where
262
258
newCollOfSize = MV. new
263
259
{-# INLINE newCollOfSize #-}
264
- instance MPV. Prim a => MutableInitialSizedCollection (MPV. MVector s a ) where
265
- type CollIndex (MPV. MVector s a ) = Int
260
+ type instance CollIndex (MPV. MVector s a ) = Int
261
+ instance MPV. Prim a => MutableAllocatedCollection (MPV. MVector s a ) where
266
262
newCollOfSize = MPV. new
267
263
{-# INLINE newCollOfSize #-}
268
- instance Storable a => MutableInitialSizedCollection (MSV. MVector s a ) where
269
- type CollIndex (MSV. MVector s a ) = Int
264
+ type instance CollIndex (MSV. MVector s a ) = Int
265
+ instance Storable a => MutableAllocatedCollection (MSV. MVector s a ) where
270
266
newCollOfSize = MSV. new
271
267
{-# INLINE newCollOfSize #-}
272
- instance MUV. Unbox a => MutableInitialSizedCollection (MUV. MVector s a ) where
273
- type CollIndex (MUV. MVector s a ) = Int
268
+ type instance CollIndex (MUV. MVector s a ) = Int
269
+ instance MUV. Unbox a => MutableAllocatedCollection (MUV. MVector s a ) where
274
270
newCollOfSize = MUV. new
275
271
{-# INLINE newCollOfSize #-}
276
- instance ( GHC.Arr. Ix i , Num i ) => MutableInitialSizedCollection (GHC.Arr. STArray s i e ) where
277
- type CollIndex (GHC.Arr. STArray s i e ) = i
272
+ type instance CollIndex (GHC.Arr. STArray s i e ) = i
273
+ instance ( GHC.Arr. Ix i , Num i ) => MutableAllocatedCollection (GHC.Arr. STArray s i e ) where
278
274
newCollOfSize x = primToPrim $ GHC.Arr. newSTArray (0 ,x) undefined
279
275
{-# INLINE newCollOfSize #-}
280
- instance Storable a => MutableInitialSizedCollection (Ptr a ) where
281
- type CollIndex (Ptr a ) = Int
276
+ type instance CollIndex (Ptr a ) = Int
277
+ instance Storable a => MutableAllocatedCollection (Ptr a ) where
282
278
newCollOfSize = primToPrim . Foreign. mallocArray
283
279
{-# INLINE newCollOfSize #-}
284
280
285
- class MutableInitialSizedCollection c => MutableIndexing c where
286
- readIndex :: (PrimMonad m , PrimState m ~ MCState c ) => c -> CollIndex c -> m (CollElement c )
281
+ class MutableAllocatedCollection c => MutableIndexingWrite c where
282
+ -- readIndex :: (PrimMonad m, PrimState m ~ MCState c) => c -> CollIndex c -> m (CollElement c)
287
283
writeIndex :: (PrimMonad m , PrimState m ~ MCState c ) => c -> CollIndex c -> CollElement c -> m ()
288
- instance MutableIndexing (MV. MVector s a ) where
289
- readIndex = MV. read
290
- {-# INLINE readIndex #-}
284
+ instance MutableIndexingWrite (MV. MVector s a ) where
285
+ -- readIndex = MV.read
286
+ -- {-# INLINE readIndex #-}
291
287
writeIndex = MV. write
292
288
{-# INLINE writeIndex #-}
293
- instance MPV. Prim a => MutableIndexing (MPV. MVector s a ) where
294
- readIndex = MPV. read
295
- {-# INLINE readIndex #-}
289
+ instance MPV. Prim a => MutableIndexingWrite (MPV. MVector s a ) where
290
+ -- readIndex = MPV.read
291
+ -- {-# INLINE readIndex #-}
296
292
writeIndex = MPV. write
297
293
{-# INLINE writeIndex #-}
298
- instance Storable a => MutableIndexing (MSV. MVector s a ) where
299
- readIndex = MSV. read
300
- {-# INLINE readIndex #-}
294
+ instance Storable a => MutableIndexingWrite (MSV. MVector s a ) where
295
+ -- readIndex = MSV.read
296
+ -- {-# INLINE readIndex #-}
301
297
writeIndex = MSV. write
302
298
{-# INLINE writeIndex #-}
303
- instance MUV. Unbox a => MutableIndexing (MUV. MVector s a ) where
304
- readIndex = MUV. read
305
- {-# INLINE readIndex #-}
299
+ instance MUV. Unbox a => MutableIndexingWrite (MUV. MVector s a ) where
300
+ -- readIndex = MUV.read
301
+ -- {-# INLINE readIndex #-}
306
302
writeIndex = MUV. write
307
303
{-# INLINE writeIndex #-}
308
- instance (GHC.Arr. Ix i , Num i ) => MutableIndexing (GHC.Arr. STArray s i e ) where
309
- readIndex c i = primToPrim $ GHC.Arr. readSTArray c i
310
- {-# INLINE readIndex #-}
304
+ instance (GHC.Arr. Ix i , Num i ) => MutableIndexingWrite (GHC.Arr. STArray s i e ) where
305
+ -- readIndex c i = primToPrim $ GHC.Arr.readSTArray c i
306
+ -- {-# INLINE readIndex #-}
311
307
writeIndex c i e = primToPrim $ GHC.Arr. writeSTArray c i e
312
308
{-# INLINE writeIndex #-}
313
- instance Storable a => MutableIndexing (Ptr a ) where
314
- readIndex p i = primToPrim $ Foreign. peekElemOff p i
315
- {-# INLINE readIndex #-}
309
+ instance Storable a => MutableIndexingWrite (Ptr a ) where
310
+ -- readIndex p i = primToPrim $ Foreign.peekElemOff p i
311
+ -- {-# INLINE readIndex #-}
316
312
writeIndex p i e = primToPrim $ Foreign. pokeElemOff p i e
317
313
{-# INLINE writeIndex #-}
318
314
0 commit comments