Comments (4)
Can these all be written in terms of MonadError? Why should they be specialized to ParserT?
from purescript-parsing.
Can these all be written in terms of MonadError?
Yes, in like one line.
Why should they be specialized to ParserT?
Mostly as documentation to encourage users to “parse, don’t validate?”
from purescript-parsing.
To clarify, if they are implemented only with MonadError, then their utility is far greater than just ParserT, and it would be worth potentially upstreaming them to transformers
if they don't exist.
from purescript-parsing.
Why should they be specialized to ParserT?
In Control.Monad.Error.Class we have
-- | Lift a `Maybe` value to a MonadThrow monad.
liftMaybe :: forall m e a. MonadThrow e m => e -> Maybe a -> m a
-- | Lift an `Either` value to a MonadThrow monad.
liftEither :: forall m e a. MonadThrow e m => Either e a -> m a
It's awkward for parsing users to use these functions because the type for e
would be ParseError
, which has constructor ParseError String Position
. We don't want to require users to supply the Position
argument of the constructor. We would rather specialize the e
type to String
and use the current parsing position.
Also it can be expensive to construct String
s, especially on a parsing hot path where we expect a parsing failure to be rare, so in liftMaybe
it makes sense to defer the String
construction.
So with those adjustments we get
liftMaybe :: forall s m a. Monad m => (Unit -> String) -> Maybe a -> ParserT s m a
liftEither :: forall s m a. Monad m => Either String a -> ParserT s m a
As for liftExceptT
(and liftMaybeT
?) it”s the same as the above, with the stipulation that if the user needs some special base monad feature for parsing then maybe they also need the special base monad feature for validation. This could be true while parsing DataView
s with a base monad Effect
, for example.
So that would be
liftMaybeT :: forall s m a. Monad m => (Unit -> String) -> MaybeT m a -> ParserT s m a
liftExceptT :: forall s m a. Monad m => ExceptT String m a -> ParserT s m a
Those two functions don't seem to exist in transformers
already but if they did then they would look like
-- | Lift a `MaybeT` value to a MonadThrow monad.
liftMaybeT :: forall m e a. MonadThrow e m => e -> MaybeT m a -> m a
-- | Lift an `ExceptT` value to a MonadThrow monad.
liftExceptT :: forall m e a. MonadThrow e m => ExceptT e m a -> m a
from purescript-parsing.
Related Issues (20)
- Fix issues caused by making `<|>` infixr HOT 1
- Change Position to Int HOT 3
- Indents
- purescript-datetime-parsing
- Combinator variations HOT 12
- Talk about alternate backends in documentation
- Fully remove the `Parsing.Pos` module? HOT 1
- MonadST instance for ParserT? HOT 1
- Drop unicode dependency? HOT 5
- `skipSpaces` always commits to branch even if no spaces are consumed HOT 6
- Chris martin's seven parser types HOT 4
- Parsing a `number` in scientific notation _without_ a decimal exponent fails.
- Change “consume” to “commit” HOT 3
- manyIndex ParseError message
- manyMonoid?
- Consider `Parser0` HOT 1
- Multiple errors HOT 7
- withRecovery HOT 2
- Factor out `Tokens` and `Language` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-parsing.