-
Notifications
You must be signed in to change notification settings - Fork 51
liftMaybe, liftEither, liftExceptT #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can these all be written in terms of MonadError? Why should they be specialized to ParserT? |
Yes, in like one line.
Mostly as documentation to encourage users to “parse, don’t validate?” |
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 |
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 Also it can be expensive to construct 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 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 -- | 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 |
“Validation Parsers”
Similar to
https://pursuit.purescript.org/packages/purescript-transformers/6.0.0/docs/Control.Monad.Error.Class#v:liftMaybe
Similar to
https://pursuit.purescript.org/packages/purescript-protobuf/2.1.2/docs/Protobuf.Library#v:parseMaybe
See also #84
See also https://pursuit.purescript.org/packages/purescript-lazy/6.0.0/docs/Data.Lazy
Or perhaps these should be called
maybeParserT
,eitherParserT
,exceptParserT
?The text was updated successfully, but these errors were encountered: