@@ -115,20 +115,29 @@ instance Functor m => Functor (Parser m a) where
115115
116116 fmap3 g = fmap (fmap (fmap g))
117117
118+{-# INLINE wrap #-}
119+wrap :: Monad m => b -> Parser m a b
120+wrap b = Parser (\_ _ -> pure $ Stop 0 ()) -- step
121+ (pure ()) -- initial
122+ (\_ -> pure $ Right b) -- extract
123+
118124{-# ANN type SeqParseState Fuse #-}
119125data SeqParseState sl f sr =
120126 SeqParseL sl | SeqParseR f sr | SeqParseLErr String
121127
128+-- XXX implement interleaved variant, parse using the first parser and then
129+-- using the second parser alternately.
130+--
122131-- | Apply two parsing folds sequentially to an input. The input is provided to
123132-- the first parser, if the parser fails then whole composition fails. If the
124133-- parser succeeds, the remaining input is supplied to the second parser. If
125134-- the second parser succeeds the composed parser succeeds otherwise it fails.
126135--
136+-- This is the opposite of the "append" operation on streams.
137+--
127138instance Monad m => Applicative (Parser m a) where
128139 {-# INLINE pure #-}
129− pure b = Parser (\_ _ -> return $ Stop 0 ())
130− (return ())
131− (\_ -> return $ Right b)
140+ pure = wrap
132141
133142 {-# INLINE (<*>) #-}
134143 (Parser stepL initialL extractL) <*> (Parser stepR initialR extractR) =