From 1ca259ecf59379e602cd7ea61a58909b7bda9874 Mon Sep 17 00:00:00 2001 From: Aleksey Khudyakov Date: Mon, 18 Mar 2024 21:21:46 +0300 Subject: [PATCH] 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. --- vector/src/Data/Vector/Generic/Base.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vector/src/Data/Vector/Generic/Base.hs b/vector/src/Data/Vector/Generic/Base.hs index afb78782..e1055f81 100644 --- a/vector/src/Data/Vector/Generic/Base.hs +++ b/vector/src/Data/Vector/Generic/Base.hs @@ -28,6 +28,9 @@ module Data.Vector.Generic.Base ( import Data.Vector.Generic.Mutable.Base ( MVector ) import qualified Data.Vector.Generic.Mutable.Base as M import Data.Vector.Fusion.Util (Box(..), liftBox) +import qualified Data.Primitive.Array as Prim +import qualified Data.Primitive.SmallArray as Prim +import qualified Data.Primitive.PrimArray as Prim import Control.Monad.ST import Data.Kind (Type) @@ -36,6 +39,11 @@ import Data.Kind (Type) -- the state token @s@. It is injective on GHC 8 and newer. type family Mutable (v :: Type -> Type) = (mv :: Type -> Type -> Type) | mv -> v +type instance Mutable Prim.Array = Prim.MutableArray +type instance Mutable Prim.SmallArray = Prim.SmallMutableArray +type instance Mutable Prim.PrimArray = Prim.MutablePrimArray + + -- | Class of immutable vectors. Every immutable vector is associated with its -- mutable version through the 'Mutable' type family. Methods of this class -- should not be used directly. Instead, "Data.Vector.Generic" and other