{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Data.Aeson.WithField.Internal
  ( mplus0
  ) where

import Data.Aeson.Types (Parser, JSONPath)

import Unsafe.Coerce

newtype P a = P 
   { P a
-> forall (f :: * -> *) r.
   JSONPath -> Failure f r -> Success a f r -> f r
runP :: forall f r.
                   JSONPath
                -> Failure f r
                -> Success a f r
                -> f r }

type Failure f r   = JSONPath -> String -> f r
type Success a f r = a -> f r

mplus0 :: forall a . Parser a -> Parser a -> Parser a
mplus0 :: Parser a -> Parser a -> Parser a
mplus0 a :: Parser a
a b :: Parser a
b = forall b. P a -> b
forall a b. a -> b
unsafeCoerce @(P a) (P a -> Parser a) -> P a -> Parser a
forall a b. (a -> b) -> a -> b
$ (forall (f :: * -> *) r.
 JSONPath -> Failure f r -> Success a f r -> f r)
-> P a
forall a.
(forall (f :: * -> *) r.
 JSONPath -> Failure f r -> Success a f r -> f r)
-> P a
P ((forall (f :: * -> *) r.
  JSONPath -> Failure f r -> Success a f r -> f r)
 -> P a)
-> (forall (f :: * -> *) r.
    JSONPath -> Failure f r -> Success a f r -> f r)
-> P a
forall a b. (a -> b) -> a -> b
$ \path :: JSONPath
path kf :: Failure f r
kf ks :: Success a f r
ks -> 
  let kf' :: Failure f r
kf' p :: JSONPath
p l :: String
l = P a -> JSONPath -> Failure f r -> Success a f r -> f r
forall a.
P a
-> forall (f :: * -> *) r.
   JSONPath -> Failure f r -> Success a f r -> f r
runP (Parser a -> P a
forall a b. a -> b
unsafeCoerce Parser a
b) JSONPath
path (\_ _ -> Failure f r
kf JSONPath
p String
l) Success a f r
ks
  in P a -> JSONPath -> Failure f r -> Success a f r -> f r
forall a.
P a
-> forall (f :: * -> *) r.
   JSONPath -> Failure f r -> Success a f r -> f r
runP (Parser a -> P a
forall a b. a -> b
unsafeCoerce Parser a
a) JSONPath
path Failure f r
kf' Success a f r
ks