From 286da921c602c21c4dec549b94e2cb22401f6e92 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Sat, 14 Dec 2024 14:14:30 +0300 Subject: [PATCH 1/3] Deprecate sequenceA --- fixed-vector/ChangeLog.md | 3 +++ fixed-vector/Data/Vector/Fixed.hs | 7 ++++--- fixed-vector/Data/Vector/Fixed/Boxed.hs | 2 +- fixed-vector/Data/Vector/Fixed/Internal.hs | 3 ++- fixed-vector/Data/Vector/Fixed/Strict.hs | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/fixed-vector/ChangeLog.md b/fixed-vector/ChangeLog.md index 9d050d3..3fb9688 100644 --- a/fixed-vector/ChangeLog.md +++ b/fixed-vector/ChangeLog.md @@ -23,6 +23,9 @@ Changes in 1.3.0.0 * `Data.Vector.Fixed.Storable.unsafeWith` ensures that pointer won't get GC'd while function runs + * `Data.Vector.Fixed.sequenceA` is deprecated in favor of `sequence` + + Changes in 1.2.3.0 * Pattern `V1` added diff --git a/fixed-vector/Data/Vector/Fixed.hs b/fixed-vector/Data/Vector/Fixed.hs index d4fd062..803ee38 100644 --- a/fixed-vector/Data/Vector/Fixed.hs +++ b/fixed-vector/Data/Vector/Fixed.hs @@ -117,7 +117,6 @@ module Data.Vector.Fixed ( , scanl1 , sequence , sequence_ - , sequenceA , traverse , distribute , collect @@ -184,6 +183,8 @@ module Data.Vector.Fixed ( , defaultPoke -- ** NFData , defaultRnf + -- * Deprecated functions + , sequenceA ) where import Control.Applicative (Applicative(..)) @@ -284,7 +285,7 @@ deriving via ViaFixed (VecList n) instance (Arity n) => Applicative (VecList n) deriving via ViaFixed (VecList n) instance (Arity n) => F.Foldable (VecList n) instance Arity n => T.Traversable (VecList n) where - sequenceA = sequenceA + sequenceA = sequence traverse = traverse deriving via ViaFixed (VecList n) a instance (Arity n, Show a) => Show (VecList n a) @@ -302,7 +303,7 @@ deriving via ViaFixed (VecPeano n) instance (ArityPeano n) => Applicative (VecPe deriving via ViaFixed (VecPeano n) instance (ArityPeano n) => F.Foldable (VecPeano n) instance ArityPeano n => T.Traversable (VecPeano n) where - sequenceA = sequenceA + sequenceA = sequence traverse = traverse deriving via ViaFixed (VecPeano n) a instance (ArityPeano n, Show a) => Show (VecPeano n a) diff --git a/fixed-vector/Data/Vector/Fixed/Boxed.hs b/fixed-vector/Data/Vector/Fixed/Boxed.hs index 2b266ab..f255aa7 100644 --- a/fixed-vector/Data/Vector/Fixed/Boxed.hs +++ b/fixed-vector/Data/Vector/Fixed/Boxed.hs @@ -66,7 +66,7 @@ deriving via ViaFixed (Vec n) instance Arity n => Applicative (Vec n) deriving via ViaFixed (Vec n) instance Arity n => F.Foldable (Vec n) instance Arity n => T.Traversable (Vec n) where - sequenceA = sequenceA + sequenceA = sequence traverse = traverse {-# INLINE sequenceA #-} {-# INLINE traverse #-} diff --git a/fixed-vector/Data/Vector/Fixed/Internal.hs b/fixed-vector/Data/Vector/Fixed/Internal.hs index adfb517..8f6f4cf 100644 --- a/fixed-vector/Data/Vector/Fixed/Internal.hs +++ b/fixed-vector/Data/Vector/Fixed/Internal.hs @@ -494,7 +494,8 @@ scanl1 f = vector . C.scanl1 f . C.cvec sequenceA :: (Vector v a, Vector v (f a), Applicative f) => v (f a) -> f (v a) {-# INLINE sequenceA #-} -sequenceA = fmap vector . T.sequenceA . C.cvec +sequenceA = sequence +{-# DEPRECATED sequenceA "Use sequence instead" #-} -- | Analog of 'T.traverse' from 'T.Traversable'. traverse :: (Vector v a, Vector v b, Applicative f) diff --git a/fixed-vector/Data/Vector/Fixed/Strict.hs b/fixed-vector/Data/Vector/Fixed/Strict.hs index 79d7e0c..17bf64f 100644 --- a/fixed-vector/Data/Vector/Fixed/Strict.hs +++ b/fixed-vector/Data/Vector/Fixed/Strict.hs @@ -56,7 +56,7 @@ deriving via ViaFixed (Vec n) instance Arity n => Applicative (Vec n) deriving via ViaFixed (Vec n) instance Arity n => F.Foldable (Vec n) instance Arity n => T.Traversable (Vec n) where - sequenceA = sequenceA + sequenceA = sequence traverse = traverse {-# INLINE sequenceA #-} {-# INLINE traverse #-} From 2c30c161a13520977cc99aadacd75665e6f8b3f6 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Sat, 14 Dec 2024 14:22:17 +0300 Subject: [PATCH 2/3] Define all methods of Traversable for ContVec --- fixed-vector/Data/Vector/Fixed/Cont.hs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/fixed-vector/Data/Vector/Fixed/Cont.hs b/fixed-vector/Data/Vector/Fixed/Cont.hs index 15366aa..99e9542 100644 --- a/fixed-vector/Data/Vector/Fixed/Cont.hs +++ b/fixed-vector/Data/Vector/Fixed/Cont.hs @@ -129,6 +129,7 @@ import GHC.Exts (Proxy#, proxy#) import Prelude hiding ( replicate,map,zipWith,zipWith3,maximum,minimum,and,or,any,all , foldl,foldr,foldl1,length,sum,reverse,scanl,scanl1 , head,tail,mapM,mapM_,sequence,sequence_,concat + , Foldable(..), Traversable(..) ) @@ -508,18 +509,14 @@ instance (ArityPeano n) => F.Foldable (ContVec n) where {-# INLINE foldr #-} instance (ArityPeano n) => F.Traversable (ContVec n) where - sequenceA v = inspect v $ sequenceAF construct + sequence = sequence + sequenceA = sequence + traverse = mapM + mapM = mapM + {-# INLINE sequence #-} {-# INLINE sequenceA #-} - -sequenceAF :: forall f n a b. (Applicative f, ArityPeano n) - => Fun n a b -> Fun n (f a) (f b) -{-# INLINE sequenceAF #-} -sequenceAF (Fun f0) - = accum (\(T_sequenceA f) a -> T_sequenceA (f <*> a)) - (\(T_sequenceA f) -> f) - (T_sequenceA (pure f0) :: T_sequenceA f a b n) - -newtype T_sequenceA f a b n = T_sequenceA (f (Fn n a b)) + {-# INLINE mapM #-} + {-# INLINE traverse #-} From a305a69af90e2db25dcfab2790c4e154196f822f Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Sat, 14 Dec 2024 14:24:42 +0300 Subject: [PATCH 3/3] Import prelude explicitly I almost got into problem by defining Taversable's traverse=traverse where traverse got from Prelude --- fixed-vector/Data/Vector/Fixed/Cont.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fixed-vector/Data/Vector/Fixed/Cont.hs b/fixed-vector/Data/Vector/Fixed/Cont.hs index 99e9542..ac6f4a6 100644 --- a/fixed-vector/Data/Vector/Fixed/Cont.hs +++ b/fixed-vector/Data/Vector/Fixed/Cont.hs @@ -126,10 +126,10 @@ import qualified Data.Traversable as F import Unsafe.Coerce (unsafeCoerce) import GHC.TypeLits import GHC.Exts (Proxy#, proxy#) -import Prelude hiding ( replicate,map,zipWith,zipWith3,maximum,minimum,and,or,any,all - , foldl,foldr,foldl1,length,sum,reverse,scanl,scanl1 - , head,tail,mapM,mapM_,sequence,sequence_,concat - , Foldable(..), Traversable(..) +import Prelude ( Bool(..), Int, Maybe(..), Either(..) + , Eq(..), Ord(..), Num(..), Functor(..), Applicative(..), Monad(..) + , Semigroup(..), Monoid(..) + , (.), ($), (&&), (||), (<$>), const, id, flip, error, otherwise, fst, maybe )