Skip to content

Commit

Permalink
Small cleanup enabled by vector-0.13 (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
amesgen authored Nov 15, 2023
2 parents e7617bf + 87bc914 commit 1b01fa9
Showing 1 changed file with 4 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

Expand Down Expand Up @@ -39,37 +41,10 @@ import qualified Test.QuickCheck as QC
newtype S = S Bool
deriving (QC.Arbitrary, Eq, Ord, Read, Show)

-- these instances adapted from
-- https://github.com/minoki/unboxing-vector/blob/3a152014b9660ef1e2885d6b9c66423064223f63/test/Foo.hs#L36-L63
--
-- vector 0.13 lets us derive the two big instances;
-- see the top of https://hackage.haskell.org/package/vector-0.13.0.0/docs/Data-Vector-Unboxed.html
--
-- TODO do so once we eventually bump our dependency on vector to include that feature
newtype instance MV.MVector s S = MV_S (MV.MVector s Bool)
newtype instance V.Vector S = V_S (V.Vector Bool)
instance MVG.MVector MV.MVector S where
basicLength (MV_S mv) = MVG.basicLength mv
basicUnsafeSlice i l (MV_S mv) = MV_S (MVG.basicUnsafeSlice i l mv)
basicOverlaps (MV_S mv) (MV_S mv') = MVG.basicOverlaps mv mv'
basicUnsafeNew l = MV_S <$> MVG.basicUnsafeNew l
basicInitialize (MV_S mv) = MVG.basicInitialize mv
basicUnsafeReplicate i x = MV_S <$> MVG.basicUnsafeReplicate i (coerce x)
basicUnsafeRead (MV_S mv) i = coerce <$> MVG.basicUnsafeRead mv i
basicUnsafeWrite (MV_S mv) i x = MVG.basicUnsafeWrite mv i (coerce x)
basicClear (MV_S mv) = MVG.basicClear mv
basicSet (MV_S mv) x = MVG.basicSet mv (coerce x)
basicUnsafeCopy (MV_S mv) (MV_S mv') = MVG.basicUnsafeCopy mv mv'
basicUnsafeMove (MV_S mv) (MV_S mv') = MVG.basicUnsafeMove mv mv'
basicUnsafeGrow (MV_S mv) n = MV_S <$> MVG.basicUnsafeGrow mv n
instance VG.Vector V.Vector S where
basicUnsafeFreeze (MV_S mv) = V_S <$> VG.basicUnsafeFreeze mv
basicUnsafeThaw (V_S v) = MV_S <$> VG.basicUnsafeThaw v
basicLength (V_S v) = VG.basicLength v
basicUnsafeSlice i l (V_S v) = V_S (VG.basicUnsafeSlice i l v)
basicUnsafeIndexM (V_S v) i = coerce <$> VG.basicUnsafeIndexM v i
basicUnsafeCopy (MV_S mv) (V_S v) = VG.basicUnsafeCopy mv v
elemseq (V_S v) x y = VG.elemseq v (coerce x) y
deriving newtype instance MVG.MVector MV.MVector S
deriving newtype instance VG.Vector V.Vector S
instance V.Unbox S

-----
Expand Down

0 comments on commit 1b01fa9

Please sign in to comment.