packages feed

indexed-traversable 0.1.2 → 0.1.2.1

raw patch · 8 files changed

+82/−45 lines, 8 filesdep ~basedep ~base-orphansPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, base-orphans

API changes (from Hackage documentation)

Files

Changelog.md view
@@ -1,3 +1,8 @@+# 0.1.2.1 [2022-12-28]++- TraversableWithIndex [] doesn't use `zip [0..]` idiom anymore.+  https://gitlab.haskell.org/ghc/ghc/-/issues/22673+ # 0.1.2 [2021-10-30]  - Changed `(<$>)` + `(<*>)` to `liftA2` to potentially avoid extra `fmap`.
indexed-traversable.cabal view
@@ -1,6 +1,6 @@ cabal-version:      1.12 name:               indexed-traversable-version:            0.1.2+version:            0.1.2.1 build-type:         Simple license:            BSD2 license-file:       LICENSE@@ -46,8 +46,10 @@    || ==8.6.5    || ==8.8.4    || ==8.10.7-   || ==9.0.1-   || ==9.2.1+   || ==9.0.2+   || ==9.2.7+   || ==9.4.4+   || ==9.6.1  source-repository head   type:     git@@ -59,7 +61,8 @@   ghc-options:      -Wall   hs-source-dirs:   src   other-modules:-    GhcExts+    CoerceCompat+    GhcList     WithIndex    exposed-modules:@@ -69,7 +72,7 @@    build-depends:       array         >=0.3.0.2 && <0.6-    , base          >=4.3     && <4.17+    , base          >=4.3     && <4.19     , containers    >=0.4.0.0 && <0.7     , transformers  >=0.3.0.0 && <0.7 @@ -81,8 +84,8 @@    if !impl(ghc >=8.0)     build-depends:-        base-orphans         >=0.8.3  && <0.9-      , semigroups           >=0.18.4 && <0.20+        base-orphans         >=0.8.3  && <0.10+      , semigroups           >=0.18.4 && <0.21       , transformers-compat  >=0.6.6  && <0.8    if (impl(ghc >=7.0) && impl(ghc <7.6))
+ src/CoerceCompat.hs view
@@ -0,0 +1,29 @@+{-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >= 702+{-# LANGUAGE Trustworthy #-}+#endif+module CoerceCompat where++#if __GLASGOW_HASKELL__ >=708+import Data.Coerce (Coercible, coerce)+#else+import Unsafe.Coerce (unsafeCoerce)+#endif+++#if __GLASGOW_HASKELL__ >=708+(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a -> c)+_ #. x = coerce x++(#..) :: Coercible b c => (b -> c) -> (i -> a -> b) -> (i -> a -> c)+_ #.. x = coerce x+#else+(#.) :: (b -> c) -> (a -> b) -> (a -> c)+_ #. x = unsafeCoerce x++(#..) :: (b -> c) -> (i -> a -> b) -> (i -> a -> c)+_ #.. x = unsafeCoerce x+#endif+infixr 9 #., #..+{-# INLINE (#.) #-}+{-# INLINE (#..) #-}
src/Data/Foldable/WithIndex.hs view
@@ -31,7 +31,9 @@ import Data.Foldable       (Foldable, any) import Data.Monoid         (All (..), Any (..)) -import GhcExts (build)+import CoerceCompat ((#.), (#..))+import GhcList      (build)+ import WithIndex  -- | Return whether or not any element in a container satisfies a predicate, with access to the index @i@.
src/Data/Traversable/WithIndex.hs view
@@ -28,6 +28,7 @@ import qualified Control.Monad.Trans.State.Lazy as Lazy  import WithIndex+import CoerceCompat  -- | Traverse with an index (and the arguments flipped). --
− src/GhcExts.hs
@@ -1,9 +0,0 @@-{-# LANGUAGE CPP         #-}-#if __GLASGOW_HASKELL__ >= 702-{-# LANGUAGE Trustworthy #-}-#endif-module GhcExts (-    build,-) where--import GHC.Exts (build)
+ src/GhcList.hs view
@@ -0,0 +1,15 @@+{-# LANGUAGE CPP         #-}+#if MIN_VERSION_base(4,17,0)+{-# LANGUAGE Safe #-}+#elif __GLASGOW_HASKELL__ >= 702+{-# LANGUAGE Trustworthy #-}+#endif+module GhcList (+    build,+) where++#if MIN_VERSION_base(4,17,0)+import GHC.List (build)+#else+import GHC.Exts (build)+#endif
src/WithIndex.hs view
@@ -7,8 +7,14 @@ {-# LANGUAGE TypeOperators          #-} {-# LANGUAGE UndecidableInstances   #-} +{-# LANGUAGE CPP         #-}+#if __GLASGOW_HASKELL__ >= 704+{-# LANGUAGE Safe        #-}+#elif __GLASGOW_HASKELL__ >= 702+{-# LANGUAGE Trustworthy #-}+#endif+ #if __GLASGOW_HASKELL__ >= 702-{-# LANGUAGE Trustworthy            #-} {-# LANGUAGE DefaultSignatures      #-} #endif @@ -19,7 +25,7 @@  import Prelude        (Either (..), Functor (..), Int, Maybe (..), Monad (..), Num (..), error,-       flip, id, seq, snd, ($!), ($), (.), zip)+       flip, id, seq, snd, ($!), ($), (.))  import Control.Applicative        (Applicative (..), Const (..), ZipList (..), (<$>), liftA2)@@ -65,11 +71,7 @@ import Data.Orphans () #endif -#if __GLASGOW_HASKELL__ >=708-import Data.Coerce (Coercible, coerce)-#else-import Unsafe.Coerce (unsafeCoerce)-#endif+import CoerceCompat  ------------------------------------------------------------------------------- -- FunctorWithIndex@@ -263,9 +265,15 @@     go !n (x:xs) = f n x (go (n + 1) xs)   {-# INLINE ifoldr #-} instance TraversableWithIndex Int [] where-  itraverse f = traverse (uncurry' f) . zip [0..]+  itraverse = itraverseListOff 0   {-# INLINE itraverse #-} +-- traverse (uncurry' f) . zip [0..] seems to not work well:+-- https://gitlab.haskell.org/ghc/ghc/-/issues/22673+itraverseListOff :: Applicative f => Int -> (Int -> a -> f b) -> [a] -> f [b]+itraverseListOff !_   _ []     = pure []+itraverseListOff !off f (x:xs) = liftA2 (:) (f off x) (itraverseListOff (off + 1) f xs)+ -- TODO: we could experiment with streaming framework -- imapListFB f xs = build (\c n -> ifoldr (\i a -> c (f i a)) n xs) @@ -292,7 +300,7 @@   {-# INLINE ifoldMap #-} instance TraversableWithIndex Int NonEmpty where   itraverse f ~(a :| as) =-    liftA2 (:|) (f 0 a) (traverse (uncurry' f) (zip [1..] as))+    liftA2 (:|) (f 0 a) (itraverseListOff 1 f as)   {-# INLINE itraverse #-}  -------------------------------------------------------------------------------@@ -632,23 +640,6 @@ -- Misc. ------------------------------------------------------------------------------- -#if __GLASGOW_HASKELL__ >=708-(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a -> c)-_ #. x = coerce x--(#..) :: Coercible b c => (b -> c) -> (i -> a -> b) -> (i -> a -> c)-_ #.. x = coerce x-#else-(#.) :: (b -> c) -> (a -> b) -> (a -> c)-_ #. x = unsafeCoerce x--(#..) :: (b -> c) -> (i -> a -> b) -> (i -> a -> c)-_ #.. x = unsafeCoerce x-#endif-infixr 9 #., #..-{-# INLINE (#.) #-}-{-# INLINE (#..)#-}- skip :: a -> () skip _ = () {-# INLINE skip #-}@@ -670,7 +661,7 @@ instance Applicative f => Monoid (Traversed a f) where   mempty = Traversed (pure (error "Traversed: value used"))   {-# INLINE mempty #-}-  Traversed ma `mappend` Traversed mb = Traversed (ma *> mb)+  mappend = (<>)   {-# INLINE mappend #-}  ------------------------------------------------------------------------------@@ -691,7 +682,7 @@ instance Monad m => Monoid (Sequenced a m) where   mempty = Sequenced (return (error "Sequenced: value used"))   {-# INLINE mempty #-}-  Sequenced ma `mappend` Sequenced mb = Sequenced (ma >> mb)+  mappend = (<>)   {-# INLINE mappend #-}  ------------------------------------------------------------------------------