|
|
|
# Replacing the Read Class
|
|
|
|
|
|
|
|
## Tickets
|
|
|
|
|
|
|
|
<table><tr><th>[\#61](https://gitlab.haskell.org//haskell/prime/issues/61)</th>
|
|
|
|
<td>replace the Read class</td></tr></table>
|
|
|
|
|
|
|
|
## Problems with the Haskell 98 class
|
|
|
|
|
|
|
|
- the backtracking parser is very inefficient
|
| ... | ... | @@ -10,30 +15,42 @@ |
|
|
|
|
|
|
|
## Proposed replacements
|
|
|
|
|
|
|
|
- parsers based on [ ReadP](http://www.haskell.org/ghc/docs/latest/html/libraries/base/Text-ParserCombinators-ReadP.html), from [ Parallel Parsing Processes](http://www.md.chalmers.se/~koen/Papers/parsing-pearl.ps) by Koen Classen, JFP 2004.
|
|
|
|
- parsers based on [ ReadP](http://www.haskell.org/ghc/dist/current/docs/libraries/base/Text-ParserCombinators-ReadP.html), from [ Parallel Parsing Processes](http://www.md.chalmers.se/~koen/Papers/parsing-pearl.ps) by Koen Classen, JFP 2004.
|
|
|
|
|
|
|
|
- monadic interface
|
|
|
|
- supports nondeterminism without needing explicit committed choice
|
|
|
|
- abstract type with monadic interface, invoked with
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
readP_to_S :: ReadP a -> String -> [(a, String)]
|
|
|
|
```
|
|
|
|
|
|
|
|
(The internal representation is more complex.)
|
|
|
|
- choice operator supports full nondeterminism by parsing alternatives in parallel.
|
|
|
|
(There is also a committed choice operator.)
|
|
|
|
- mostly deterministic parsers are much more efficient than `ReadS`
|
|
|
|
- no error reporting
|
|
|
|
- returns no information on failure, but could be altered to do so, as it knows the position at which all alternatives are exhausted.
|
|
|
|
- requires [PolymorphicComponents](polymorphic-components)
|
|
|
|
|
|
|
|
GHC has used a new `Read` class based on these parsers since 5.04 (July 2002).
|
|
|
|
|
|
|
|
- Malcolm's experimental [ Poly parser](http://nhc98.blogspot.com/) in the CVS version of [ HaXml](http://www.cs.york.ac.uk/fp/HaXml-1.14/).
|
|
|
|
- Malcolm's experimental [ Poly parser](http://nhc98.blogspot.com/#113301726218243351) in the development version of [ HaXml](http://www.cs.york.ac.uk/fp/HaXml-1.14/).
|
|
|
|
|
|
|
|
- monadic interface
|
|
|
|
- supports non-determinism but also has deterministically committed path (like cut operator in prolog)
|
|
|
|
- returns an error string on failure
|
|
|
|
- monadic interface, invoked with
|
|
|
|
|
|
|
|
- Could also use something based on Daan's Parsec combinators
|
|
|
|
```wiki
|
|
|
|
runParser :: Parser t a -> [t] -> (Either String a, [t])
|
|
|
|
```
|
|
|
|
|
|
|
|
- monadic interface
|
|
|
|
- mostly deterministic, with explicit 'try' operator for non-determinism
|
|
|
|
- error-reporting
|
|
|
|
- already widely used for other parsing tasks
|
|
|
|
(This is essentially the internal representation.)
|
|
|
|
- choice operator commits to the first successful alternative
|
|
|
|
- on failure, returns an error string and the unparsed input
|
|
|
|
|
|
|
|
## Tickets
|
|
|
|
- Could also use something based on Daan's [ Parsec](http://www.cs.uu.nl/people/daan/parsec.html) combinators
|
|
|
|
|
|
|
|
<table><tr><th>[\#61](https://gitlab.haskell.org//haskell/prime/issues/61)</th>
|
|
|
|
<td>replace the Read class</td></tr></table> |
|
|
\ No newline at end of file |
|
|
|
- monadic interface, invoked with (simplifying slightly)
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
parse :: Parser a -> SourceName -> String -> Either ParseError a
|
|
|
|
```
|
|
|
|
- mostly deterministic, with explicit 'try' operator for non-determinism
|
|
|
|
- on failure, reports an error message including the position at which the error occured.
|
|
|
|
- already widely used for other parsing tasks |