mirror of
https://github.com/mrkkrp/megaparsec.git
synced 2024-11-26 00:04:18 +03:00
Use better implementations for many and some by default
This commit is contained in:
parent
ca56748247
commit
8d1f5cc35e
@ -7,6 +7,9 @@
|
||||
370](https://github.com/mrkkrp/megaparsec/issues/370).
|
||||
* Inlined `Applicative` operators `(<*)` and `(*>)`. [PR
|
||||
566](https://github.com/mrkkrp/megaparsec/pull/566).
|
||||
* `many` and `some` of the `Alternative` instance of `ParsecT` are now more
|
||||
efficient, since they use the monadic implementations under the hood.
|
||||
[Issue 567](https://github.com/mrkkrp/megaparsec/issues/567).
|
||||
|
||||
## Megaparsec 9.6.1
|
||||
|
||||
|
@ -130,12 +130,16 @@ import Text.Megaparsec.Stream
|
||||
--
|
||||
-- Note that we re-export monadic combinators from
|
||||
-- "Control.Monad.Combinators" because these are more efficient than
|
||||
-- 'Applicative'-based ones. Thus 'many' and 'some' may clash with the
|
||||
-- 'Applicative'-based ones (†). Thus 'many' and 'some' may clash with the
|
||||
-- functions from "Control.Applicative". You need to hide the functions like
|
||||
-- this:
|
||||
--
|
||||
-- > import Control.Applicative hiding (many, some)
|
||||
--
|
||||
-- † As of Megaparsec 9.7.0 'Control.Applicative.many' and
|
||||
-- 'Control.Applicative.some' are as efficient as their monadic
|
||||
-- counterparts.
|
||||
--
|
||||
-- Also note that you can import "Control.Monad.Combinators.NonEmpty" if you
|
||||
-- wish that combinators like 'some' return 'NonEmpty' lists. The module
|
||||
-- lives in the @parser-combinators@ package (you need at least version
|
||||
|
@ -46,6 +46,7 @@ where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import qualified Control.Monad.Combinators
|
||||
import Control.Monad.Cont.Class
|
||||
import Control.Monad.Error.Class
|
||||
import qualified Control.Monad.Fail as Fail
|
||||
@ -211,6 +212,8 @@ pAp m k = ParsecT $ \s cok cerr eok eerr ->
|
||||
instance (Ord e, Stream s) => Alternative (ParsecT e s m) where
|
||||
empty = mzero
|
||||
(<|>) = mplus
|
||||
many = Control.Monad.Combinators.many
|
||||
some = Control.Monad.Combinators.some
|
||||
|
||||
-- | 'return' returns a parser that __succeeds__ without consuming input.
|
||||
instance (Stream s) => Monad (ParsecT e s m) where
|
||||
|
Loading…
Reference in New Issue
Block a user