Introduce Parser'
- Dominant language
- Haskell
- Stars
- 1.3k
- Forks
- 336
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 4
Description
introduce new `Parser'` (name open to bikeshedding)
```haskell
newtype Parser' a = Parser' {
runParser' :: forall f r.
JSONPath
-> Value -- different from primeless Parser
-> Failure f r
-> Success a f r
-> f r
}
```
This will allow to modify `FromJSON` (in backward compatible way):
```haskell
class FromJSON a where
parseJSON :: Value -> Parser a
parseJSON v = Parser $ \path f s -> runParser' parseJSON' path v f s
parseJSON' :: Parser' a
parseJSON' = Parser' $ \path v f s -> runParser (parseJSON v) f s
{-# MINIMAL parseJSON | parseJSON' #-}
```
---
Having `Parser'` will be a little more ergonomic, e.g. for
```haskell
newtype X = X Y
instance FromJSON X where
parseJSON' = X <$> parseJSON'
-- instead of of old one
parseJSON = fmap X . parseJSON
-- or
parseJSON = X <$$> parseJSON -- where (<$$>) = fmap . fmap
```
---
Prime version `Parser'` would require own variants of `withObject`
```haskell
withObject' :: String -> (Object -> Parser a) -> Parser' a
```
OTOH, they aren't really required as
```diff
- parseJSON' = withObject' ...
+ parseJSON = withObject ...
```
Note:
```haskell
-- bad
withObject' :: String
-> (Object -> Parser' a) -- ^ we don't need prime here!
-> Parser' a
```
---
In case this is bad idea, let's document why. Or is it already somewhere?
Contributor guide
Assessment
This issue has not been assessed yet.