Skip to content

Commit 1ca259e

Browse files
authored
Add instances for Mutable t.f. for arrays from primitive (#473)
While arrays from primitive could not have `Vector`/`MVector` instances, `Mutable` is well defined for them. It's useful on its own and could be used with another pair of type classes.
1 parent 7e7c90d commit 1ca259e

File tree

1 file changed

+8
-0
lines changed
  • vector/src/Data/Vector/Generic

1 file changed

+8
-0
lines changed

vector/src/Data/Vector/Generic/Base.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ module Data.Vector.Generic.Base (
2828
import Data.Vector.Generic.Mutable.Base ( MVector )
2929
import qualified Data.Vector.Generic.Mutable.Base as M
3030
import Data.Vector.Fusion.Util (Box(..), liftBox)
31+
import qualified Data.Primitive.Array as Prim
32+
import qualified Data.Primitive.SmallArray as Prim
33+
import qualified Data.Primitive.PrimArray as Prim
3134

3235
import Control.Monad.ST
3336
import Data.Kind (Type)
@@ -36,6 +39,11 @@ import Data.Kind (Type)
3639
-- the state token @s@. It is injective on GHC 8 and newer.
3740
type family Mutable (v :: Type -> Type) = (mv :: Type -> Type -> Type) | mv -> v
3841

42+
type instance Mutable Prim.Array = Prim.MutableArray
43+
type instance Mutable Prim.SmallArray = Prim.SmallMutableArray
44+
type instance Mutable Prim.PrimArray = Prim.MutablePrimArray
45+
46+
3947
-- | Class of immutable vectors. Every immutable vector is associated with its
4048
-- mutable version through the 'Mutable' type family. Methods of this class
4149
-- should not be used directly. Instead, "Data.Vector.Generic" and other

0 commit comments

Comments
 (0)