on master help sign in
Inline liftA2 in folds and parsers
179d7e6Harendra Kumar
src/Streamly/Internal/Data/Fold/Types.hs+5
@@ -591,6 +591,11 @@ instance Monad m => Applicative (Fold m a) where
591 {-# INLINE (<*>) #-}
591 {-# INLINE (<*>) #-}
592 (<*>) = teeWith ($)
592 (<*>) = teeWith ($)
593
593
594+#if MIN_VERSION_base(4,10,0)
595+ {-# INLINE liftA2 #-}
596+ liftA2 f x = (<*>) (fmap f x)
597+#endif
598+
594-- | @teeWith k f1 f2@ distributes its input to both @f1@ and @f2@ until both
599-- | @teeWith k f1 f2@ distributes its input to both @f1@ and @f2@ until both
595-- of them terminate and combines their output using @k@.
600-- of them terminate and combines their output using @k@.
596--
601--
src/Streamly/Internal/Data/Parser/ParserD/Types.hs+6−1
@@ -132,7 +132,7 @@ module Streamly.Internal.Data.Parser.ParserD.Types
132 )
132 )
133where
133where
134
134
135−import Control.Applicative (Alternative(..))
135+import Control.Applicative (Alternative(..), liftA2)
136import Control.Exception (assert, Exception(..))
136import Control.Exception (assert, Exception(..))
137import Control.Monad (MonadPlus(..))
137import Control.Monad (MonadPlus(..))
138import Control.Monad.Catch (MonadCatch, try, throwM, MonadThrow)
138import Control.Monad.Catch (MonadCatch, try, throwM, MonadThrow)
@@ -524,6 +524,11 @@ instance MonadThrow m => Applicative (Parser m a) where
524 {-# INLINE (*>) #-}
524 {-# INLINE (*>) #-}
525 (*>) = split_
525 (*>) = split_
526
526
527+#if MIN_VERSION_base(4,10,0)
528+ {-# INLINE liftA2 #-}
529+ liftA2 f x = (<*>) (fmap f x)
530+#endif
531+
527-------------------------------------------------------------------------------
532-------------------------------------------------------------------------------
528-- Sequential Alternative
533-- Sequential Alternative
529-------------------------------------------------------------------------------
534-------------------------------------------------------------------------------
src/Streamly/Internal/Data/Parser/ParserK/Types.hs+6−1
@@ -31,7 +31,7 @@ module Streamly.Internal.Data.Parser.ParserK.Types
31 )
31 )
32where
32where
33
33
34−import Control.Applicative (Alternative(..))
34+import Control.Applicative (Alternative(..), liftA2)
35import Control.Exception (assert, Exception(..))
35import Control.Exception (assert, Exception(..))
36import Control.Monad (MonadPlus(..), ap)
36import Control.Monad (MonadPlus(..), ap)
37import Control.Monad.Catch (MonadCatch, MonadThrow(..), try)
37import Control.Monad.Catch (MonadCatch, MonadThrow(..), try)
@@ -319,6 +319,11 @@ instance Monad m => Applicative (Parser m a) where
319 yield1 s (Error e) = yieldk s (Error e)
319 yield1 s (Error e) = yieldk s (Error e)
320 in runParser m1 lo st yield1
320 in runParser m1 lo st yield1
321
321
322+#if MIN_VERSION_base(4,10,0)
323+ {-# INLINE liftA2 #-}
324+ liftA2 f x = (<*>) (fmap f x)
325+#endif
326+
322-------------------------------------------------------------------------------
327-------------------------------------------------------------------------------
323-- Monad
328-- Monad
324-------------------------------------------------------------------------------
329-------------------------------------------------------------------------------