Skip to content

Commit

Permalink
Add instances for Mutable t.f. for arrays from primitive (#473)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Shimuuar committed Mar 18, 2024
1 parent 7e7c90d commit 1ca259e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vector/src/Data/Vector/Generic/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 1ca259e

Please sign in to comment.