Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
759 views
in Technique[技术] by (71.8m points)

haskell - What's the difference between Text.ParserCombinators.Parsec and Text.Parsec

Text
    Text.Parsec
        Text.Parsec.ByteString
            Text.Parsec.ByteString.Lazy
        Text.Parsec.Char
        Text.Parsec.Combinator
        Text.Parsec.Error
        Text.Parsec.Expr
        Text.Parsec.Language
        Text.Parsec.Perm
        Text.Parsec.Pos
        Text.Parsec.Prim
        Text.Parsec.String
        Text.Parsec.Token
    ParserCombinators
        Text.ParserCombinators.Parsec
            Text.ParserCombinators.Parsec.Char
            Text.ParserCombinators.Parsec.Combinator
            Text.ParserCombinators.Parsec.Error
            Text.ParserCombinators.Parsec.Expr
            Text.ParserCombinators.Parsec.Language
            Text.ParserCombinators.Parsec.Perm
            Text.ParserCombinators.Parsec.Pos
            Text.ParserCombinators.Parsec.Prim
            Text.ParserCombinators.Parsec.Token

Are they the same?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

At the moment there are two widely used major versions of Parsec: Parsec 2 and Parsec 3.

My advice is simply to use the latest release of Parsec 3. But if you want to make a conscientious choice, read on.

New in Parsec 3

Monad Transformer

Parsec 3 introduces a monad transformer, ParsecT, which can be used to combine parsing with other monadic effects.

Streams

Although Parsec 2 lets you to choose the token type (which is useful when you want to separate lexical analysis from the parsing), the tokens are always arranged into lists. List may be not the most efficient data structure in which to store large texts.

Parsec 3 can work with arbitrary streams -- data structures with a list-like interface. You can define your own streams, but Parsec 3 also includes a popular and efficient Stream implementation based on ByteString (for Char-based parsing), exposed through the modules Text.Parsec.ByteString and Text.Parsec.ByteString.Lazy.

Reasons to prefer Parsec 2

Fewer extensions required

Advanced features provided by Parsec 3 do not come for free; to implement them several language extensions are required.

Neither of the two versions is Haskell-2010 (i.e. both use extensions), but Parsec 2 uses fewer extensions than Parsec 3, so chances that any given compiler can compile Parsec 2 are higher than those for Parsec 3.

By this time both versions work with GHC, while Parsec 2 is also reported to build with JHC and is included as one of the JHC's standard libraries.

Performance

Originally (i.e. as of 3.0 version) Parsec 3 was considerably slower than Parsec 2. However, work on improving Parsec 3 performance has been done, and as of version 3.1 Parsec 3 is only slightly slower than Parsec 2 (benchmarks: 1, 2).

Compatibility layer

It has been possible to "reimplement" all of the Parsec 2 API in Parsec 3. This compatibility layer is provided by the Parsec 3 package under the module hierarchy Text.ParserCombinators.Parsec (the same hierarchy which is used by Parsec 2), while the new Parsec 3 API is available under the Text.Parsec hierarchy.

This means that you can use Parsec 3 as a drop-in replacement for Parsec 2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...