{-# OPTIONS_HADDOCK hide, not-home #-}
module Data.HFunctor.Chain.Internal (
Chain1(..)
, foldChain1, unfoldChain1
, foldChain1A
, toChain1, injectChain1
, matchChain1
, Chain(..)
, foldChain, unfoldChain
, foldChainA
, splittingChain, unconsChain
, DivAp1(..)
, DivAp(..)
, DecAlt(..)
, DecAlt1(..)
) where
import Control.Monad.Freer.Church
import Control.Natural
import Control.Natural.IsoF
import Data.Functor.Apply
import Data.Functor.Classes
import Data.Functor.Contravariant
import Data.Functor.Identity
import Data.Functor.Invariant
import Data.Functor.Invariant.Internative
import Data.HBifunctor
import Data.HFunctor
import Data.HFunctor.Interpret
import Data.HFunctor.HTraversable
import Data.Kind
import Data.Typeable
import Data.Void
import GHC.Generics
import qualified Data.Functor.Invariant.Day as ID
import qualified Data.Functor.Invariant.Night as IN
data Chain1 t f a = Done1 (f a)
| More1 (t f (Chain1 t f) a)
deriving (Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k) x.
Rep (Chain1 t f a) x -> Chain1 t f a
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k) x.
Chain1 t f a -> Rep (Chain1 t f a) x
$cto :: forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k) x.
Rep (Chain1 t f a) x -> Chain1 t f a
$cfrom :: forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k) x.
Chain1 t f a -> Rep (Chain1 t f a) x
Generic)
deriving instance (Eq (f a), Eq (t f (Chain1 t f) a)) => Eq (Chain1 t f a)
deriving instance (Ord (f a), Ord (t f (Chain1 t f) a)) => Ord (Chain1 t f a)
deriving instance (Show (f a), Show (t f (Chain1 t f) a)) => Show (Chain1 t f a)
deriving instance (Read (f a), Read (t f (Chain1 t f) a)) => Read (Chain1 t f a)
deriving instance (Functor f, Functor (t f (Chain1 t f))) => Functor (Chain1 t f)
deriving instance (Foldable f, Foldable (t f (Chain1 t f))) => Foldable (Chain1 t f)
deriving instance (Traversable f, Traversable (t f (Chain1 t f))) => Traversable (Chain1 t f)
instance (Eq1 f, Eq1 (t f (Chain1 t f))) => Eq1 (Chain1 t f) where
liftEq :: forall a b.
(a -> b -> Bool) -> Chain1 t f a -> Chain1 t f b -> Bool
liftEq a -> b -> Bool
eq = \case
Done1 f a
x -> \case
Done1 f b
y -> forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq f a
x f b
y
More1 t f (Chain1 t f) b
_ -> Bool
False
More1 t f (Chain1 t f) a
x -> \case
Done1 f b
_ -> Bool
False
More1 t f (Chain1 t f) b
y -> forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq t f (Chain1 t f) a
x t f (Chain1 t f) b
y
instance (Ord1 f, Ord1 (t f (Chain1 t f))) => Ord1 (Chain1 t f) where
liftCompare :: forall a b.
(a -> b -> Ordering) -> Chain1 t f a -> Chain1 t f b -> Ordering
liftCompare a -> b -> Ordering
c = \case
Done1 f a
x -> \case
Done1 f b
y -> forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
c f a
x f b
y
More1 t f (Chain1 t f) b
_ -> Ordering
LT
More1 t f (Chain1 t f) a
x -> \case
Done1 f b
_ -> Ordering
GT
More1 t f (Chain1 t f) b
y -> forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
c t f (Chain1 t f) a
x t f (Chain1 t f) b
y
instance (Show1 (t f (Chain1 t f)), Show1 f) => Show1 (Chain1 t f) where
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Chain1 t f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl Int
d = \case
Done1 f a
x -> forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) String
"Done1" Int
d f a
x
More1 t f (Chain1 t f) a
xs -> forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) String
"More1" Int
d t f (Chain1 t f) a
xs
instance (Functor f, Read1 (t f (Chain1 t f)), Read1 f) => Read1 (Chain1 t f) where
liftReadsPrec :: forall a.
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Chain1 t f a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
rl = forall a. (String -> ReadS a) -> Int -> ReadS a
readsData forall a b. (a -> b) -> a -> b
$
forall a t.
(Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
readsUnaryWith (forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
rl) String
"Done1" forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1
forall a. Semigroup a => a -> a -> a
<> forall a t.
(Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
readsUnaryWith (forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
rl) String
"More1" forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1
instance (Contravariant f, Contravariant (t f (Chain1 t f))) => Contravariant (Chain1 t f) where
contramap :: forall a' a. (a' -> a) -> Chain1 t f a -> Chain1 t f a'
contramap a' -> a
f = \case
Done1 f a
x -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1 (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f f a
x )
More1 t f (Chain1 t f) a
xs -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f t f (Chain1 t f) a
xs)
instance (Invariant f, Invariant (t f (Chain1 t f))) => Invariant (Chain1 t f) where
invmap :: forall a b. (a -> b) -> (b -> a) -> Chain1 t f a -> Chain1 t f b
invmap a -> b
f b -> a
g = \case
Done1 f a
x -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1 (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
x )
More1 t f (Chain1 t f) a
xs -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g t f (Chain1 t f) a
xs)
instance HBifunctor t => HFunctor (Chain1 t) where
hmap :: forall (f :: k1 -> *) (g :: k1 -> *).
(f ~> g) -> Chain1 t f ~> Chain1 t g
hmap f ~> g
f = forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(g :: k -> *).
HBifunctor t =>
(f ~> g) -> (t f g ~> g) -> Chain1 t f ~> g
foldChain1 (forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. f ~> g
f) (forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(j :: k -> *) (g :: k -> *).
HBifunctor t =>
(f ~> j) -> t f g ~> t j g
hleft f ~> g
f)
instance HBifunctor t => Inject (Chain1 t) where
inject :: forall (f :: k -> *). f ~> Chain1 t f
inject = forall {k} (f :: k -> *) (t :: (k -> *) -> (k -> *) -> k -> *).
f ~> Chain1 t f
injectChain1
foldChain1
:: forall t f g. HBifunctor t
=> f ~> g
-> t f g ~> g
-> Chain1 t f ~> g
foldChain1 :: forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(g :: k -> *).
HBifunctor t =>
(f ~> g) -> (t f g ~> g) -> Chain1 t f ~> g
foldChain1 f ~> g
f t f g ~> g
g = Chain1 t f ~> g
go
where
go :: Chain1 t f ~> g
go :: Chain1 t f ~> g
go = \case
Done1 f x
x -> f ~> g
f f x
x
More1 t f (Chain1 t f) x
xs -> t f g ~> g
g (forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
(l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright Chain1 t f ~> g
go t f (Chain1 t f) x
xs)
foldChain1A
:: (HBifunctor t, Functor h)
=> (forall x. f x -> h (g x))
-> (forall x. t f (Comp h g) x -> h (g x))
-> Chain1 t f a
-> h (g a)
foldChain1A :: forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (h :: * -> *)
(f :: k -> *) (g :: k -> *) (a :: k).
(HBifunctor t, Functor h) =>
(forall (x :: k). f x -> h (g x))
-> (forall (x :: k). t f (Comp h g) x -> h (g x))
-> Chain1 t f a
-> h (g a)
foldChain1A forall (x :: k). f x -> h (g x)
f forall (x :: k). t f (Comp h g) x -> h (g x)
g = forall {k} (f :: * -> *) (g :: k -> *) (a :: k).
Functor f =>
Comp f g a -> f (g a)
unComp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(g :: k -> *).
HBifunctor t =>
(f ~> g) -> (t f g ~> g) -> Chain1 t f ~> g
foldChain1 (forall {k} (f :: * -> *) (g :: k -> *) (a :: k).
Functor f =>
f (g a) -> Comp f g a
Comp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (x :: k). f x -> h (g x)
f) (forall {k} (f :: * -> *) (g :: k -> *) (a :: k).
Functor f =>
f (g a) -> Comp f g a
Comp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (x :: k). t f (Comp h g) x -> h (g x)
g)
unfoldChain1
:: forall t f (g :: Type -> Type). HBifunctor t
=> (g ~> f :+: t f g)
-> g ~> Chain1 t f
unfoldChain1 :: forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
(g :: * -> *).
HBifunctor t =>
(g ~> (f :+: t f g)) -> g ~> Chain1 t f
unfoldChain1 g ~> (f :+: t f g)
f = g ~> Chain1 t f
go
where
go :: g ~> Chain1 t f
go :: g ~> Chain1 t f
go = (\case L1 f x
x -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1 f x
x; R1 t f g x
y -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
(l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright g ~> Chain1 t f
go t f g x
y)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. g ~> (f :+: t f g)
f
toChain1 :: HBifunctor t => t f f ~> Chain1 t f
toChain1 :: forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *).
HBifunctor t =>
t f f ~> Chain1 t f
toChain1 = forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
(l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1
injectChain1 :: f ~> Chain1 t f
injectChain1 :: forall {k} (f :: k -> *) (t :: (k -> *) -> (k -> *) -> k -> *).
f ~> Chain1 t f
injectChain1 = forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1
matchChain1 :: Chain1 t f ~> (f :+: t f (Chain1 t f))
matchChain1 :: forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *).
Chain1 t f ~> (f :+: t f (Chain1 t f))
matchChain1 = \case
Done1 f x
x -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f x
x
More1 t f (Chain1 t f) x
xs -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 t f (Chain1 t f) x
xs
data Chain t i f a = Done (i a)
| More (t f (Chain t i f) a)
deriving instance (Eq (i a), Eq (t f (Chain t i f) a)) => Eq (Chain t i f a)
deriving instance (Ord (i a), Ord (t f (Chain t i f) a)) => Ord (Chain t i f a)
deriving instance (Show (i a), Show (t f (Chain t i f) a)) => Show (Chain t i f a)
deriving instance (Read (i a), Read (t f (Chain t i f) a)) => Read (Chain t i f a)
deriving instance (Functor i, Functor (t f (Chain t i f))) => Functor (Chain t i f)
deriving instance (Foldable i, Foldable (t f (Chain t i f))) => Foldable (Chain t i f)
deriving instance (Traversable i, Traversable (t f (Chain t i f))) => Traversable (Chain t i f)
instance (Eq1 i, Eq1 (t f (Chain t i f))) => Eq1 (Chain t i f) where
liftEq :: forall a b.
(a -> b -> Bool) -> Chain t i f a -> Chain t i f b -> Bool
liftEq a -> b -> Bool
eq = \case
Done i a
x -> \case
Done i b
y -> forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq i a
x i b
y
More t f (Chain t i f) b
_ -> Bool
False
More t f (Chain t i f) a
x -> \case
Done i b
_ -> Bool
False
More t f (Chain t i f) b
y -> forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq t f (Chain t i f) a
x t f (Chain t i f) b
y
instance (Ord1 i, Ord1 (t f (Chain t i f))) => Ord1 (Chain t i f) where
liftCompare :: forall a b.
(a -> b -> Ordering) -> Chain t i f a -> Chain t i f b -> Ordering
liftCompare a -> b -> Ordering
c = \case
Done i a
x -> \case
Done i b
y -> forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
c i a
x i b
y
More t f (Chain t i f) b
_ -> Ordering
LT
More t f (Chain t i f) a
x -> \case
Done i b
_ -> Ordering
GT
More t f (Chain t i f) b
y -> forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
c t f (Chain t i f) a
x t f (Chain t i f) b
y
instance (Show1 (t f (Chain t i f)), Show1 i) => Show1 (Chain t i f) where
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Chain t i f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl Int
d = \case
Done i a
x -> forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) String
"Done" Int
d i a
x
More t f (Chain t i f) a
xs -> forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) String
"More" Int
d t f (Chain t i f) a
xs
instance (Functor i, Read1 (t f (Chain t i f)), Read1 i) => Read1 (Chain t i f) where
liftReadsPrec :: forall a.
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Chain t i f a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
rl = forall a. (String -> ReadS a) -> Int -> ReadS a
readsData forall a b. (a -> b) -> a -> b
$
forall a t.
(Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
readsUnaryWith (forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
rl) String
"Done" forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done
forall a. Semigroup a => a -> a -> a
<> forall a t.
(Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
readsUnaryWith (forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
rl) String
"More" forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More
instance (Contravariant i, Contravariant (t f (Chain t i f))) => Contravariant (Chain t i f) where
contramap :: forall a' a. (a' -> a) -> Chain t i f a -> Chain t i f a'
contramap a' -> a
f = \case
Done i a
x -> forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f i a
x )
More t f (Chain t i f) a
xs -> forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f t f (Chain t i f) a
xs)
instance (Invariant i, Invariant (t f (Chain t i f))) => Invariant (Chain t i f) where
invmap :: forall a b. (a -> b) -> (b -> a) -> Chain t i f a -> Chain t i f b
invmap a -> b
f b -> a
g = \case
Done i a
x -> forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g i a
x )
More t f (Chain t i f) a
xs -> forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g t f (Chain t i f) a
xs)
instance HBifunctor t => HFunctor (Chain t i) where
hmap :: forall (f :: k1 -> *) (g :: k1 -> *).
(f ~> g) -> Chain t i f ~> Chain t i g
hmap f ~> g
f = forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k -> *) (g :: k -> *).
HBifunctor t =>
(i ~> g) -> (t f g ~> g) -> Chain t i f ~> g
foldChain forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done (forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(j :: k -> *) (g :: k -> *).
HBifunctor t =>
(f ~> j) -> t f g ~> t j g
hleft f ~> g
f)
foldChain
:: forall t i f g. HBifunctor t
=> (i ~> g)
-> (t f g ~> g)
-> Chain t i f ~> g
foldChain :: forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k -> *) (g :: k -> *).
HBifunctor t =>
(i ~> g) -> (t f g ~> g) -> Chain t i f ~> g
foldChain i ~> g
f t f g ~> g
g = Chain t i f ~> g
go
where
go :: Chain t i f ~> g
go :: Chain t i f ~> g
go = \case
Done i x
x -> i ~> g
f i x
x
More t f (Chain t i f) x
xs -> t f g ~> g
g (forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
(l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright Chain t i f ~> g
go t f (Chain t i f) x
xs)
foldChainA
:: (HBifunctor t, Functor h)
=> (forall x. i x -> h (g x))
-> (forall x. t f (Comp h g) x -> h (g x))
-> Chain t i f a
-> h (g a)
foldChainA :: forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (h :: * -> *)
(i :: k -> *) (g :: k -> *) (f :: k -> *) (a :: k).
(HBifunctor t, Functor h) =>
(forall (x :: k). i x -> h (g x))
-> (forall (x :: k). t f (Comp h g) x -> h (g x))
-> Chain t i f a
-> h (g a)
foldChainA forall (x :: k). i x -> h (g x)
f forall (x :: k). t f (Comp h g) x -> h (g x)
g = forall {k} (f :: * -> *) (g :: k -> *) (a :: k).
Functor f =>
Comp f g a -> f (g a)
unComp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k -> *) (g :: k -> *).
HBifunctor t =>
(i ~> g) -> (t f g ~> g) -> Chain t i f ~> g
foldChain (forall {k} (f :: * -> *) (g :: k -> *) (a :: k).
Functor f =>
f (g a) -> Comp f g a
Comp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (x :: k). i x -> h (g x)
f) (forall {k} (f :: * -> *) (g :: k -> *) (a :: k).
Functor f =>
f (g a) -> Comp f g a
Comp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (x :: k). t f (Comp h g) x -> h (g x)
g)
unfoldChain
:: forall t f (g :: Type -> Type) i. HBifunctor t
=> (g ~> i :+: t f g)
-> g ~> Chain t i f
unfoldChain :: forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
(g :: * -> *) (i :: * -> *).
HBifunctor t =>
(g ~> (i :+: t f g)) -> g ~> Chain t i f
unfoldChain g ~> (i :+: t f g)
f = forall a. g a -> Chain t i f a
go
where
go :: g a -> Chain t i f a
go :: forall a. g a -> Chain t i f a
go = (\case L1 i a
x -> forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done i a
x; R1 t f g a
y -> forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More (forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
(l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright forall a. g a -> Chain t i f a
go t f g a
y)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. g ~> (i :+: t f g)
f
splittingChain :: Chain t i f <~> (i :+: t f (Chain t i f))
splittingChain :: forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k).
Chain t i f <~> (i :+: t f (Chain t i f))
splittingChain = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k).
Chain t i f ~> (i :+: t f (Chain t i f))
unconsChain forall a b. (a -> b) -> a -> b
$ \case
L1 i x
x -> forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done i x
x
R1 t f (Chain t i f) x
xs -> forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More t f (Chain t i f) x
xs
unconsChain :: Chain t i f ~> i :+: t f (Chain t i f)
unconsChain :: forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k).
Chain t i f ~> (i :+: t f (Chain t i f))
unconsChain = \case
Done i x
x -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 i x
x
More t f (Chain t i f) x
xs -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 t f (Chain t i f) x
xs
newtype DivAp1 f a = DivAp1_ { forall (f :: * -> *) a. DivAp1 f a -> Chain1 Day f a
unDivAp1 :: Chain1 ID.Day f a }
deriving (forall a b. (a -> b) -> (b -> a) -> DivAp1 f a -> DivAp1 f b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> DivAp1 f a -> DivAp1 f b
forall (f :: * -> *).
(forall a b. (a -> b) -> (b -> a) -> f a -> f b) -> Invariant f
invmap :: forall a b. (a -> b) -> (b -> a) -> DivAp1 f a -> DivAp1 f b
$cinvmap :: forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> DivAp1 f a -> DivAp1 f b
Invariant, forall {k} {k1} (t :: (k -> *) -> k1 -> *).
(forall (f :: k -> *) (g :: k -> *). (f ~> g) -> t f ~> t g)
-> HFunctor t
forall (f :: * -> *) (g :: * -> *).
(f ~> g) -> DivAp1 f ~> DivAp1 g
hmap :: forall (f :: * -> *) (g :: * -> *).
(f ~> g) -> DivAp1 f ~> DivAp1 g
$chmap :: forall (f :: * -> *) (g :: * -> *).
(f ~> g) -> DivAp1 f ~> DivAp1 g
HFunctor, HFunctor DivAp1
forall {k} (t :: (k -> *) -> k -> *).
HFunctor t -> (forall (f :: k -> *). f ~> t f) -> Inject t
forall (f :: * -> *) x. f x -> DivAp1 f x
inject :: forall (f :: * -> *) x. f x -> DivAp1 f x
$cinject :: forall (f :: * -> *) x. f x -> DivAp1 f x
Inject)
instance HTraversable DivAp1 where
htraverse :: forall (h :: * -> *) (f :: * -> *) (g :: * -> *) a.
Applicative h =>
(forall x. f x -> h (g x)) -> DivAp1 f a -> h (DivAp1 g a)
htraverse forall x. f x -> h (g x)
f =
forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (h :: * -> *)
(f :: k -> *) (g :: k -> *) (a :: k).
(HBifunctor t, Functor h) =>
(forall (x :: k). f x -> h (g x))
-> (forall (x :: k). t f (Comp h g) x -> h (g x))
-> Chain1 t f a
-> h (g a)
foldChain1A
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a. Chain1 Day f a -> DivAp1 f a
DivAp1_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. f x -> h (g x)
f)
(\case ID.Day f b
x (Comp h (DivAp1 g c)
y) b -> c -> x
g x -> (b, c)
h ->
(\g b
x' Chain1 Day g c
y' -> forall (f :: * -> *) a. Chain1 Day f a -> DivAp1 f a
DivAp1_ (forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (b -> c -> a) -> (a -> (b, c)) -> Day f g a
ID.Day g b
x' Chain1 Day g c
y' b -> c -> x
g x -> (b, c)
h)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall x. f x -> h (g x)
f f b
x forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (f :: * -> *) a. DivAp1 f a -> Chain1 Day f a
unDivAp1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> h (DivAp1 g c)
y)
)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. DivAp1 f a -> Chain1 Day f a
unDivAp1
instance HTraversable1 DivAp1 where
htraverse1 :: forall (h :: * -> *) (f :: * -> *) (g :: * -> *) a.
Apply h =>
(forall x. f x -> h (g x)) -> DivAp1 f a -> h (DivAp1 g a)
htraverse1 forall x. f x -> h (g x)
f =
forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (h :: * -> *)
(f :: k -> *) (g :: k -> *) (a :: k).
(HBifunctor t, Functor h) =>
(forall (x :: k). f x -> h (g x))
-> (forall (x :: k). t f (Comp h g) x -> h (g x))
-> Chain1 t f a
-> h (g a)
foldChain1A
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a. Chain1 Day f a -> DivAp1 f a
DivAp1_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. f x -> h (g x)
f)
(\case ID.Day f b
x (Comp h (DivAp1 g c)
y) b -> c -> x
g x -> (b, c)
h ->
(\g b
x' Chain1 Day g c
y' -> forall (f :: * -> *) a. Chain1 Day f a -> DivAp1 f a
DivAp1_ (forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (b -> c -> a) -> (a -> (b, c)) -> Day f g a
ID.Day g b
x' Chain1 Day g c
y' b -> c -> x
g x -> (b, c)
h)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall x. f x -> h (g x)
f f b
x forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> (forall (f :: * -> *) a. DivAp1 f a -> Chain1 Day f a
unDivAp1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> h (DivAp1 g c)
y)
)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. DivAp1 f a -> Chain1 Day f a
unDivAp1
newtype DivAp f a = DivAp { forall (f :: * -> *) a. DivAp f a -> Chain Day Identity f a
unDivAp :: Chain ID.Day Identity f a }
deriving (forall a b. (a -> b) -> (b -> a) -> DivAp f a -> DivAp f b
forall (f :: * -> *).
(forall a b. (a -> b) -> (b -> a) -> f a -> f b) -> Invariant f
forall (f :: * -> *) a b.
(a -> b) -> (b -> a) -> DivAp f a -> DivAp f b
invmap :: forall a b. (a -> b) -> (b -> a) -> DivAp f a -> DivAp f b
$cinvmap :: forall (f :: * -> *) a b.
(a -> b) -> (b -> a) -> DivAp f a -> DivAp f b
Invariant, forall {k} {k1} (t :: (k -> *) -> k1 -> *).
(forall (f :: k -> *) (g :: k -> *). (f ~> g) -> t f ~> t g)
-> HFunctor t
forall (f :: * -> *) (g :: * -> *). (f ~> g) -> DivAp f ~> DivAp g
hmap :: forall (f :: * -> *) (g :: * -> *). (f ~> g) -> DivAp f ~> DivAp g
$chmap :: forall (f :: * -> *) (g :: * -> *). (f ~> g) -> DivAp f ~> DivAp g
HFunctor)
instance Inject DivAp where
inject :: forall (f :: * -> *). f ~> DivAp f
inject f x
x = forall (f :: * -> *) a. Chain Day Identity f a -> DivAp f a
DivAp forall a b. (a -> b) -> a -> b
$ forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More (forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (b -> c -> a) -> (a -> (b, c)) -> Day f g a
ID.Day f x
x (forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done (forall a. a -> Identity a
Identity ())) forall a b. a -> b -> a
const (,()))
instance HTraversable DivAp where
htraverse :: forall (h :: * -> *) (f :: * -> *) (g :: * -> *) a.
Applicative h =>
(forall x. f x -> h (g x)) -> DivAp f a -> h (DivAp g a)
htraverse forall x. f x -> h (g x)
f =
forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (h :: * -> *)
(i :: k -> *) (g :: k -> *) (f :: k -> *) (a :: k).
(HBifunctor t, Functor h) =>
(forall (x :: k). i x -> h (g x))
-> (forall (x :: k). t f (Comp h g) x -> h (g x))
-> Chain t i f a
-> h (g a)
foldChainA
(forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Chain Day Identity f a -> DivAp f a
DivAp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done)
(\case ID.Day f b
x (Comp h (DivAp g c)
y) b -> c -> x
g x -> (b, c)
h ->
(\g b
x' Chain Day Identity g c
y' -> forall (f :: * -> *) a. Chain Day Identity f a -> DivAp f a
DivAp (forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More (forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (b -> c -> a) -> (a -> (b, c)) -> Day f g a
ID.Day g b
x' Chain Day Identity g c
y' b -> c -> x
g x -> (b, c)
h)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall x. f x -> h (g x)
f f b
x forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (f :: * -> *) a. DivAp f a -> Chain Day Identity f a
unDivAp forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> h (DivAp g c)
y)
)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. DivAp f a -> Chain Day Identity f a
unDivAp
newtype DecAlt1 f a = DecAlt1_ { forall (f :: * -> *) a. DecAlt1 f a -> Chain1 Night f a
unDecAlt1 :: Chain1 IN.Night f a }
deriving (forall a b. (a -> b) -> (b -> a) -> DecAlt1 f a -> DecAlt1 f b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> DecAlt1 f a -> DecAlt1 f b
forall (f :: * -> *).
(forall a b. (a -> b) -> (b -> a) -> f a -> f b) -> Invariant f
invmap :: forall a b. (a -> b) -> (b -> a) -> DecAlt1 f a -> DecAlt1 f b
$cinvmap :: forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> DecAlt1 f a -> DecAlt1 f b
Invariant, forall {k} {k1} (t :: (k -> *) -> k1 -> *).
(forall (f :: k -> *) (g :: k -> *). (f ~> g) -> t f ~> t g)
-> HFunctor t
forall (f :: * -> *) (g :: * -> *).
(f ~> g) -> DecAlt1 f ~> DecAlt1 g
hmap :: forall (f :: * -> *) (g :: * -> *).
(f ~> g) -> DecAlt1 f ~> DecAlt1 g
$chmap :: forall (f :: * -> *) (g :: * -> *).
(f ~> g) -> DecAlt1 f ~> DecAlt1 g
HFunctor, HFunctor DecAlt1
forall {k} (t :: (k -> *) -> k -> *).
HFunctor t -> (forall (f :: k -> *). f ~> t f) -> Inject t
forall (f :: * -> *) x. f x -> DecAlt1 f x
inject :: forall (f :: * -> *) x. f x -> DecAlt1 f x
$cinject :: forall (f :: * -> *) x. f x -> DecAlt1 f x
Inject)
instance HTraversable DecAlt1 where
htraverse :: forall (h :: * -> *) (f :: * -> *) (g :: * -> *) a.
Applicative h =>
(forall x. f x -> h (g x)) -> DecAlt1 f a -> h (DecAlt1 g a)
htraverse forall x. f x -> h (g x)
f =
forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (h :: * -> *)
(f :: k -> *) (g :: k -> *) (a :: k).
(HBifunctor t, Functor h) =>
(forall (x :: k). f x -> h (g x))
-> (forall (x :: k). t f (Comp h g) x -> h (g x))
-> Chain1 t f a
-> h (g a)
foldChain1A
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a. Chain1 Night f a -> DecAlt1 f a
DecAlt1_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. f x -> h (g x)
f)
(\case IN.Night f b1
x (Comp h (DecAlt1 g c1)
y) b1 -> x
g c1 -> x
h x -> Either b1 c1
k ->
(\g b1
x' Chain1 Night g c1
y' -> forall (f :: * -> *) a. Chain1 Night f a -> DecAlt1 f a
DecAlt1_ (forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (forall (a :: * -> *) b1 (b :: * -> *) c1 c.
a b1
-> b c1
-> (b1 -> c)
-> (c1 -> c)
-> (c -> Either b1 c1)
-> Night a b c
IN.Night g b1
x' Chain1 Night g c1
y' b1 -> x
g c1 -> x
h x -> Either b1 c1
k)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall x. f x -> h (g x)
f f b1
x forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (f :: * -> *) a. DecAlt1 f a -> Chain1 Night f a
unDecAlt1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> h (DecAlt1 g c1)
y)
)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. DecAlt1 f a -> Chain1 Night f a
unDecAlt1
instance HTraversable1 DecAlt1 where
htraverse1 :: forall (h :: * -> *) (f :: * -> *) (g :: * -> *) a.
Apply h =>
(forall x. f x -> h (g x)) -> DecAlt1 f a -> h (DecAlt1 g a)
htraverse1 forall x. f x -> h (g x)
f =
forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (h :: * -> *)
(f :: k -> *) (g :: k -> *) (a :: k).
(HBifunctor t, Functor h) =>
(forall (x :: k). f x -> h (g x))
-> (forall (x :: k). t f (Comp h g) x -> h (g x))
-> Chain1 t f a
-> h (g a)
foldChain1A
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a. Chain1 Night f a -> DecAlt1 f a
DecAlt1_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
f a -> Chain1 t f a
Done1) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. f x -> h (g x)
f)
(\case IN.Night f b1
x (Comp h (DecAlt1 g c1)
y) b1 -> x
g c1 -> x
h x -> Either b1 c1
k ->
(\g b1
x' Chain1 Night g c1
y' -> forall (f :: * -> *) a. Chain1 Night f a -> DecAlt1 f a
DecAlt1_ (forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (forall (a :: * -> *) b1 (b :: * -> *) c1 c.
a b1
-> b c1
-> (b1 -> c)
-> (c1 -> c)
-> (c -> Either b1 c1)
-> Night a b c
IN.Night g b1
x' Chain1 Night g c1
y' b1 -> x
g c1 -> x
h x -> Either b1 c1
k)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall x. f x -> h (g x)
f f b1
x forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> (forall (f :: * -> *) a. DecAlt1 f a -> Chain1 Night f a
unDecAlt1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> h (DecAlt1 g c1)
y)
)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. DecAlt1 f a -> Chain1 Night f a
unDecAlt1
instance Inalt f => Interpret DecAlt1 f where
interpret :: forall (g :: * -> *). (g ~> f) -> DecAlt1 g ~> f
interpret g ~> f
f (DecAlt1_ Chain1 Night g x
x) = forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
(g :: k -> *).
HBifunctor t =>
(f ~> g) -> (t f g ~> g) -> Chain1 t f ~> g
foldChain1 g ~> f
f (forall (h :: * -> *) (f :: * -> *) (g :: * -> *).
Inalt h =>
(f ~> h) -> (g ~> h) -> Night f g ~> h
IN.runNight g ~> f
f forall a. a -> a
id) Chain1 Night g x
x
newtype DecAlt f a = DecAlt { forall (f :: * -> *) a. DecAlt f a -> Chain Night Not f a
unDecAlt :: Chain IN.Night IN.Not f a }
deriving (forall a b. (a -> b) -> (b -> a) -> DecAlt f a -> DecAlt f b
forall (f :: * -> *).
(forall a b. (a -> b) -> (b -> a) -> f a -> f b) -> Invariant f
forall (f :: * -> *) a b.
(a -> b) -> (b -> a) -> DecAlt f a -> DecAlt f b
invmap :: forall a b. (a -> b) -> (b -> a) -> DecAlt f a -> DecAlt f b
$cinvmap :: forall (f :: * -> *) a b.
(a -> b) -> (b -> a) -> DecAlt f a -> DecAlt f b
Invariant, forall {k} {k1} (t :: (k -> *) -> k1 -> *).
(forall (f :: k -> *) (g :: k -> *). (f ~> g) -> t f ~> t g)
-> HFunctor t
forall (f :: * -> *) (g :: * -> *).
(f ~> g) -> DecAlt f ~> DecAlt g
hmap :: forall (f :: * -> *) (g :: * -> *).
(f ~> g) -> DecAlt f ~> DecAlt g
$chmap :: forall (f :: * -> *) (g :: * -> *).
(f ~> g) -> DecAlt f ~> DecAlt g
HFunctor)
instance Inject DecAlt where
inject :: forall (f :: * -> *). f ~> DecAlt f
inject f x
x = forall (f :: * -> *) a. Chain Night Not f a -> DecAlt f a
DecAlt forall a b. (a -> b) -> a -> b
$ forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More (forall (a :: * -> *) b1 (b :: * -> *) c1 c.
a b1
-> b c1
-> (b1 -> c)
-> (c1 -> c)
-> (c -> Either b1 c1)
-> Night a b c
IN.Night f x
x (forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done Not Void
IN.refuted) forall a. a -> a
id forall a. Void -> a
absurd forall a b. a -> Either a b
Left)
instance HTraversable DecAlt where
htraverse :: forall (h :: * -> *) (f :: * -> *) (g :: * -> *) a.
Applicative h =>
(forall x. f x -> h (g x)) -> DecAlt f a -> h (DecAlt g a)
htraverse forall x. f x -> h (g x)
f =
forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (h :: * -> *)
(i :: k -> *) (g :: k -> *) (f :: k -> *) (a :: k).
(HBifunctor t, Functor h) =>
(forall (x :: k). i x -> h (g x))
-> (forall (x :: k). t f (Comp h g) x -> h (g x))
-> Chain t i f a
-> h (g a)
foldChainA (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Chain Night Not f a -> DecAlt f a
DecAlt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
i a -> Chain t i f a
Done)
(\case IN.Night f b1
x (Comp h (DecAlt g c1)
y) b1 -> x
g c1 -> x
h x -> Either b1 c1
k ->
(\g b1
x' Chain Night Not g c1
y' -> forall (f :: * -> *) a. Chain Night Not f a -> DecAlt f a
DecAlt (forall {k} {k} (t :: k -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k) (a :: k).
t f (Chain t i f) a -> Chain t i f a
More (forall (a :: * -> *) b1 (b :: * -> *) c1 c.
a b1
-> b c1
-> (b1 -> c)
-> (c1 -> c)
-> (c -> Either b1 c1)
-> Night a b c
IN.Night g b1
x' Chain Night Not g c1
y' b1 -> x
g c1 -> x
h x -> Either b1 c1
k)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall x. f x -> h (g x)
f f b1
x forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (f :: * -> *) a. DecAlt f a -> Chain Night Not f a
unDecAlt forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> h (DecAlt g c1)
y)
)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. DecAlt f a -> Chain Night Not f a
unDecAlt
instance Inplus f => Interpret DecAlt f where
interpret :: forall (g :: * -> *). (g ~> f) -> DecAlt g ~> f
interpret g ~> f
f (DecAlt Chain Night Not g x
x) = forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (i :: k -> *)
(f :: k -> *) (g :: k -> *).
HBifunctor t =>
(i ~> g) -> (t f g ~> g) -> Chain t i f ~> g
foldChain (forall (f :: * -> *) a. Inplus f => (a -> Void) -> f a
reject forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Not a -> a -> Void
IN.refute) (forall (h :: * -> *) (f :: * -> *) (g :: * -> *).
Inalt h =>
(f ~> h) -> (g ~> h) -> Night f g ~> h
IN.runNight g ~> f
f forall a. a -> a
id) Chain Night Not g x
x