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