haskell / haskell/aeson

Introduce Parser'

Open
#565 1 comment 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.