From 22c51eeb72cff60e854ba0bb1e6c074c8a766ffa Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Sat, 27 Jun 2020 15:43:59 +0300 Subject: [PATCH 1/2] Fix fusion of `<$` operator --- Data/Vector.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Data/Vector.hs b/Data/Vector.hs index feb0bebe..17b13dde 100644 --- a/Data/Vector.hs +++ b/Data/Vector.hs @@ -340,6 +340,9 @@ instance Functor Vector where {-# INLINE fmap #-} fmap = map + {-# INLINE (<$) #-} + (<$) = map . const + instance Monad Vector where {-# INLINE return #-} return = Applicative.pure From 06769697f32cd096071f39244d4950a1810405be Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Sat, 27 Jun 2020 19:08:00 +0300 Subject: [PATCH 2/2] Add custom `<$` implementation with INLINE pragma for `Bundle` and `Stream` as well as `Vector` --- Data/Vector/Fusion/Bundle/Monadic.hs | 2 ++ Data/Vector/Fusion/Stream/Monadic.hs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Data/Vector/Fusion/Bundle/Monadic.hs b/Data/Vector/Fusion/Bundle/Monadic.hs index fc0909a0..67d4e545 100644 --- a/Data/Vector/Fusion/Bundle/Monadic.hs +++ b/Data/Vector/Fusion/Bundle/Monadic.hs @@ -287,6 +287,8 @@ drop n Bundle{sElems = s, sSize = sz} = instance Monad m => Functor (Bundle m v) where {-# INLINE fmap #-} fmap = map + {-# INLINE (<$) #-} + (<$) = map . const -- | Map a function over a 'Bundle' map :: Monad m => (a -> b) -> Bundle m v a -> Bundle m v b diff --git a/Data/Vector/Fusion/Stream/Monadic.hs b/Data/Vector/Fusion/Stream/Monadic.hs index bee37b53..8339c3b9 100644 --- a/Data/Vector/Fusion/Stream/Monadic.hs +++ b/Data/Vector/Fusion/Stream/Monadic.hs @@ -119,6 +119,8 @@ instance Functor (Step s) where fmap f (Yield x s) = Yield (f x) s fmap _ (Skip s) = Skip s fmap _ Done = Done + {-# INLINE (<$) #-} + (<$) = fmap . const -- | Monadic streams data Stream m a = forall s. Stream (s -> m (Step s a)) s