{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE NoStarIsType #-}
{-# LANGUAGE EmptyDataDeriving #-}
-- | Elr related methods

module Predicate.Data.Elr (

 -- ** destructors

    ENone'
  , ELeft'
  , ERight'
  , EBoth'

  , ElrIn
  , ElrId
  , ElrPair
  , ElrInSimple
  , PartitionElr

  , ENoneDef
  , ELeftDef
  , ERightDef
  , EBothDef

 -- ** constructors

  , MkENone
  , MkELeft
  , MkERight
  , MkEBoth

  , MkENone'
  , MkELeft'
  , MkERight'

 -- ** predicates

  , IsENone
  , IsELeft
  , IsERight
  , IsEBoth

  -- ** converters

  , These2Elr
  , Elr2These
  , Elr2Maybe
 ) where
import Predicate.Core
import Predicate.Util
import Predicate.Elr
import Data.Kind (Type)
import Control.Lens
import Data.Proxy (Proxy(..))
import Data.These (These)
-- $setup

-- >>> import Predicate

-- >>> import qualified Data.Semigroup as SG

-- >>> :m + Data.These


-- | 'ENone' constructor

--

-- >>> pz @(Proxy Int >> MkENone' UnproxyT 10) []

-- Val ENone

--

data MkENone' t t1 deriving Int -> MkENone' t t1 -> ShowS
[MkENone' t t1] -> ShowS
MkENone' t t1 -> String
(Int -> MkENone' t t1 -> ShowS)
-> (MkENone' t t1 -> String)
-> ([MkENone' t t1] -> ShowS)
-> Show (MkENone' t t1)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (t :: k) k (t1 :: k). Int -> MkENone' t t1 -> ShowS
forall k (t :: k) k (t1 :: k). [MkENone' t t1] -> ShowS
forall k (t :: k) k (t1 :: k). MkENone' t t1 -> String
showList :: [MkENone' t t1] -> ShowS
$cshowList :: forall k (t :: k) k (t1 :: k). [MkENone' t t1] -> ShowS
show :: MkENone' t t1 -> String
$cshow :: forall k (t :: k) k (t1 :: k). MkENone' t t1 -> String
showsPrec :: Int -> MkENone' t t1 -> ShowS
$cshowsPrec :: forall k (t :: k) k (t1 :: k). Int -> MkENone' t t1 -> ShowS
Show

instance P (MkENone' t t1) x where
  type PP (MkENone' t t1) x = Elr (PP t x) (PP t1 x)
  eval :: proxy (MkENone' t t1)
-> POpts -> x -> m (TT (PP (MkENone' t t1) x))
eval proxy (MkENone' t t1)
_ POpts
opts x
_ =
    let msg0 :: String
msg0 = String
"MkENone"
        d :: Elr a b
d = Elr a b
forall a b. Elr a b
ENone
    in TT (Elr (PP t x) (PP t1 x)) -> m (TT (Elr (PP t x) (PP t1 x)))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (Elr (PP t x) (PP t1 x)) -> m (TT (Elr (PP t x) (PP t1 x))))
-> TT (Elr (PP t x) (PP t1 x)) -> m (TT (Elr (PP t x) (PP t1 x)))
forall a b. (a -> b) -> a -> b
$ POpts
-> Val (Elr (PP t x) (PP t1 x))
-> String
-> [Tree PE]
-> TT (Elr (PP t x) (PP t1 x))
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (Elr (PP t x) (PP t1 x) -> Val (Elr (PP t x) (PP t1 x))
forall a. a -> Val a
Val Elr (PP t x) (PP t1 x)
forall a b. Elr a b
d) String
msg0 []

-- | 'ENone' constructor

--

-- >>> pl @(MkENone () Id) 'x'

-- Present ENone (MkENone)

-- Val ENone

--

data MkENone (t :: Type) (t1 :: Type) deriving Int -> MkENone t t1 -> ShowS
[MkENone t t1] -> ShowS
MkENone t t1 -> String
(Int -> MkENone t t1 -> ShowS)
-> (MkENone t t1 -> String)
-> ([MkENone t t1] -> ShowS)
-> Show (MkENone t t1)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall t t1. Int -> MkENone t t1 -> ShowS
forall t t1. [MkENone t t1] -> ShowS
forall t t1. MkENone t t1 -> String
showList :: [MkENone t t1] -> ShowS
$cshowList :: forall t t1. [MkENone t t1] -> ShowS
show :: MkENone t t1 -> String
$cshow :: forall t t1. MkENone t t1 -> String
showsPrec :: Int -> MkENone t t1 -> ShowS
$cshowsPrec :: forall t t1. Int -> MkENone t t1 -> ShowS
Show
type MkENoneT (t :: Type) (t1 :: Type) = MkENone' (Hole t) (Hole t1)

instance P (MkENone t t1) x where
  type PP (MkENone t t1) x = PP (MkENoneT t t1) x
  eval :: proxy (MkENone t t1) -> POpts -> x -> m (TT (PP (MkENone t t1) x))
eval proxy (MkENone t t1)
_ = Proxy (MkENoneT t t1)
-> POpts -> x -> m (TT (PP (MkENoneT t t1) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (MkENoneT t t1)
forall k (t :: k). Proxy t
Proxy @(MkENoneT t t1))

-- | 'ELeft' constructor

--

-- >>> pz @(Proxy Int >> MkELeft' UnproxyT 10) []

-- Val (ELeft 10)

--

data MkELeft' t p deriving Int -> MkELeft' t p -> ShowS
[MkELeft' t p] -> ShowS
MkELeft' t p -> String
(Int -> MkELeft' t p -> ShowS)
-> (MkELeft' t p -> String)
-> ([MkELeft' t p] -> ShowS)
-> Show (MkELeft' t p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (t :: k) k (p :: k). Int -> MkELeft' t p -> ShowS
forall k (t :: k) k (p :: k). [MkELeft' t p] -> ShowS
forall k (t :: k) k (p :: k). MkELeft' t p -> String
showList :: [MkELeft' t p] -> ShowS
$cshowList :: forall k (t :: k) k (p :: k). [MkELeft' t p] -> ShowS
show :: MkELeft' t p -> String
$cshow :: forall k (t :: k) k (p :: k). MkELeft' t p -> String
showsPrec :: Int -> MkELeft' t p -> ShowS
$cshowsPrec :: forall k (t :: k) k (p :: k). Int -> MkELeft' t p -> ShowS
Show

instance P p x
      => P (MkELeft' t p) x where
  type PP (MkELeft' t p) x = Elr (PP p x) (PP t x)
  eval :: proxy (MkELeft' t p) -> POpts -> x -> m (TT (PP (MkELeft' t p) x))
eval proxy (MkELeft' t p)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"MkELeft"
    TT (PP p x)
pp <- Proxy p -> POpts -> x -> m (TT (PP p x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy p
forall k (t :: k). Proxy t
Proxy @p) POpts
opts x
x
    TT (Elr (PP p x) (PP t x)) -> m (TT (Elr (PP p x) (PP t x)))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (Elr (PP p x) (PP t x)) -> m (TT (Elr (PP p x) (PP t x))))
-> TT (Elr (PP p x) (PP t x)) -> m (TT (Elr (PP p x) (PP t x)))
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT (PP p x)
-> [Tree PE]
-> Either (TT (Elr (PP p x) (PP t x))) (PP p x)
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts String
msg0 TT (PP p x)
pp [] of
      Left TT (Elr (PP p x) (PP t x))
e -> TT (Elr (PP p x) (PP t x))
e
      Right PP p x
p ->
        let d :: Elr (PP p x) (PP t x)
d = PP p x -> Elr (PP p x) (PP t x)
forall a b. a -> Elr a b
ELeft PP p x
p
        in POpts
-> Val (Elr (PP p x) (PP t x))
-> String
-> [Tree PE]
-> TT (Elr (PP p x) (PP t x))
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (Elr (PP p x) (PP t x) -> Val (Elr (PP p x) (PP t x))
forall a. a -> Val a
Val Elr (PP p x) (PP t x)
d) String
msg0 [TT (PP p x) -> Tree PE
forall a. TT a -> Tree PE
hh TT (PP p x)
pp]

-- | 'ELeft' constructor

--

-- >>> pl @(MkELeft () Id) 'x'

-- Present ELeft 'x' (MkELeft)

-- Val (ELeft 'x')

--

-- >>> pl @(MkELeft () Fst) ('x',True)

-- Present ELeft 'x' (MkELeft)

-- Val (ELeft 'x')

--

-- >>> pz @(MkELeft _ Id) 44

-- Val (ELeft 44)

--

data MkELeft (t :: Type) p deriving Int -> MkELeft t p -> ShowS
[MkELeft t p] -> ShowS
MkELeft t p -> String
(Int -> MkELeft t p -> ShowS)
-> (MkELeft t p -> String)
-> ([MkELeft t p] -> ShowS)
-> Show (MkELeft t p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall t k (p :: k). Int -> MkELeft t p -> ShowS
forall t k (p :: k). [MkELeft t p] -> ShowS
forall t k (p :: k). MkELeft t p -> String
showList :: [MkELeft t p] -> ShowS
$cshowList :: forall t k (p :: k). [MkELeft t p] -> ShowS
show :: MkELeft t p -> String
$cshow :: forall t k (p :: k). MkELeft t p -> String
showsPrec :: Int -> MkELeft t p -> ShowS
$cshowsPrec :: forall t k (p :: k). Int -> MkELeft t p -> ShowS
Show
type MkELeftT (t :: Type) p = MkELeft' (Hole t) p

instance P (MkELeftT t p) x => P (MkELeft t p) x where
  type PP (MkELeft t p) x = PP (MkELeftT t p) x
  eval :: proxy (MkELeft t p) -> POpts -> x -> m (TT (PP (MkELeft t p) x))
eval proxy (MkELeft t p)
_ = Proxy (MkELeftT t p) -> POpts -> x -> m (TT (PP (MkELeftT t p) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (MkELeftT t p)
forall k (t :: k). Proxy t
Proxy @(MkELeftT t p))

-- | similar to 'MkERight' where @t@ references the type

data MkERight' t p deriving Int -> MkERight' t p -> ShowS
[MkERight' t p] -> ShowS
MkERight' t p -> String
(Int -> MkERight' t p -> ShowS)
-> (MkERight' t p -> String)
-> ([MkERight' t p] -> ShowS)
-> Show (MkERight' t p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (t :: k) k (p :: k). Int -> MkERight' t p -> ShowS
forall k (t :: k) k (p :: k). [MkERight' t p] -> ShowS
forall k (t :: k) k (p :: k). MkERight' t p -> String
showList :: [MkERight' t p] -> ShowS
$cshowList :: forall k (t :: k) k (p :: k). [MkERight' t p] -> ShowS
show :: MkERight' t p -> String
$cshow :: forall k (t :: k) k (p :: k). MkERight' t p -> String
showsPrec :: Int -> MkERight' t p -> ShowS
$cshowsPrec :: forall k (t :: k) k (p :: k). Int -> MkERight' t p -> ShowS
Show

instance P p x
      => P (MkERight' t p) x where
  type PP (MkERight' t p) x = Elr (PP t x) (PP p x)
  eval :: proxy (MkERight' t p)
-> POpts -> x -> m (TT (PP (MkERight' t p) x))
eval proxy (MkERight' t p)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"MkERight"
    TT (PP p x)
pp <- Proxy p -> POpts -> x -> m (TT (PP p x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy p
forall k (t :: k). Proxy t
Proxy @p) POpts
opts x
x
    TT (Elr (PP t x) (PP p x)) -> m (TT (Elr (PP t x) (PP p x)))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (Elr (PP t x) (PP p x)) -> m (TT (Elr (PP t x) (PP p x))))
-> TT (Elr (PP t x) (PP p x)) -> m (TT (Elr (PP t x) (PP p x)))
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT (PP p x)
-> [Tree PE]
-> Either (TT (Elr (PP t x) (PP p x))) (PP p x)
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts String
msg0 TT (PP p x)
pp [] of
      Left TT (Elr (PP t x) (PP p x))
e -> TT (Elr (PP t x) (PP p x))
e
      Right PP p x
p ->
        let d :: Elr (PP t x) (PP p x)
d = PP p x -> Elr (PP t x) (PP p x)
forall a b. b -> Elr a b
ERight PP p x
p
        in POpts
-> Val (Elr (PP t x) (PP p x))
-> String
-> [Tree PE]
-> TT (Elr (PP t x) (PP p x))
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (Elr (PP t x) (PP p x) -> Val (Elr (PP t x) (PP p x))
forall a. a -> Val a
Val Elr (PP t x) (PP p x)
d) String
msg0 [TT (PP p x) -> Tree PE
forall a. TT a -> Tree PE
hh TT (PP p x)
pp]

-- | 'ERight' constructor

--

-- >>> pz @(MkERight _ Id) 44

-- Val (ERight 44)

--

-- >>> pz @(MkERight _ "Abc" <> MkELeft _ '[1,2] <> MkEBoth [3,4] "def") ()

-- Val (EBoth [1,2,3,4] "Abcdef")

--

-- >>> pl @(MkERight () Id) 'x'

-- Present ERight 'x' (MkERight)

-- Val (ERight 'x')

--

data MkERight (t :: Type) p deriving Int -> MkERight t p -> ShowS
[MkERight t p] -> ShowS
MkERight t p -> String
(Int -> MkERight t p -> ShowS)
-> (MkERight t p -> String)
-> ([MkERight t p] -> ShowS)
-> Show (MkERight t p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall t k (p :: k). Int -> MkERight t p -> ShowS
forall t k (p :: k). [MkERight t p] -> ShowS
forall t k (p :: k). MkERight t p -> String
showList :: [MkERight t p] -> ShowS
$cshowList :: forall t k (p :: k). [MkERight t p] -> ShowS
show :: MkERight t p -> String
$cshow :: forall t k (p :: k). MkERight t p -> String
showsPrec :: Int -> MkERight t p -> ShowS
$cshowsPrec :: forall t k (p :: k). Int -> MkERight t p -> ShowS
Show
type MkERightT (t :: Type) p = MkERight' (Hole t) p

instance P (MkERightT t p) x => P (MkERight t p) x where
  type PP (MkERight t p) x = PP (MkERightT t p) x
  eval :: proxy (MkERight t p) -> POpts -> x -> m (TT (PP (MkERight t p) x))
eval proxy (MkERight t p)
_ = Proxy (MkERightT t p)
-> POpts -> x -> m (TT (PP (MkERightT t p) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (MkERightT t p)
forall k (t :: k). Proxy t
Proxy @(MkERightT t p))

-- | 'EBoth' constructor

--

-- >>> pz @(MkEBoth Fst Snd) (44,'x')

-- Val (EBoth 44 'x')

--

-- >>> pl @(MkEBoth Id 'True) 'x'

-- Present EBoth 'x' True (MkEBoth)

-- Val (EBoth 'x' True)

--

-- >>> pz @(MkENone _ _ <> MkELeft _ '[1] <> MkERight _ "abc" <> MkELeft _ '[2] <> MkEBoth '[3,4,5] "def") ()

-- Val (EBoth [1,2,3,4,5] "abcdef")

--

data MkEBoth p q deriving Int -> MkEBoth p q -> ShowS
[MkEBoth p q] -> ShowS
MkEBoth p q -> String
(Int -> MkEBoth p q -> ShowS)
-> (MkEBoth p q -> String)
-> ([MkEBoth p q] -> ShowS)
-> Show (MkEBoth p q)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k) k (q :: k). Int -> MkEBoth p q -> ShowS
forall k (p :: k) k (q :: k). [MkEBoth p q] -> ShowS
forall k (p :: k) k (q :: k). MkEBoth p q -> String
showList :: [MkEBoth p q] -> ShowS
$cshowList :: forall k (p :: k) k (q :: k). [MkEBoth p q] -> ShowS
show :: MkEBoth p q -> String
$cshow :: forall k (p :: k) k (q :: k). MkEBoth p q -> String
showsPrec :: Int -> MkEBoth p q -> ShowS
$cshowsPrec :: forall k (p :: k) k (q :: k). Int -> MkEBoth p q -> ShowS
Show
instance ( P p a
         , P q a
         ) => P (MkEBoth p q) a where
  type PP (MkEBoth p q) a = Elr (PP p a) (PP q a)
  eval :: proxy (MkEBoth p q) -> POpts -> a -> m (TT (PP (MkEBoth p q) a))
eval proxy (MkEBoth p q)
_ POpts
opts a
a = do
    let msg0 :: String
msg0 = String
"MkEBoth"
    Either
  (TT (Elr (PP p a) (PP q a)))
  (PP p a, PP q a, TT (PP p a), TT (PP q a))
lr <- Inline
-> String
-> Proxy p
-> Proxy q
-> POpts
-> a
-> [Tree PE]
-> m (Either
        (TT (Elr (PP p a) (PP q a)))
        (PP p a, PP q a, TT (PP p a), TT (PP q a)))
forall k1 k2 (p :: k1) a (q :: k2) (m :: Type -> Type)
       (proxy1 :: k1 -> Type) (proxy2 :: k2 -> Type) x.
(P p a, P q a, MonadEval m) =>
Inline
-> String
-> proxy1 p
-> proxy2 q
-> POpts
-> a
-> [Tree PE]
-> m (Either (TT x) (PP p a, PP q a, TT (PP p a), TT (PP q a)))
runPQ Inline
NoInline String
msg0 (Proxy p
forall k (t :: k). Proxy t
Proxy @p) (Proxy q
forall k (t :: k). Proxy t
Proxy @q) POpts
opts a
a []
    TT (Elr (PP p a) (PP q a)) -> m (TT (Elr (PP p a) (PP q a)))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (Elr (PP p a) (PP q a)) -> m (TT (Elr (PP p a) (PP q a))))
-> TT (Elr (PP p a) (PP q a)) -> m (TT (Elr (PP p a) (PP q a)))
forall a b. (a -> b) -> a -> b
$ case Either
  (TT (Elr (PP p a) (PP q a)))
  (PP p a, PP q a, TT (PP p a), TT (PP q a))
lr of
      Left TT (Elr (PP p a) (PP q a))
e -> TT (Elr (PP p a) (PP q a))
e
      Right (PP p a
p,PP q a
q,TT (PP p a)
pp,TT (PP q a)
qq) ->
        let d :: Elr (PP p a) (PP q a)
d = PP p a -> PP q a -> Elr (PP p a) (PP q a)
forall a b. a -> b -> Elr a b
EBoth PP p a
p PP q a
q
        in POpts
-> Val (Elr (PP p a) (PP q a))
-> String
-> [Tree PE]
-> TT (Elr (PP p a) (PP q a))
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (Elr (PP p a) (PP q a) -> Val (Elr (PP p a) (PP q a))
forall a. a -> Val a
Val Elr (PP p a) (PP q a)
d) String
msg0 [TT (PP p a) -> Tree PE
forall a. TT a -> Tree PE
hh TT (PP p a)
pp, TT (PP q a) -> Tree PE
forall a. TT a -> Tree PE
hh TT (PP q a)
qq]

data IsElr (th :: Elr x y) deriving Int -> IsElr th -> ShowS
[IsElr th] -> ShowS
IsElr th -> String
(Int -> IsElr th -> ShowS)
-> (IsElr th -> String) -> ([IsElr th] -> ShowS) -> Show (IsElr th)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall x y (th :: Elr x y). Int -> IsElr th -> ShowS
forall x y (th :: Elr x y). [IsElr th] -> ShowS
forall x y (th :: Elr x y). IsElr th -> String
showList :: [IsElr th] -> ShowS
$cshowList :: forall x y (th :: Elr x y). [IsElr th] -> ShowS
show :: IsElr th -> String
$cshow :: forall x y (th :: Elr x y). IsElr th -> String
showsPrec :: Int -> IsElr th -> ShowS
$cshowsPrec :: forall x y (th :: Elr x y). Int -> IsElr th -> ShowS
Show
-- x y can be anything


-- trying to avoid Show instance because more likely to have ambiguity errors

instance ( x ~ Elr a b
         , Show a
         , Show b
         , GetElr th
         ) => P (IsElr (th :: Elr x1 x2)) x where
  type PP (IsElr th) x = Bool
  eval :: proxy (IsElr th) -> POpts -> x -> m (TT (PP (IsElr th) x))
eval proxy (IsElr th)
_ POpts
opts x
x =
    let msg0 :: String
msg0 = String
"Is"
        th :: Elr () ()
th = GetElr th => Elr () ()
forall k k1 (th :: Elr k k1). GetElr th => Elr () ()
getElr @th
        fn :: Elr a b -> Bool
fn = case Elr () ()
th of
               Elr () ()
ENone -> Elr a b -> Bool
forall a b. Elr a b -> Bool
isENone
               ELeft () -> Elr a b -> Bool
forall a b. Elr a b -> Bool
isELeft
               ERight () -> Elr a b -> Bool
forall a b. Elr a b -> Bool
isERight
               EBoth () () -> Elr a b -> Bool
forall a b. Elr a b -> Bool
isEBoth
        b :: Bool
b = Elr a b -> Bool
fn x
Elr a b
x
    in TT Bool -> m (TT Bool)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT Bool -> m (TT Bool)) -> TT Bool -> m (TT Bool)
forall a b. (a -> b) -> a -> b
$ POpts -> Bool -> String -> [Tree PE] -> TT Bool
mkNodeB POpts
opts Bool
b (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Elr () () -> String
forall a b. Elr a b -> String
showElr Elr () ()
th String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> x -> String
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " x
x) []

-- | predicate on 'ENone'

--

-- >>> pz @IsENone ENone

-- Val True

--

-- >>> pz @IsENone (EBoth 1 'a')

-- Val False

--

data IsENone deriving Int -> IsENone -> ShowS
[IsENone] -> ShowS
IsENone -> String
(Int -> IsENone -> ShowS)
-> (IsENone -> String) -> ([IsENone] -> ShowS) -> Show IsENone
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsENone] -> ShowS
$cshowList :: [IsENone] -> ShowS
show :: IsENone -> String
$cshow :: IsENone -> String
showsPrec :: Int -> IsENone -> ShowS
$cshowsPrec :: Int -> IsENone -> ShowS
Show
type IsENoneT = IsElr 'ENone

instance P IsENoneT x => P IsENone x where
  type PP IsENone x = PP IsENoneT x
  eval :: proxy IsENone -> POpts -> x -> m (TT (PP IsENone x))
eval proxy IsENone
_ = Proxy IsENoneT -> POpts -> x -> m (TT (PP IsENoneT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsENoneT
forall k (t :: k). Proxy t
Proxy @IsENoneT)

-- | predicate on 'ELeft'

--

-- >>> pz @IsELeft (ELeft "aBc")

-- Val True

--

-- >>> pz @IsELeft (EBoth 1 'a')

-- Val False

--

-- >>> pl @IsELeft (ELeft 12)

-- True (IsELeft | ELeft 12)

-- Val True

--

data IsELeft deriving Int -> IsELeft -> ShowS
[IsELeft] -> ShowS
IsELeft -> String
(Int -> IsELeft -> ShowS)
-> (IsELeft -> String) -> ([IsELeft] -> ShowS) -> Show IsELeft
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsELeft] -> ShowS
$cshowList :: [IsELeft] -> ShowS
show :: IsELeft -> String
$cshow :: IsELeft -> String
showsPrec :: Int -> IsELeft -> ShowS
$cshowsPrec :: Int -> IsELeft -> ShowS
Show
type IsELeftT = IsElr ('ELeft '())

instance P IsELeftT x => P IsELeft x where
  type PP IsELeft x = PP IsELeftT x
  eval :: proxy IsELeft -> POpts -> x -> m (TT (PP IsELeft x))
eval proxy IsELeft
_ = Proxy IsELeftT -> POpts -> x -> m (TT (PP IsELeftT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsELeftT
forall k (t :: k). Proxy t
Proxy @IsELeftT)

-- | predicate on 'ERight'

--

-- >>> pl @IsERight (ELeft 12)

-- False (IsERight | ELeft 12)

-- Val False

--

data IsERight deriving Int -> IsERight -> ShowS
[IsERight] -> ShowS
IsERight -> String
(Int -> IsERight -> ShowS)
-> (IsERight -> String) -> ([IsERight] -> ShowS) -> Show IsERight
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsERight] -> ShowS
$cshowList :: [IsERight] -> ShowS
show :: IsERight -> String
$cshow :: IsERight -> String
showsPrec :: Int -> IsERight -> ShowS
$cshowsPrec :: Int -> IsERight -> ShowS
Show
type IsERightT = IsElr ('ERight '())

instance P IsERightT x => P IsERight x where
  type PP IsERight x = PP IsERightT x
  eval :: proxy IsERight -> POpts -> x -> m (TT (PP IsERight x))
eval proxy IsERight
_ = Proxy IsERightT -> POpts -> x -> m (TT (PP IsERightT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsERightT
forall k (t :: k). Proxy t
Proxy @IsERightT)

-- | predicate on 'EBoth'

--

-- >>> pl @IsEBoth (ELeft 12)

-- False (IsEBoth | ELeft 12)

-- Val False

--

-- >>> pz @IsEBoth (EBoth 1 'a')

-- Val True

--

-- >>> pl @IsEBoth (EBoth 'x' 12)

-- True (IsEBoth | EBoth 'x' 12)

-- Val True

--

-- >>> pl @IsEBoth (ERight (SG.Sum 12))

-- False (IsEBoth | ERight (Sum {getSum = 12}))

-- Val False

--

-- >>> pl @IsEBoth (EBoth 1 (SG.Sum 12))

-- True (IsEBoth | EBoth 1 (Sum {getSum = 12}))

-- Val True

--

data IsEBoth deriving Int -> IsEBoth -> ShowS
[IsEBoth] -> ShowS
IsEBoth -> String
(Int -> IsEBoth -> ShowS)
-> (IsEBoth -> String) -> ([IsEBoth] -> ShowS) -> Show IsEBoth
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsEBoth] -> ShowS
$cshowList :: [IsEBoth] -> ShowS
show :: IsEBoth -> String
$cshow :: IsEBoth -> String
showsPrec :: Int -> IsEBoth -> ShowS
$cshowsPrec :: Int -> IsEBoth -> ShowS
Show
type IsEBothT = IsElr ('EBoth '() '())

instance P IsEBothT x => P IsEBoth x where
  type PP IsEBoth x = PP IsEBothT x
  eval :: proxy IsEBoth -> POpts -> x -> m (TT (PP IsEBoth x))
eval proxy IsEBoth
_ = Proxy IsEBothT -> POpts -> x -> m (TT (PP IsEBothT x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy IsEBothT
forall k (t :: k). Proxy t
Proxy @IsEBothT)

-- | tries to extract a () from the 'ENone' constructor

--

-- >>> pz @ENone' ENone

-- Val ()

--

-- >>> pz @ENone' (ERight 'a')

-- Fail "ENone' found ERight"

--

data ENone' deriving Int -> ENone' -> ShowS
[ENone'] -> ShowS
ENone' -> String
(Int -> ENone' -> ShowS)
-> (ENone' -> String) -> ([ENone'] -> ShowS) -> Show ENone'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ENone'] -> ShowS
$cshowList :: [ENone'] -> ShowS
show :: ENone' -> String
$cshow :: ENone' -> String
showsPrec :: Int -> ENone' -> ShowS
$cshowsPrec :: Int -> ENone' -> ShowS
Show

instance P ENone' (Elr x y) where
  type PP ENone' (Elr x y) = ()
  eval :: proxy ENone' -> POpts -> Elr x y -> m (TT (PP ENone' (Elr x y)))
eval proxy ENone'
_ POpts
opts Elr x y
lr =
    let msg0 :: String
msg0 = String
"ENone'"
    in TT () -> m (TT ())
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT () -> m (TT ())) -> TT () -> m (TT ())
forall a b. (a -> b) -> a -> b
$ case Elr x y
lr of
         Elr x y
ENone -> POpts -> Val () -> String -> [Tree PE] -> TT ()
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (() -> Val ()
forall a. a -> Val a
Val ()) String
msg0 []
         Elr x y
_ -> POpts -> Val () -> String -> [Tree PE] -> TT ()
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val ()
forall a. String -> Val a
Fail (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" found " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Elr x y -> String
forall a b. Elr a b -> String
showElr Elr x y
lr)) String
"" []

-- | tries to extract a value from the 'ELeft' constructor

--

-- >>> pz @(ELeft' >> Succ) (ELeft 20)

-- Val 21

--

-- >>> pz @(ELeft' >> Succ) (ERight 'a')

-- Fail "ELeft' found ERight"

--

data ELeft' deriving Int -> ELeft' -> ShowS
[ELeft'] -> ShowS
ELeft' -> String
(Int -> ELeft' -> ShowS)
-> (ELeft' -> String) -> ([ELeft'] -> ShowS) -> Show ELeft'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ELeft'] -> ShowS
$cshowList :: [ELeft'] -> ShowS
show :: ELeft' -> String
$cshow :: ELeft' -> String
showsPrec :: Int -> ELeft' -> ShowS
$cshowsPrec :: Int -> ELeft' -> ShowS
Show

instance Show a => P ELeft' (Elr a x) where
  type PP ELeft' (Elr a x) = a
  eval :: proxy ELeft' -> POpts -> Elr a x -> m (TT (PP ELeft' (Elr a x)))
eval proxy ELeft'
_ POpts
opts Elr a x
lr =
    let msg0 :: String
msg0 = String
"ELeft'"
    in TT a -> m (TT a)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT a -> m (TT a)) -> TT a -> m (TT a)
forall a b. (a -> b) -> a -> b
$ case Elr a x
lr of
         ELeft a
a -> POpts -> Val a -> String -> [Tree PE] -> TT a
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (a -> Val a
forall a. a -> Val a
Val a
a) (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> a -> String
forall a. Show a => POpts -> a -> String
showL POpts
opts a
a) []
         Elr a x
_ -> POpts -> Val a -> String -> [Tree PE] -> TT a
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val a
forall a. String -> Val a
Fail (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" found " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Elr a x -> String
forall a b. Elr a b -> String
showElr Elr a x
lr)) String
"" []

-- | tries to extract a value from the 'ERight' constructor

--

-- >>> pz @(ERight' >> Succ) (ERight 20)

-- Val 21

--

-- >>> pz @(ERight' >> Succ) (ELeft 'a')

-- Fail "ERight' found ELeft"

--

data ERight' deriving Int -> ERight' -> ShowS
[ERight'] -> ShowS
ERight' -> String
(Int -> ERight' -> ShowS)
-> (ERight' -> String) -> ([ERight'] -> ShowS) -> Show ERight'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ERight'] -> ShowS
$cshowList :: [ERight'] -> ShowS
show :: ERight' -> String
$cshow :: ERight' -> String
showsPrec :: Int -> ERight' -> ShowS
$cshowsPrec :: Int -> ERight' -> ShowS
Show

instance Show a => P ERight' (Elr x a) where
  type PP ERight' (Elr x a) = a
  eval :: proxy ERight' -> POpts -> Elr x a -> m (TT (PP ERight' (Elr x a)))
eval proxy ERight'
_ POpts
opts Elr x a
lr =
    let msg0 :: String
msg0 = String
"ERight'"
    in TT a -> m (TT a)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT a -> m (TT a)) -> TT a -> m (TT a)
forall a b. (a -> b) -> a -> b
$ case Elr x a
lr of
         ERight a
a -> POpts -> Val a -> String -> [Tree PE] -> TT a
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (a -> Val a
forall a. a -> Val a
Val a
a) (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> a -> String
forall a. Show a => POpts -> a -> String
showL POpts
opts a
a) []
         Elr x a
_ -> POpts -> Val a -> String -> [Tree PE] -> TT a
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val a
forall a. String -> Val a
Fail (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" found " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Elr x a -> String
forall a b. Elr a b -> String
showElr Elr x a
lr)) String
"" []

-- | tries to extract the values from the 'EBoth' constructor

--

-- >>> pz @(EBoth' >> Second Succ) (EBoth 1 'a')

-- Val (1,'b')

--

-- >>> pz @(ERight' >> Succ) (ELeft 'a')

-- Fail "ERight' found ELeft"

--

-- >>> pz @(EBoth' >> Second Succ) (ERight 8)

-- Fail "EBoth' found ERight"

--

data EBoth' deriving Int -> EBoth' -> ShowS
[EBoth'] -> ShowS
EBoth' -> String
(Int -> EBoth' -> ShowS)
-> (EBoth' -> String) -> ([EBoth'] -> ShowS) -> Show EBoth'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EBoth'] -> ShowS
$cshowList :: [EBoth'] -> ShowS
show :: EBoth' -> String
$cshow :: EBoth' -> String
showsPrec :: Int -> EBoth' -> ShowS
$cshowsPrec :: Int -> EBoth' -> ShowS
Show

instance ( Show a
         , Show b
        ) => P EBoth' (Elr a b) where
  type PP EBoth' (Elr a b) = (a,b)
  eval :: proxy EBoth' -> POpts -> Elr a b -> m (TT (PP EBoth' (Elr a b)))
eval proxy EBoth'
_ POpts
opts Elr a b
lr =
    let msg0 :: String
msg0 = String
"EBoth'"
    in TT (a, b) -> m (TT (a, b))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (a, b) -> m (TT (a, b))) -> TT (a, b) -> m (TT (a, b))
forall a b. (a -> b) -> a -> b
$ case Elr a b
lr of
         EBoth a
a b
b -> POpts -> Val (a, b) -> String -> [Tree PE] -> TT (a, b)
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts ((a, b) -> Val (a, b)
forall a. a -> Val a
Val (a
a,b
b)) (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> (a, b) -> String
forall a. Show a => POpts -> a -> String
showL POpts
opts (a
a,b
b)) []
         Elr a b
_ -> POpts -> Val (a, b) -> String -> [Tree PE] -> TT (a, b)
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val (a, b)
forall a. String -> Val a
Fail (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" found " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Elr a b -> String
forall a b. Elr a b -> String
showElr Elr a b
lr)) String
"" []

-- | similar to 'Predicate.Data.These.PartitionThese' for 'Elr'. returns a 4-tuple with the results so use 'Fst' 'Snd' 'Thd' 'L4' to extract

--

-- >>> pz @PartitionElr [ELeft 'a', ENone, ERight 2, ELeft 'c', EBoth 'z' 1, ERight 4, EBoth 'a' 2, ERight 99, ENone]

-- Val ([(),()],"ac",[2,4,99],[('z',1),('a',2)])

--

-- >>> pz @PartitionElr [ELeft 4, ERight 'x', ERight 'y',EBoth 3 'b', ELeft 99, EBoth 5 'x']

-- Val ([],[4,99],"xy",[(3,'b'),(5,'x')])

--

-- >>> pz @PartitionElr [ENone,ELeft 1,ERight 'x',ELeft 4,ERight 'y',EBoth 9 'z',ELeft 10,EBoth 8 'y']

-- Val ([()],[1,4,10],"xy",[(9,'z'),(8,'y')])

--

data PartitionElr deriving Int -> PartitionElr -> ShowS
[PartitionElr] -> ShowS
PartitionElr -> String
(Int -> PartitionElr -> ShowS)
-> (PartitionElr -> String)
-> ([PartitionElr] -> ShowS)
-> Show PartitionElr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PartitionElr] -> ShowS
$cshowList :: [PartitionElr] -> ShowS
show :: PartitionElr -> String
$cshow :: PartitionElr -> String
showsPrec :: Int -> PartitionElr -> ShowS
$cshowsPrec :: Int -> PartitionElr -> ShowS
Show

instance ( Show a
         , Show b
         ) => P PartitionElr [Elr a b] where
  type PP PartitionElr [Elr a b] = ([()], [a], [b], [(a, b)])
  eval :: proxy PartitionElr
-> POpts -> [Elr a b] -> m (TT (PP PartitionElr [Elr a b]))
eval proxy PartitionElr
_ POpts
opts [Elr a b]
as =
    let msg0 :: String
msg0 = String
"PartitionElr"
        b :: ([()], [a], [b], [(a, b)])
b = [Elr a b] -> ([()], [a], [b], [(a, b)])
forall a b. [Elr a b] -> ([()], [a], [b], [(a, b)])
partitionElr [Elr a b]
as
    in TT ([()], [a], [b], [(a, b)]) -> m (TT ([()], [a], [b], [(a, b)]))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT ([()], [a], [b], [(a, b)])
 -> m (TT ([()], [a], [b], [(a, b)])))
-> TT ([()], [a], [b], [(a, b)])
-> m (TT ([()], [a], [b], [(a, b)]))
forall a b. (a -> b) -> a -> b
$ POpts
-> Val ([()], [a], [b], [(a, b)])
-> String
-> [Tree PE]
-> TT ([()], [a], [b], [(a, b)])
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (([()], [a], [b], [(a, b)]) -> Val ([()], [a], [b], [(a, b)])
forall a. a -> Val a
Val ([()], [a], [b], [(a, b)])
b) (POpts
-> String -> ([()], [a], [b], [(a, b)]) -> [Elr a b] -> String
forall a1 a2.
(Show a1, Show a2) =>
POpts -> String -> a1 -> a2 -> String
show3 POpts
opts String
msg0 ([()], [a], [b], [(a, b)])
b [Elr a b]
as) []

-- | destructs an Elr value

--   @n@ @ENone@ receives @(PP s x)@

--   @p@ @ELeft a@ receives @(PP s x,a)@

--   @q@ @ERight b@ receives @(PP s x,b)@

--   @r@ @EBoth a b@ receives @(PP s x,(a,b))@

--   @s@ points to the environment you want to pass in

--   @t@ points to the Elr value

--

-- >>> pz @(ElrIn Id '(Snd,L12) '(L11,Snd) Snd Fst Snd) ((999,'a'), EBoth 12 'x')

-- Val (12,'x')

--

-- >>> pz @(ElrIn Id '(Snd,L12) '(L11,Snd) Snd Fst Snd) ((999,'a'), ENone)

-- Val (999,'a')

--

-- >>> pz @(ElrIn Id '(Snd,L12) '(L11,Snd) Snd Fst Snd) ((999,'a'), ERight 'z')

-- Val (999,'z')

--

-- >>> pz @(ElrIn 999 Snd (Snd >> Len) (Snd >> Fst + Length Snd) () Id) (ELeft 13)

-- Val 13

--

-- >>> pz @(ElrIn 999 Snd (Snd >> Len) (Snd >> Fst + Length Snd) () Id) (ERight "abcdef")

-- Val 6

--

-- >>> pl @(ElrIn "none" "left" "right" "both" () Id) (ELeft (SG.Sum 12))

-- Present "left" (ElrIn(ELeft) "left" | Sum {getSum = 12})

-- Val "left"

--

-- >>> pl @(ElrIn '("",2) '(Snd,999) '("no value",Snd) Snd () Id) (EBoth "Ab" 13)

-- Present ("Ab",13) (ElrIn(EBoth) ("Ab",13) | ("Ab",13))

-- Val ("Ab",13)

--

-- >>> pl @(ElrIn '("",2) '(Snd,999) '("no value",Snd) Snd () Id) (ELeft "Ab")

-- Present ("Ab",999) (ElrIn(ELeft) ("Ab",999) | "Ab")

-- Val ("Ab",999)

--

-- >>> pl @(ElrIn '("",2) '(Snd,999) '("no value",Snd) Snd () Id) ENone

-- Present ("",2) (ElrIn(ENone) ("",2) | ())

-- Val ("",2)

--

-- >>> pl @(ElrIn (FailT _ "none found") '(Snd,"fromleft") '(888,Snd) Snd () Id)  ENone

-- Error none found (ElrIn(ENone) n failed)

-- Fail "none found"

--

data ElrIn n p q r s t deriving Int -> ElrIn n p q r s t -> ShowS
[ElrIn n p q r s t] -> ShowS
ElrIn n p q r s t -> String
(Int -> ElrIn n p q r s t -> ShowS)
-> (ElrIn n p q r s t -> String)
-> ([ElrIn n p q r s t] -> ShowS)
-> Show (ElrIn n p q r s t)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (n :: k) k (p :: k) k (q :: k) k (r :: k) k (s :: k) k
       (t :: k).
Int -> ElrIn n p q r s t -> ShowS
forall k (n :: k) k (p :: k) k (q :: k) k (r :: k) k (s :: k) k
       (t :: k).
[ElrIn n p q r s t] -> ShowS
forall k (n :: k) k (p :: k) k (q :: k) k (r :: k) k (s :: k) k
       (t :: k).
ElrIn n p q r s t -> String
showList :: [ElrIn n p q r s t] -> ShowS
$cshowList :: forall k (n :: k) k (p :: k) k (q :: k) k (r :: k) k (s :: k) k
       (t :: k).
[ElrIn n p q r s t] -> ShowS
show :: ElrIn n p q r s t -> String
$cshow :: forall k (n :: k) k (p :: k) k (q :: k) k (r :: k) k (s :: k) k
       (t :: k).
ElrIn n p q r s t -> String
showsPrec :: Int -> ElrIn n p q r s t -> ShowS
$cshowsPrec :: forall k (n :: k) k (p :: k) k (q :: k) k (r :: k) k (s :: k) k
       (t :: k).
Int -> ElrIn n p q r s t -> ShowS
Show

instance ( Show a
         , Show b
         , Show (PP r (y,(a,b)))
         , P n y
         , P p (y,a)
         , P q (y,b)
         , P r (y,(a,b))
         , PP n y ~ PP p (y,a)
         , PP p (y,a) ~ PP q (y,b)
         , PP q (y,b) ~ PP r (y,(a,b))
         , P s x
         , P t x
         , PP t x ~ Elr a b
         , PP s x ~ y
         )  => P (ElrIn n p q r s t) x where
  type PP (ElrIn n p q r s t) x = PP n (PP s x)
  eval :: proxy (ElrIn n p q r s t)
-> POpts -> x -> m (TT (PP (ElrIn n p q r s t) x))
eval proxy (ElrIn n p q r s t)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"ElrIn"
    Either (TT (PP r (y, (a, b)))) (y, Elr a b, TT y, TT (Elr a b))
lr <- Inline
-> String
-> Proxy s
-> Proxy t
-> POpts
-> x
-> [Tree PE]
-> m (Either
        (TT (PP r (y, (a, b)))) (PP s x, PP t x, TT (PP s x), TT (PP t x)))
forall k1 k2 (p :: k1) a (q :: k2) (m :: Type -> Type)
       (proxy1 :: k1 -> Type) (proxy2 :: k2 -> Type) x.
(P p a, P q a, MonadEval m) =>
Inline
-> String
-> proxy1 p
-> proxy2 q
-> POpts
-> a
-> [Tree PE]
-> m (Either (TT x) (PP p a, PP q a, TT (PP p a), TT (PP q a)))
runPQ Inline
NoInline String
msg0 (Proxy s
forall k (t :: k). Proxy t
Proxy @s) (Proxy t
forall k (t :: k). Proxy t
Proxy @t) POpts
opts x
x []
    case Either (TT (PP r (y, (a, b)))) (y, Elr a b, TT y, TT (Elr a b))
lr of
      Left TT (PP r (y, (a, b)))
e -> TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b))))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure TT (PP r (y, (a, b)))
e
      Right (y
s,Elr a b
t,TT y
ss,TT (Elr a b)
tt) -> do
         let hhs :: [Tree PE]
hhs = [TT y -> Tree PE
forall a. TT a -> Tree PE
hh TT y
ss, TT (Elr a b) -> Tree PE
forall a. TT a -> Tree PE
hh TT (Elr a b)
tt]
         case Elr a b
t of
            Elr a b
ENone -> do
              let msg1 :: String
msg1 = String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"(ENone)"
              TT (PP r (y, (a, b)))
nn <- Proxy n -> POpts -> y -> m (TT (PP n y))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy n
forall k (t :: k). Proxy t
Proxy @n) POpts
opts y
s
              TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b))))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b)))))
-> TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b))))
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT (PP r (y, (a, b)))
-> [Tree PE]
-> Either (TT (PP r (y, (a, b)))) (PP r (y, (a, b)))
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" n failed") TT (PP r (y, (a, b)))
nn [Tree PE]
hhs of
                   Left TT (PP r (y, (a, b)))
e -> TT (PP r (y, (a, b)))
e
                   Right PP r (y, (a, b))
c -> POpts
-> TT (PP r (y, (a, b)))
-> String
-> [Tree PE]
-> TT (PP r (y, (a, b)))
forall a. POpts -> TT a -> String -> [Tree PE] -> TT a
mkNodeCopy POpts
opts TT (PP r (y, (a, b)))
nn (POpts -> String -> PP r (y, (a, b)) -> () -> String
forall a1 a2.
(Show a1, Show a2) =>
POpts -> String -> a1 -> a2 -> String
show3 POpts
opts String
msg1 PP r (y, (a, b))
c ()) [Tree PE]
hhs
            ELeft a
a -> do
              let msg1 :: String
msg1 = String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"(ELeft)"
              TT (PP r (y, (a, b)))
pp <- Proxy p -> POpts -> (y, a) -> m (TT (PP p (y, a)))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy p
forall k (t :: k). Proxy t
Proxy @p) POpts
opts (y
s,a
a)
              TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b))))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b)))))
-> TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b))))
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT (PP r (y, (a, b)))
-> [Tree PE]
-> Either (TT (PP r (y, (a, b)))) (PP r (y, (a, b)))
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" p failed") TT (PP r (y, (a, b)))
pp [Tree PE]
hhs of
                   Left TT (PP r (y, (a, b)))
e -> TT (PP r (y, (a, b)))
e
                   Right PP r (y, (a, b))
c -> POpts
-> TT (PP r (y, (a, b)))
-> String
-> [Tree PE]
-> TT (PP r (y, (a, b)))
forall a. POpts -> TT a -> String -> [Tree PE] -> TT a
mkNodeCopy POpts
opts TT (PP r (y, (a, b)))
pp (POpts -> String -> PP r (y, (a, b)) -> a -> String
forall a1 a2.
(Show a1, Show a2) =>
POpts -> String -> a1 -> a2 -> String
show3 POpts
opts String
msg1 PP r (y, (a, b))
c a
a) [Tree PE]
hhs
            ERight b
b -> do
              let msg1 :: String
msg1 = String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"(ERight)"
              TT (PP r (y, (a, b)))
qq <- Proxy q -> POpts -> (y, b) -> m (TT (PP q (y, b)))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy q
forall k (t :: k). Proxy t
Proxy @q) POpts
opts (y
s,b
b)
              TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b))))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b)))))
-> TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b))))
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT (PP r (y, (a, b)))
-> [Tree PE]
-> Either (TT (PP r (y, (a, b)))) (PP r (y, (a, b)))
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" q failed") TT (PP r (y, (a, b)))
qq [Tree PE]
hhs of
                   Left TT (PP r (y, (a, b)))
e -> TT (PP r (y, (a, b)))
e
                   Right PP r (y, (a, b))
c -> POpts
-> TT (PP r (y, (a, b)))
-> String
-> [Tree PE]
-> TT (PP r (y, (a, b)))
forall a. POpts -> TT a -> String -> [Tree PE] -> TT a
mkNodeCopy POpts
opts TT (PP r (y, (a, b)))
qq (POpts -> String -> PP r (y, (a, b)) -> b -> String
forall a1 a2.
(Show a1, Show a2) =>
POpts -> String -> a1 -> a2 -> String
show3 POpts
opts String
msg1 PP r (y, (a, b))
c b
b) [Tree PE]
hhs
            EBoth a
a b
b -> do
              let msg1 :: String
msg1 = String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"(EBoth)"
              TT (PP r (y, (a, b)))
rr <- Proxy r -> POpts -> (y, (a, b)) -> m (TT (PP r (y, (a, b))))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy r
forall k (t :: k). Proxy t
Proxy @r) POpts
opts (y
s,(a
a,b
b))
              TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b))))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b)))))
-> TT (PP r (y, (a, b))) -> m (TT (PP r (y, (a, b))))
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT (PP r (y, (a, b)))
-> [Tree PE]
-> Either (TT (PP r (y, (a, b)))) (PP r (y, (a, b)))
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" r failed") TT (PP r (y, (a, b)))
rr [Tree PE]
hhs of
                   Left TT (PP r (y, (a, b)))
e -> TT (PP r (y, (a, b)))
e
                   Right PP r (y, (a, b))
c -> POpts
-> TT (PP r (y, (a, b)))
-> String
-> [Tree PE]
-> TT (PP r (y, (a, b)))
forall a. POpts -> TT a -> String -> [Tree PE] -> TT a
mkNodeCopy POpts
opts TT (PP r (y, (a, b)))
rr (POpts -> String -> PP r (y, (a, b)) -> (a, b) -> String
forall a1 a2.
(Show a1, Show a2) =>
POpts -> String -> a1 -> a2 -> String
show3 POpts
opts String
msg1 PP r (y, (a, b))
c (a
a,b
b)) [Tree PE]
hhs

-- | simple version of 'ElrIn' with Id as the Elr value and the environment set to ()

--

-- >>> pz @(ElrId '(999,"oops") '(Id,"fromleft") '(888,Id) Id) (EBoth 222 "ok")

-- Val (222,"ok")

--

-- >>> pz @(ElrId '(999,"oops") '(Id,"fromleft") '(888,Id) Id) (ERight "ok")

-- Val (888,"ok")

--

-- >>> pz @(ElrId '(999,"oops") '(Id,"fromleft") '(888,Id) Id) ENone

-- Val (999,"oops")

--

-- >>> pz @(ElrId '(999,"oops") '(Id,"fromleft") '(888,Id) Id) (ELeft 123)

-- Val (123,"fromleft")

--

-- >>> pl @(ElrId (FailT _ "none found") '(Id,"fromleft") '(888,Id) Id) ENone

-- Error none found (ElrIn(ENone) n failed)

-- Fail "none found"

--

data ElrId n p q r deriving Int -> ElrId n p q r -> ShowS
[ElrId n p q r] -> ShowS
ElrId n p q r -> String
(Int -> ElrId n p q r -> ShowS)
-> (ElrId n p q r -> String)
-> ([ElrId n p q r] -> ShowS)
-> Show (ElrId n p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
Int -> ElrId n p q r -> ShowS
forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
[ElrId n p q r] -> ShowS
forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
ElrId n p q r -> String
showList :: [ElrId n p q r] -> ShowS
$cshowList :: forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
[ElrId n p q r] -> ShowS
show :: ElrId n p q r -> String
$cshow :: forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
ElrId n p q r -> String
showsPrec :: Int -> ElrId n p q r -> ShowS
$cshowsPrec :: forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
Int -> ElrId n p q r -> ShowS
Show

type ElrIdT n p q r = ElrIn n (Snd >> p) (Snd >> q) (Snd >> r) () Id

instance P (ElrIdT n p q r) x => P (ElrId n p q r) x where
  type PP (ElrId n p q r) x = PP (ElrIdT n p q r) x
  eval :: proxy (ElrId n p q r)
-> POpts -> x -> m (TT (PP (ElrId n p q r) x))
eval proxy (ElrId n p q r)
_ = Proxy (ElrIdT n p q r)
-> POpts -> x -> m (TT (PP (ElrIdT n p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ElrIdT n p q r)
forall k (t :: k). Proxy t
Proxy @(ElrIdT n p q r))

-- | creates a pair where the values are filled in by @s@ and @t@ holds the Elr value

--

-- >>> pz @(ElrPair Fst Snd) ((999,"oops"),EBoth 2 "xx")

-- Val (2,"xx")

--

-- >>> pz @(ElrPair Fst Snd) ((999,"oops"),ENone)

-- Val (999,"oops")

--

-- >>> pz @(ElrPair Fst Snd) ((999,"oops"),ERight "ok")

-- Val (999,"ok")

--

data ElrPair s t deriving Int -> ElrPair s t -> ShowS
[ElrPair s t] -> ShowS
ElrPair s t -> String
(Int -> ElrPair s t -> ShowS)
-> (ElrPair s t -> String)
-> ([ElrPair s t] -> ShowS)
-> Show (ElrPair s t)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (s :: k) k (t :: k). Int -> ElrPair s t -> ShowS
forall k (s :: k) k (t :: k). [ElrPair s t] -> ShowS
forall k (s :: k) k (t :: k). ElrPair s t -> String
showList :: [ElrPair s t] -> ShowS
$cshowList :: forall k (s :: k) k (t :: k). [ElrPair s t] -> ShowS
show :: ElrPair s t -> String
$cshow :: forall k (s :: k) k (t :: k). ElrPair s t -> String
showsPrec :: Int -> ElrPair s t -> ShowS
$cshowsPrec :: forall k (s :: k) k (t :: k). Int -> ElrPair s t -> ShowS
Show

type ElrPairT s t = ElrIn Id '(Snd,L12) '(L11,Snd) Snd s t

instance P (ElrPairT s t) x => P (ElrPair s t) x where
  type PP (ElrPair s t) x = PP (ElrPairT s t) x
  eval :: proxy (ElrPair s t) -> POpts -> x -> m (TT (PP (ElrPair s t) x))
eval proxy (ElrPair s t)
_ = Proxy (ElrPairT s t) -> POpts -> x -> m (TT (PP (ElrPairT s t) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ElrPairT s t)
forall k (t :: k). Proxy t
Proxy @(ElrPairT s t))

-- | similar to 'ElrIn' but without an environment @s@ and uses Id for @t@

--

-- >>> pz @(ElrInSimple 999 Id Len (Fst + Length Snd)) (ELeft 13)

-- Val 13

--

-- >>> pz @(ElrInSimple 999 Id Len (Fst + Length Snd)) ENone

-- Val 999

--

-- >>> pz @(ElrInSimple 999 Id Len (Fst + Length Snd)) (ERight "this is a long string")

-- Val 21

--

-- >>> pz @(ElrInSimple 999 Id Len (Fst + Length Snd)) (EBoth 20 "somedata")

-- Val 28

--

-- >>> pz @(ElrInSimple (FailT _ "err") (MkLeft _ Id) (MkRight _ Id) (If (Fst > Length Snd) (MkLeft _ Fst) (MkRight _ Snd))) (ERight "this is a long string")

-- Val (Right "this is a long string")

--

-- >>> pz @(ElrInSimple (FailT _ "err") (MkLeft _ Id) (MkRight _ Id) (If (Fst > Length Snd) (MkLeft _ Fst) (MkRight _ Snd))) ENone

-- Fail "err"

--

-- >>> pz @(ElrInSimple (FailT _ "err") (MkLeft _ Id) (MkRight _ Id) (If (Fst > Length Snd) (MkLeft _ Fst) (MkRight _ Snd))) (EBoth 1 "this is a long string")

-- Val (Right "this is a long string")

--

-- >>> pz @(ElrInSimple (FailT _ "err") (MkLeft _ Id) (MkRight _ Id) (If (Fst > Length Snd) (MkLeft _ Fst) (MkRight _ Snd))) (EBoth 100 "this is a long string")

-- Val (Left 100)

--

-- >>> pl @(ElrInSimple "none" "left" "right" "both") (ELeft (SG.Sum 12))

-- Present "left" (ElrIn(ELeft) "left" | Sum {getSum = 12})

-- Val "left"

--

-- >>> pl @(ElrInSimple (FailT _ "err") (Id &&& 999) ("no value" &&& Id) Id) (EBoth "Ab" 13)

-- Present ("Ab",13) (ElrIn(EBoth) ("Ab",13) | ("Ab",13))

-- Val ("Ab",13)

--

-- >>> pl @(ElrInSimple (FailT _ "err") (Id &&& 999) ("no value" &&& Id) Id) (ELeft "Ab")

-- Present ("Ab",999) (ElrIn(ELeft) ("Ab",999) | "Ab")

-- Val ("Ab",999)

--

-- >>> pl @(ElrInSimple (FailT _ "err") (Id &&& 999) ("no value" &&& Id) Id) (ERight 13)

-- Present ("no value",13) (ElrIn(ERight) ("no value",13) | 13)

-- Val ("no value",13)

--

data ElrInSimple n p q r deriving Int -> ElrInSimple n p q r -> ShowS
[ElrInSimple n p q r] -> ShowS
ElrInSimple n p q r -> String
(Int -> ElrInSimple n p q r -> ShowS)
-> (ElrInSimple n p q r -> String)
-> ([ElrInSimple n p q r] -> ShowS)
-> Show (ElrInSimple n p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
Int -> ElrInSimple n p q r -> ShowS
forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
[ElrInSimple n p q r] -> ShowS
forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
ElrInSimple n p q r -> String
showList :: [ElrInSimple n p q r] -> ShowS
$cshowList :: forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
[ElrInSimple n p q r] -> ShowS
show :: ElrInSimple n p q r -> String
$cshow :: forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
ElrInSimple n p q r -> String
showsPrec :: Int -> ElrInSimple n p q r -> ShowS
$cshowsPrec :: forall k (n :: k) k (p :: k) k (q :: k) k (r :: k).
Int -> ElrInSimple n p q r -> ShowS
Show

type ElrInSimpleT n p q r = ElrIn n (Snd >> p) (Snd >> q) (Snd >> r) () Id

instance P (ElrInSimpleT n p q r) x => P (ElrInSimple n p q r) x where
  type PP (ElrInSimple n p q r) x = PP (ElrInSimpleT n p q r) x
  eval :: proxy (ElrInSimple n p q r)
-> POpts -> x -> m (TT (PP (ElrInSimple n p q r) x))
eval proxy (ElrInSimple n p q r)
_ = Proxy (ElrInSimpleT n p q r)
-> POpts -> x -> m (TT (PP (ElrInSimpleT n p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ElrInSimpleT n p q r)
forall k (t :: k). Proxy t
Proxy @(ElrInSimpleT n p q r))

-- | get ENone or run @p@: really only useful when p is set to Fail: where @q@ is the environment and @r@ is the Elr value

--

-- >>> pz @(ENoneDef (FailT _ "not ENone") () Id) ENone

-- Val ()

--

-- >>> pz @(ENoneDef (FailT _ "not ENone") () Id) (ELeft 1)

-- Fail "not ENone"

--

-- >>> pz @(ENoneDef (FailT _ Id) Fst Snd) ("not right",EBoth 1 2)

-- Fail "not right"

--

data ENoneDef p q r deriving Int -> ENoneDef p q r -> ShowS
[ENoneDef p q r] -> ShowS
ENoneDef p q r -> String
(Int -> ENoneDef p q r -> ShowS)
-> (ENoneDef p q r -> String)
-> ([ENoneDef p q r] -> ShowS)
-> Show (ENoneDef p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k) k (q :: k) k (r :: k).
Int -> ENoneDef p q r -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). [ENoneDef p q r] -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). ENoneDef p q r -> String
showList :: [ENoneDef p q r] -> ShowS
$cshowList :: forall k (p :: k) k (q :: k) k (r :: k). [ENoneDef p q r] -> ShowS
show :: ENoneDef p q r -> String
$cshow :: forall k (p :: k) k (q :: k) k (r :: k). ENoneDef p q r -> String
showsPrec :: Int -> ENoneDef p q r -> ShowS
$cshowsPrec :: forall k (p :: k) k (q :: k) k (r :: k).
Int -> ENoneDef p q r -> ShowS
Show

type ENoneDefT p q r = ElrIn Id (Fst >> p) (Fst >> p) (Fst >> p) q r

instance P (ENoneDefT p q r) x => P (ENoneDef p q r) x where
  type PP (ENoneDef p q r) x = PP (ENoneDefT p q r) x
  eval :: proxy (ENoneDef p q r)
-> POpts -> x -> m (TT (PP (ENoneDef p q r) x))
eval proxy (ENoneDef p q r)
_ = Proxy (ENoneDefT p q r)
-> POpts -> x -> m (TT (PP (ENoneDefT p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ENoneDefT p q r)
forall k (t :: k). Proxy t
Proxy @(ENoneDefT p q r))

-- | get ELeft or use the default value @p@: @q@ is the environment and @r@ is the Elr value

--

-- >>> pz @(ELeftDef Id Fst Snd) (999,ENone)

-- Val 999

--

-- >>> pz @(ELeftDef 999 () Id) (ERight "sdf")

-- Val 999

--

-- >>> pz @(ELeftDef 999 () Id) (ELeft 1)

-- Val 1

--

data ELeftDef p q r deriving Int -> ELeftDef p q r -> ShowS
[ELeftDef p q r] -> ShowS
ELeftDef p q r -> String
(Int -> ELeftDef p q r -> ShowS)
-> (ELeftDef p q r -> String)
-> ([ELeftDef p q r] -> ShowS)
-> Show (ELeftDef p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k) k (q :: k) k (r :: k).
Int -> ELeftDef p q r -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). [ELeftDef p q r] -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). ELeftDef p q r -> String
showList :: [ELeftDef p q r] -> ShowS
$cshowList :: forall k (p :: k) k (q :: k) k (r :: k). [ELeftDef p q r] -> ShowS
show :: ELeftDef p q r -> String
$cshow :: forall k (p :: k) k (q :: k) k (r :: k). ELeftDef p q r -> String
showsPrec :: Int -> ELeftDef p q r -> ShowS
$cshowsPrec :: forall k (p :: k) k (q :: k) k (r :: k).
Int -> ELeftDef p q r -> ShowS
Show

type ELeftDefT p q r = ElrIn p Snd (Fst >> p) (Fst >> p) q r

instance P (ELeftDefT p q r) x => P (ELeftDef p q r) x where
  type PP (ELeftDef p q r) x = PP (ELeftDefT p q r) x
  eval :: proxy (ELeftDef p q r)
-> POpts -> x -> m (TT (PP (ELeftDef p q r) x))
eval proxy (ELeftDef p q r)
_ = Proxy (ELeftDefT p q r)
-> POpts -> x -> m (TT (PP (ELeftDefT p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ELeftDefT p q r)
forall k (t :: k). Proxy t
Proxy @(ELeftDefT p q r))

-- | get ERight or use the default value @p@: @q@ is the environment and @r@ is the Elr value

--

-- >>> pz @(ERightDef 999 () Id) ENone

-- Val 999

--

-- >>> pz @(ERightDef 999 () Id) (ELeft "sdf")

-- Val 999

--

-- >>> pz @(ERightDef 999 Fst Snd) (999,ERight 1)

-- Val 1

--

data ERightDef p q r deriving Int -> ERightDef p q r -> ShowS
[ERightDef p q r] -> ShowS
ERightDef p q r -> String
(Int -> ERightDef p q r -> ShowS)
-> (ERightDef p q r -> String)
-> ([ERightDef p q r] -> ShowS)
-> Show (ERightDef p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k) k (q :: k) k (r :: k).
Int -> ERightDef p q r -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). [ERightDef p q r] -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). ERightDef p q r -> String
showList :: [ERightDef p q r] -> ShowS
$cshowList :: forall k (p :: k) k (q :: k) k (r :: k). [ERightDef p q r] -> ShowS
show :: ERightDef p q r -> String
$cshow :: forall k (p :: k) k (q :: k) k (r :: k). ERightDef p q r -> String
showsPrec :: Int -> ERightDef p q r -> ShowS
$cshowsPrec :: forall k (p :: k) k (q :: k) k (r :: k).
Int -> ERightDef p q r -> ShowS
Show

type ERightDefT p q r = ElrIn p (Fst >> p) Snd (Fst >> p) q r

instance P (ERightDefT p q r) x => P (ERightDef p q r) x where
  type PP (ERightDef p q r) x = PP (ERightDefT p q r) x
  eval :: proxy (ERightDef p q r)
-> POpts -> x -> m (TT (PP (ERightDef p q r) x))
eval proxy (ERightDef p q r)
_ = Proxy (ERightDefT p q r)
-> POpts -> x -> m (TT (PP (ERightDefT p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ERightDefT p q r)
forall k (t :: k). Proxy t
Proxy @(ERightDefT p q r))

-- | get EBoth or use the default value @p@: @q@ is the environment and @r@ is the Elr value

--

-- >>> pz @(EBothDef '(999,"xx") () Id) ENone

-- Val (999,"xx")

--

-- >>> pz @(EBothDef '(999,"xx") () Id) (ERight "abc")

-- Val (999,"xx")

--

-- >>> pz @(EBothDef '(999,"xx") () Id) (ELeft 1)

-- Val (999,"xx")

--

-- >>> pz @(EBothDef '(999,"xx") () Id) (EBoth 1 "abc")

-- Val (1,"abc")

--

-- >>> pz @(EBothDef Id Fst Snd) ((999,"xx"),ENone)

-- Val (999,"xx")

--

data EBothDef p q r deriving Int -> EBothDef p q r -> ShowS
[EBothDef p q r] -> ShowS
EBothDef p q r -> String
(Int -> EBothDef p q r -> ShowS)
-> (EBothDef p q r -> String)
-> ([EBothDef p q r] -> ShowS)
-> Show (EBothDef p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k) k (q :: k) k (r :: k).
Int -> EBothDef p q r -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). [EBothDef p q r] -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). EBothDef p q r -> String
showList :: [EBothDef p q r] -> ShowS
$cshowList :: forall k (p :: k) k (q :: k) k (r :: k). [EBothDef p q r] -> ShowS
show :: EBothDef p q r -> String
$cshow :: forall k (p :: k) k (q :: k) k (r :: k). EBothDef p q r -> String
showsPrec :: Int -> EBothDef p q r -> ShowS
$cshowsPrec :: forall k (p :: k) k (q :: k) k (r :: k).
Int -> EBothDef p q r -> ShowS
Show

type EBothDefT p q r = ElrIn p (Fst >> p) (Fst >> p) Snd q r

instance P (EBothDefT p q r) x => P (EBothDef p q r) x where
  type PP (EBothDef p q r) x = PP (EBothDefT p q r) x
  eval :: proxy (EBothDef p q r)
-> POpts -> x -> m (TT (PP (EBothDef p q r) x))
eval proxy (EBothDef p q r)
_ = Proxy (EBothDefT p q r)
-> POpts -> x -> m (TT (PP (EBothDefT p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (EBothDefT p q r)
forall k (t :: k). Proxy t
Proxy @(EBothDefT p q r))

-- | converts 'Elr' to 'These'

--

-- >>> pz @Elr2These ENone

-- Val Nothing

--

-- >>> pz @Elr2These (ELeft 123)

-- Val (Just (This 123))

--

data Elr2These deriving Int -> Elr2These -> ShowS
[Elr2These] -> ShowS
Elr2These -> String
(Int -> Elr2These -> ShowS)
-> (Elr2These -> String)
-> ([Elr2These] -> ShowS)
-> Show Elr2These
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Elr2These] -> ShowS
$cshowList :: [Elr2These] -> ShowS
show :: Elr2These -> String
$cshow :: Elr2These -> String
showsPrec :: Int -> Elr2These -> ShowS
$cshowsPrec :: Int -> Elr2These -> ShowS
Show

instance P Elr2These (Elr a b) where
  type PP Elr2These (Elr a b) = Maybe (These a b)
  eval :: proxy Elr2These
-> POpts -> Elr a b -> m (TT (PP Elr2These (Elr a b)))
eval proxy Elr2These
_ POpts
opts Elr a b
x =
    let msg0 :: String
msg0 = String
"Elr2These"
        b :: Maybe (These a b)
b = Elr a b
x Elr a b
-> Getting (Maybe (These a b)) (Elr a b) (Maybe (These a b))
-> Maybe (These a b)
forall s a. s -> Getting a s a -> a
^. Getting (Maybe (These a b)) (Elr a b) (Maybe (These a b))
forall a b a' b'.
Iso (Elr a b) (Elr a' b') (Maybe (These a b)) (Maybe (These a' b'))
_elr2These
    in TT (Maybe (These a b)) -> m (TT (Maybe (These a b)))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (Maybe (These a b)) -> m (TT (Maybe (These a b))))
-> TT (Maybe (These a b)) -> m (TT (Maybe (These a b)))
forall a b. (a -> b) -> a -> b
$ POpts
-> Val (Maybe (These a b))
-> String
-> [Tree PE]
-> TT (Maybe (These a b))
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (Maybe (These a b) -> Val (Maybe (These a b))
forall a. a -> Val a
Val Maybe (These a b)
b) String
msg0 []

-- | converts 'These' to 'Elr'

--

-- >>> pz @These2Elr (These 12 'x')

-- Val (EBoth 12 'x')

--

-- >>> pz @These2Elr (This 123)

-- Val (ELeft 123)

--

data These2Elr deriving Int -> These2Elr -> ShowS
[These2Elr] -> ShowS
These2Elr -> String
(Int -> These2Elr -> ShowS)
-> (These2Elr -> String)
-> ([These2Elr] -> ShowS)
-> Show These2Elr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [These2Elr] -> ShowS
$cshowList :: [These2Elr] -> ShowS
show :: These2Elr -> String
$cshow :: These2Elr -> String
showsPrec :: Int -> These2Elr -> ShowS
$cshowsPrec :: Int -> These2Elr -> ShowS
Show

instance P These2Elr (These a b) where
  type PP These2Elr (These a b) = Elr a b
  eval :: proxy These2Elr
-> POpts -> These a b -> m (TT (PP These2Elr (These a b)))
eval proxy These2Elr
_ POpts
opts These a b
x =
    let msg0 :: String
msg0 = String
"These2Elr"
        b :: Elr a b
b = Tagged (Maybe (These a b)) (Identity (Maybe (These a b)))
-> Tagged (Elr a b) (Identity (Elr a b))
forall a b a' b'.
Iso (Elr a b) (Elr a' b') (Maybe (These a b)) (Maybe (These a' b'))
_elr2These (Tagged (Maybe (These a b)) (Identity (Maybe (These a b)))
 -> Tagged (Elr a b) (Identity (Elr a b)))
-> Maybe (These a b) -> Elr a b
forall t b. AReview t b -> b -> t
# These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just These a b
x
    in TT (Elr a b) -> m (TT (Elr a b))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (Elr a b) -> m (TT (Elr a b)))
-> TT (Elr a b) -> m (TT (Elr a b))
forall a b. (a -> b) -> a -> b
$ POpts -> Val (Elr a b) -> String -> [Tree PE] -> TT (Elr a b)
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (Elr a b -> Val (Elr a b)
forall a. a -> Val a
Val Elr a b
b) String
msg0 []

-- | converts 'Elr' to a pair of Maybes

--

-- >>> pz @Elr2Maybe ENone

-- Val (Nothing,Nothing)

--

-- >>> pz @Elr2Maybe (ELeft 123)

-- Val (Just 123,Nothing)

--

-- >>> pz @Elr2Maybe (EBoth 'x' 123)

-- Val (Just 'x',Just 123)

--

-- >>> pz @Elr2Maybe (ERight 123)

-- Val (Nothing,Just 123)

--

data Elr2Maybe deriving Int -> Elr2Maybe -> ShowS
[Elr2Maybe] -> ShowS
Elr2Maybe -> String
(Int -> Elr2Maybe -> ShowS)
-> (Elr2Maybe -> String)
-> ([Elr2Maybe] -> ShowS)
-> Show Elr2Maybe
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Elr2Maybe] -> ShowS
$cshowList :: [Elr2Maybe] -> ShowS
show :: Elr2Maybe -> String
$cshow :: Elr2Maybe -> String
showsPrec :: Int -> Elr2Maybe -> ShowS
$cshowsPrec :: Int -> Elr2Maybe -> ShowS
Show

instance P Elr2Maybe (Elr a b) where
  type PP Elr2Maybe (Elr a b) = (Maybe a, Maybe b)
  eval :: proxy Elr2Maybe
-> POpts -> Elr a b -> m (TT (PP Elr2Maybe (Elr a b)))
eval proxy Elr2Maybe
_ POpts
opts Elr a b
x =
    let msg0 :: String
msg0 = String
"Elr2Maybe"
        b :: (Maybe a, Maybe b)
b = Elr a b
x Elr a b
-> Getting (Maybe a, Maybe b) (Elr a b) (Maybe a, Maybe b)
-> (Maybe a, Maybe b)
forall s a. s -> Getting a s a -> a
^. Getting (Maybe a, Maybe b) (Elr a b) (Maybe a, Maybe b)
forall a b a' b'.
Iso (Elr a b) (Elr a' b') (Maybe a, Maybe b) (Maybe a', Maybe b')
_elr2Maybe
    in TT (Maybe a, Maybe b) -> m (TT (Maybe a, Maybe b))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT (Maybe a, Maybe b) -> m (TT (Maybe a, Maybe b)))
-> TT (Maybe a, Maybe b) -> m (TT (Maybe a, Maybe b))
forall a b. (a -> b) -> a -> b
$ POpts
-> Val (Maybe a, Maybe b)
-> String
-> [Tree PE]
-> TT (Maybe a, Maybe b)
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts ((Maybe a, Maybe b) -> Val (Maybe a, Maybe b)
forall a. a -> Val a
Val (Maybe a, Maybe b)
b) String
msg0 []