functor-combinators 0.4.1.3 → 0.4.1.4
raw patch · 35 files changed
+5890/−4986 lines, 35 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Functor.Combinator: data ConstF e f a
- Data.Functor.Contravariant.Divisible.Free: pattern Div1_ :: (a -> (b, c)) -> f b -> Div f c -> Div1 f a
- Data.Functor.Contravariant.Divisible.Free: pattern Divide :: (a -> (b, c)) -> f b -> Div f c -> Div f a
- Data.Functor.Invariant.Inplicative.Free: pattern Gather :: (b -> c -> a) -> (a -> (b, c)) -> f b -> DivAp f c -> DivAp f a
- Data.Functor.Invariant.Internative.Free: pattern Swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> f b -> DecAlt f c -> DecAlt f a
- Data.HFunctor: data ConstF e f a
+ Data.Functor.Combinator: ($dmbinterpret) :: forall (g :: Type -> Type) (h :: Type -> Type). (SemigroupIn t f, Interpret (NonEmptyBy t) f) => (g ~> f) -> (h ~> f) -> t g h ~> f
+ Data.Functor.Combinator: ($dmbiretract) :: (SemigroupIn t f, Interpret (NonEmptyBy t) f) => t f f ~> f
+ Data.Functor.Combinator: ($dmfromFree) :: forall (f :: Type -> Type). (FreeOf c t, Interpret t (Final c f)) => t f ~> Final c f
+ Data.Functor.Combinator: ($dmpureT) :: (MonoidIn t i f, Interpret (ListBy t) f) => i ~> f
+ Data.Functor.Combinator: ($dmtoFree) :: forall (f :: Type -> Type). (FreeOf c t, Inject t, c (t f)) => Final c f ~> t f
+ Data.Functor.Combinator: newtype ConstF e (f :: k) (a :: k1)
+ Data.Functor.Contravariant.Divisible.Free: pattern Div1_ :: forall a f b c. () => (a -> (b, c)) -> f b -> Div f c -> Div1 f a
+ Data.HBifunctor.Associative: ($dmbinterpret) :: forall (g :: Type -> Type) (h :: Type -> Type). (SemigroupIn t f, Interpret (NonEmptyBy t) f) => (g ~> f) -> (h ~> f) -> t g h ~> f
+ Data.HBifunctor.Associative: ($dmbiretract) :: (SemigroupIn t f, Interpret (NonEmptyBy t) f) => t f f ~> f
+ Data.HBifunctor.Tensor: ($dmpureT) :: (MonoidIn t i f, Interpret (ListBy t) f) => i ~> f
+ Data.HFunctor: newtype ConstF e (f :: k) (a :: k1)
+ Data.HFunctor.Final: ($dmfromFree) :: forall (f :: Type -> Type). (FreeOf c t, Interpret t (Final c f)) => t f ~> Final c f
+ Data.HFunctor.Final: ($dmtoFree) :: forall (f :: Type -> Type). (FreeOf c t, Inject t, c (t f)) => Final c f ~> t f
- Control.Applicative.ListF: ListF :: [f a] -> ListF f a
+ Control.Applicative.ListF: ListF :: [f a] -> ListF (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: MapF :: Map k (f a) -> MapF k f a
+ Control.Applicative.ListF: MapF :: Map k1 (f a) -> MapF k1 (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: MaybeF :: Maybe (f a) -> MaybeF f a
+ Control.Applicative.ListF: MaybeF :: Maybe (f a) -> MaybeF (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: NEMapF :: NEMap k (f a) -> NEMapF k f a
+ Control.Applicative.ListF: NEMapF :: NEMap k1 (f a) -> NEMapF k1 (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: NonEmptyF :: NonEmpty (f a) -> NonEmptyF f a
+ Control.Applicative.ListF: NonEmptyF :: NonEmpty (f a) -> NonEmptyF (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: [runListF] :: ListF f a -> [f a]
+ Control.Applicative.ListF: [runListF] :: ListF (f :: k -> Type) (a :: k) -> [f a]
- Control.Applicative.ListF: [runMapF] :: MapF k f a -> Map k (f a)
+ Control.Applicative.ListF: [runMapF] :: MapF k1 (f :: k -> Type) (a :: k) -> Map k1 (f a)
- Control.Applicative.ListF: [runMaybeF] :: MaybeF f a -> Maybe (f a)
+ Control.Applicative.ListF: [runMaybeF] :: MaybeF (f :: k -> Type) (a :: k) -> Maybe (f a)
- Control.Applicative.ListF: [runNEMapF] :: NEMapF k f a -> NEMap k (f a)
+ Control.Applicative.ListF: [runNEMapF] :: NEMapF k1 (f :: k -> Type) (a :: k) -> NEMap k1 (f a)
- Control.Applicative.ListF: [runNonEmptyF] :: NonEmptyF f a -> NonEmpty (f a)
+ Control.Applicative.ListF: [runNonEmptyF] :: NonEmptyF (f :: k -> Type) (a :: k) -> NonEmpty (f a)
- Control.Applicative.ListF: fromListF :: ListF f ~> (Proxy :+: NonEmptyF f)
+ Control.Applicative.ListF: fromListF :: forall {k} (f :: k -> Type) (x :: k). ListF f x -> ((Proxy :: k -> Type) :+: NonEmptyF f) x
- Control.Applicative.ListF: listToMaybeF :: ListF f ~> MaybeF f
+ Control.Applicative.ListF: listToMaybeF :: forall {k} (f :: k -> Type) (x :: k). ListF f x -> MaybeF f x
- Control.Applicative.ListF: mapListF :: ([f a] -> [g b]) -> ListF f a -> ListF g b
+ Control.Applicative.ListF: mapListF :: forall {k1} {k2} f (a :: k1) g (b :: k2). ([f a] -> [g b]) -> ListF f a -> ListF g b
- Control.Applicative.ListF: mapMaybeF :: (Maybe (f a) -> Maybe (g b)) -> MaybeF f a -> MaybeF g b
+ Control.Applicative.ListF: mapMaybeF :: forall {k1} {k2} f (a :: k1) g (b :: k2). (Maybe (f a) -> Maybe (g b)) -> MaybeF f a -> MaybeF g b
- Control.Applicative.ListF: mapNonEmptyF :: (NonEmpty (f a) -> NonEmpty (g b)) -> NonEmptyF f a -> NonEmptyF g b
+ Control.Applicative.ListF: mapNonEmptyF :: forall {k1} {k2} f (a :: k1) g (b :: k2). (NonEmpty (f a) -> NonEmpty (g b)) -> NonEmptyF f a -> NonEmptyF g b
- Control.Applicative.ListF: maybeToListF :: MaybeF f ~> ListF f
+ Control.Applicative.ListF: maybeToListF :: forall {k} (f :: k -> Type) (x :: k). MaybeF f x -> ListF f x
- Control.Applicative.ListF: newtype ListF f a
+ Control.Applicative.ListF: newtype ListF (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: newtype MapF k f a
+ Control.Applicative.ListF: newtype MapF k1 (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: newtype MaybeF f a
+ Control.Applicative.ListF: newtype MaybeF (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: newtype NEMapF k f a
+ Control.Applicative.ListF: newtype NEMapF k1 (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: newtype NonEmptyF f a
+ Control.Applicative.ListF: newtype NonEmptyF (f :: k -> Type) (a :: k)
- Control.Applicative.ListF: toListF :: NonEmptyF f ~> ListF f
+ Control.Applicative.ListF: toListF :: forall {k} (f :: k -> Type) (x :: k). NonEmptyF f x -> ListF f x
- Control.Applicative.Step: Flagged :: Bool -> f a -> Flagged f a
+ Control.Applicative.Step: Flagged :: Bool -> f a -> Flagged (f :: k -> Type) (a :: k)
- Control.Applicative.Step: Step :: Natural -> f a -> Step f a
+ Control.Applicative.Step: Step :: Natural -> f a -> Step (f :: k -> Type) (a :: k)
- Control.Applicative.Step: Steps :: NEMap Natural (f a) -> Steps f a
+ Control.Applicative.Step: Steps :: NEMap Natural (f a) -> Steps (f :: k -> Type) (a :: k)
- Control.Applicative.Step: [flaggedFlag] :: Flagged f a -> Bool
+ Control.Applicative.Step: [flaggedFlag] :: Flagged (f :: k -> Type) (a :: k) -> Bool
- Control.Applicative.Step: [flaggedVal] :: Flagged f a -> f a
+ Control.Applicative.Step: [flaggedVal] :: Flagged (f :: k -> Type) (a :: k) -> f a
- Control.Applicative.Step: [getSteps] :: Steps f a -> NEMap Natural (f a)
+ Control.Applicative.Step: [getSteps] :: Steps (f :: k -> Type) (a :: k) -> NEMap Natural (f a)
- Control.Applicative.Step: [stepPos] :: Step f a -> Natural
+ Control.Applicative.Step: [stepPos] :: Step (f :: k -> Type) (a :: k) -> Natural
- Control.Applicative.Step: [stepVal] :: Step f a -> f a
+ Control.Applicative.Step: [stepVal] :: Step (f :: k -> Type) (a :: k) -> f a
- Control.Applicative.Step: absurd1 :: V1 a -> f a
+ Control.Applicative.Step: absurd1 :: forall {k} (a :: k) f. V1 a -> f a
- Control.Applicative.Step: absurd2 :: Void2 f a -> t f a
+ Control.Applicative.Step: absurd2 :: forall {k1} {k2} (f :: k1) (a :: k2) t. Void2 f a -> t f a
- Control.Applicative.Step: absurd3 :: Void3 f g a -> t f g a
+ Control.Applicative.Step: absurd3 :: forall {k1} {k2} {k3} (f :: k1) (g :: k2) (a :: k3) t. Void3 f g a -> t f g a
- Control.Applicative.Step: data Flagged f a
+ Control.Applicative.Step: data Flagged (f :: k -> Type) (a :: k)
- Control.Applicative.Step: data Step f a
+ Control.Applicative.Step: data Step (f :: k -> Type) (a :: k)
- Control.Applicative.Step: data Void2 a b
+ Control.Applicative.Step: data Void2 (a :: k) (b :: k1)
- Control.Applicative.Step: data Void3 a b c
+ Control.Applicative.Step: data Void3 (a :: k) (b :: k1) (c :: k2)
- Control.Applicative.Step: newtype Steps f a
+ Control.Applicative.Step: newtype Steps (f :: k -> Type) (a :: k)
- Control.Applicative.Step: stepDown :: Step f ~> (f :+: Step f)
+ Control.Applicative.Step: stepDown :: forall {k} (f :: k -> Type) (x :: k). Step f x -> (f :+: Step f) x
- Control.Applicative.Step: stepUp :: (f :+: Step f) ~> Step f
+ Control.Applicative.Step: stepUp :: forall {k} (f :: k -> Type) (x :: k). (f :+: Step f) x -> Step f x
- Control.Applicative.Step: stepping :: Step f <~> (f :+: Step f)
+ Control.Applicative.Step: stepping :: forall {k} (f :: k -> Type) p (a :: k). Profunctor p => p ((f :+: Step f) a) ((f :+: Step f) a) -> p (Step f a) (Step f a)
- Control.Applicative.Step: steppings :: Steps f <~> These1 f (Steps f)
+ Control.Applicative.Step: steppings :: forall (f :: Type -> Type) p a. Profunctor p => p (These1 f (Steps f) a) (These1 f (Steps f) a) -> p (Steps f a) (Steps f a)
- Control.Applicative.Step: stepsDown :: Steps f ~> These1 f (Steps f)
+ Control.Applicative.Step: stepsDown :: forall (f :: Type -> Type) x. Steps f x -> These1 f (Steps f) x
- Control.Applicative.Step: stepsUp :: These1 f (Steps f) ~> Steps f
+ Control.Applicative.Step: stepsUp :: forall (f :: Type -> Type) x. These1 f (Steps f) x -> Steps f x
- Control.Monad.Freer.Church: (:>>=) :: f x -> (x -> g a) -> Comp f g a
+ Control.Monad.Freer.Church: (:>>=) :: f x -> (x -> g a) -> Comp (f :: Type -> Type) (g :: k -> Type) (a :: k)
- Control.Monad.Freer.Church: Free :: (forall r. (a -> r) -> (forall s. f s -> (s -> r) -> r) -> r) -> Free f a
+ Control.Monad.Freer.Church: Free :: (forall r. () => (a -> r) -> (forall s. () => f s -> (s -> r) -> r) -> r) -> Free (f :: Type -> Type) a
- Control.Monad.Freer.Church: Free1 :: (forall r. (forall s. f s -> (s -> a) -> r) -> (forall s. f s -> (s -> r) -> r) -> r) -> Free1 f a
+ Control.Monad.Freer.Church: Free1 :: (forall r. () => (forall s. () => f s -> (s -> a) -> r) -> (forall s. () => f s -> (s -> r) -> r) -> r) -> Free1 (f :: Type -> Type) a
- Control.Monad.Freer.Church: [runFree1] :: Free1 f a -> forall r. (forall s. f s -> (s -> a) -> r) -> (forall s. f s -> (s -> r) -> r) -> r
+ Control.Monad.Freer.Church: [runFree1] :: Free1 (f :: Type -> Type) a -> forall r. () => (forall s. () => f s -> (s -> a) -> r) -> (forall s. () => f s -> (s -> r) -> r) -> r
- Control.Monad.Freer.Church: [runFree] :: Free f a -> forall r. (a -> r) -> (forall s. f s -> (s -> r) -> r) -> r
+ Control.Monad.Freer.Church: [runFree] :: Free (f :: Type -> Type) a -> forall r. () => (a -> r) -> (forall s. () => f s -> (s -> r) -> r) -> r
- Control.Monad.Freer.Church: comp :: f (g a) -> Comp f g a
+ Control.Monad.Freer.Church: comp :: forall {k} f g (a :: k). f (g a) -> Comp f g a
- Control.Monad.Freer.Church: data Comp f g a
+ Control.Monad.Freer.Church: data Comp (f :: Type -> Type) (g :: k -> Type) (a :: k)
- Control.Monad.Freer.Church: foldFree' :: (a -> r) -> (forall s. f s -> (s -> r) -> r) -> Free f a -> r
+ Control.Monad.Freer.Church: foldFree' :: (a -> r) -> (forall s. () => f s -> (s -> r) -> r) -> Free f a -> r
- Control.Monad.Freer.Church: foldFree1' :: (forall s. f s -> (s -> a) -> r) -> (forall s. f s -> (s -> r) -> r) -> Free1 f a -> r
+ Control.Monad.Freer.Church: foldFree1' :: (forall s. () => f s -> (s -> a) -> r) -> (forall s. () => f s -> (s -> r) -> r) -> Free1 f a -> r
- Control.Monad.Freer.Church: foldFree1C :: (Coyoneda f a -> r) -> (Coyoneda f r -> r) -> Free1 f a -> r
+ Control.Monad.Freer.Church: foldFree1C :: forall (f :: Type -> Type) a r. (Coyoneda f a -> r) -> (Coyoneda f r -> r) -> Free1 f a -> r
- Control.Monad.Freer.Church: foldFreeC :: (a -> r) -> (Coyoneda f r -> r) -> Free f a -> r
+ Control.Monad.Freer.Church: foldFreeC :: forall a r (f :: Type -> Type). (a -> r) -> (Coyoneda f r -> r) -> Free f a -> r
- Control.Monad.Freer.Church: free1Comp :: Free1 f ~> Comp f (Free f)
+ Control.Monad.Freer.Church: free1Comp :: forall (f :: Type -> Type) x. Free1 f x -> Comp f (Free f) x
- Control.Monad.Freer.Church: hoistFree :: (f ~> g) -> Free f ~> Free g
+ Control.Monad.Freer.Church: hoistFree :: forall (f :: Type -> Type) (g :: Type -> Type). (f ~> g) -> Free f ~> Free g
- Control.Monad.Freer.Church: hoistFree1 :: (f ~> g) -> Free1 f ~> Free1 g
+ Control.Monad.Freer.Church: hoistFree1 :: forall (f :: Type -> Type) (g :: Type -> Type). (f ~> g) -> Free1 f ~> Free1 g
- Control.Monad.Freer.Church: interpretFree :: Monad g => (f ~> g) -> Free f ~> g
+ Control.Monad.Freer.Church: interpretFree :: forall (g :: Type -> Type) (f :: Type -> Type). Monad g => (f ~> g) -> Free f ~> g
- Control.Monad.Freer.Church: interpretFree1 :: Bind g => (f ~> g) -> Free1 f ~> g
+ Control.Monad.Freer.Church: interpretFree1 :: forall (g :: Type -> Type) (f :: Type -> Type). Bind g => (f ~> g) -> Free1 f ~> g
- Control.Monad.Freer.Church: liftFree :: f ~> Free f
+ Control.Monad.Freer.Church: liftFree :: f x -> Free f x
- Control.Monad.Freer.Church: liftFree1 :: f ~> Free1 f
+ Control.Monad.Freer.Church: liftFree1 :: f x -> Free1 f x
- Control.Monad.Freer.Church: matchFree1 :: forall f. Functor f => Free1 f ~> (f :+: Comp f (Free1 f))
+ Control.Monad.Freer.Church: matchFree1 :: forall (f :: Type -> Type). Functor f => Free1 f ~> (f :+: Comp f (Free1 f))
- Control.Monad.Freer.Church: newtype Free f a
+ Control.Monad.Freer.Church: newtype Free (f :: Type -> Type) a
- Control.Monad.Freer.Church: newtype Free1 f a
+ Control.Monad.Freer.Church: newtype Free1 (f :: Type -> Type) a
- Control.Monad.Freer.Church: pattern Comp :: Functor f => f (g a) -> Comp f g a
+ Control.Monad.Freer.Church: pattern Comp :: forall {k} f g a. Functor f => f (g a) -> Comp f g a
- Control.Monad.Freer.Church: reFree :: (MonadFree f m, Functor f) => Free f a -> m a
+ Control.Monad.Freer.Church: reFree :: forall (f :: Type -> Type) m a. (MonadFree f m, Functor f) => Free f a -> m a
- Control.Monad.Freer.Church: reFree1 :: (MonadFree f m, Functor f) => Free1 f a -> m a
+ Control.Monad.Freer.Church: reFree1 :: forall (f :: Type -> Type) m a. (MonadFree f m, Functor f) => Free1 f a -> m a
- Control.Monad.Freer.Church: retractFree :: Monad f => Free f ~> f
+ Control.Monad.Freer.Church: retractFree :: forall (f :: Type -> Type). Monad f => Free f ~> f
- Control.Monad.Freer.Church: retractFree1 :: Bind f => Free1 f ~> f
+ Control.Monad.Freer.Church: retractFree1 :: forall (f :: Type -> Type). Bind f => Free1 f ~> f
- Control.Monad.Freer.Church: toFree :: Free1 f ~> Free f
+ Control.Monad.Freer.Church: toFree :: forall (f :: Type -> Type) x. Free1 f x -> Free f x
- Control.Natural.IsoF: coercedF :: forall f g. (forall x. Coercible (f x) (g x), forall x. Coercible (g x) (f x)) => f <~> g
+ Control.Natural.IsoF: coercedF :: forall {k} (f :: k -> Type) (g :: k -> Type). (forall (x :: k). () => Coercible (f x) (g x), forall (x :: k). () => Coercible (g x) (f x)) => f <~> g
- Control.Natural.IsoF: fromF :: forall (f :: Type -> Type) (g :: Type -> Type). () => (f <~> g) -> g <~> f
+ Control.Natural.IsoF: fromF :: forall (f :: Type -> Type) (g :: Type -> Type). (f <~> g) -> g <~> f
- Control.Natural.IsoF: isoF :: (f ~> g) -> (g ~> f) -> f <~> g
+ Control.Natural.IsoF: isoF :: forall {k} (f :: k -> Type) (g :: k -> Type). (f ~> g) -> (g ~> f) -> f <~> g
- Control.Natural.IsoF: overF :: (f <~> g) -> (g ~> g) -> f ~> f
+ Control.Natural.IsoF: overF :: forall {k} (f :: k -> Type) (g :: k -> Type). (f <~> g) -> (g ~> g) -> f ~> f
- Control.Natural.IsoF: reviewF :: (f <~> g) -> g ~> f
+ Control.Natural.IsoF: reviewF :: forall {k} (f :: k -> Type) (g :: k -> Type). (f <~> g) -> g ~> f
- Control.Natural.IsoF: type f <~> g = forall p a. Profunctor p => p (g a) (g a) -> p (f a) (f a)
+ Control.Natural.IsoF: type (f :: k -> Type) <~> (g :: k -> Type) = forall (p :: Type -> Type -> Type) (a :: k). Profunctor p => p g a g a -> p f a f a
- Control.Natural.IsoF: viewF :: (f <~> g) -> f ~> g
+ Control.Natural.IsoF: viewF :: forall {k} (f :: k -> Type) (g :: k -> Type). (f <~> g) -> f ~> g
- Data.Functor.Apply.Free: [Ap1] :: f a -> Ap f (a -> b) -> Ap1 f b
+ Data.Functor.Apply.Free: [Ap1] :: forall (a :: Type -> Type) a1 b. a a1 -> Ap a (a1 -> b) -> Ap1 a b
- Data.Functor.Apply.Free: data Ap1 :: (Type -> Type) -> Type -> Type
+ Data.Functor.Apply.Free: data Ap1 (a :: Type -> Type) b
- Data.Functor.Apply.Free: fromAp :: Ap f ~> (Identity :+: Ap1 f)
+ Data.Functor.Apply.Free: fromAp :: forall (f :: Type -> Type) x. Ap f x -> (Identity :+: Ap1 f) x
- Data.Functor.Apply.Free: liftAp1 :: f ~> Ap1 f
+ Data.Functor.Apply.Free: liftAp1 :: f x -> Ap1 f x
- Data.Functor.Apply.Free: retractAp1 :: Apply f => Ap1 f ~> f
+ Data.Functor.Apply.Free: retractAp1 :: forall (f :: Type -> Type). Apply f => Ap1 f ~> f
- Data.Functor.Apply.Free: runAp1 :: Apply g => (f ~> g) -> Ap1 f ~> g
+ Data.Functor.Apply.Free: runAp1 :: forall (g :: Type -> Type) (f :: Type -> Type). Apply g => (f ~> g) -> Ap1 f ~> g
- Data.Functor.Apply.Free: toAp :: Ap1 f ~> Ap f
+ Data.Functor.Apply.Free: toAp :: forall (f :: Type -> Type) x. Ap1 f x -> Ap f x
- Data.Functor.Combinator: (!$!) :: SemigroupIn t (AltConst b) => (forall x. f x -> b) -> (forall x. g x -> b) -> t f g a -> b
+ Data.Functor.Combinator: (!$!) :: SemigroupIn t (AltConst b :: Type -> Type) => (forall x. () => f x -> b) -> (forall x. () => g x -> b) -> t f g a -> b
- Data.Functor.Combinator: (!*!) :: SemigroupIn t h => (f ~> h) -> (g ~> h) -> t f g ~> h
+ Data.Functor.Combinator: (!*!) :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). SemigroupIn t h => (f ~> h) -> (g ~> h) -> t f g ~> h
- Data.Functor.Combinator: (!+!) :: (f ~> h) -> (g ~> h) -> (f :+: g) ~> h
+ Data.Functor.Combinator: (!+!) :: forall {k} (f :: k -> Type) (h :: k -> Type) (g :: k -> Type). (f ~> h) -> (g ~> h) -> (f :+: g) ~> h
- Data.Functor.Combinator: AltConst :: w -> AltConst w a
+ Data.Functor.Combinator: AltConst :: w -> AltConst w (a :: k)
- Data.Functor.Combinator: ConstF :: e -> ConstF e f a
+ Data.Functor.Combinator: ConstF :: e -> ConstF e (f :: k) (a :: k1)
- Data.Functor.Combinator: Final :: (forall g. c g => (forall x. f x -> g x) -> g a) -> Final c f a
+ Data.Functor.Combinator: Final :: (forall (g :: k -> Type). c g => (forall (x :: k). () => f x -> g x) -> g a) -> Final (c :: (k -> Type) -> Constraint) (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: Flagged :: Bool -> f a -> Flagged f a
+ Data.Functor.Combinator: Flagged :: Bool -> f a -> Flagged (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: HJoin :: t (HFree t f) a -> HFree t f a
+ Data.Functor.Combinator: HJoin :: t (HFree t f) a -> HFree (t :: (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: HOther :: t f a -> HLift t f a
+ Data.Functor.Combinator: HOther :: t f a -> HLift (t :: (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: HPure :: f a -> HLift t f a
+ Data.Functor.Combinator: HPure :: f a -> HLift (t :: (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: HReturn :: f a -> HFree t f a
+ Data.Functor.Combinator: HReturn :: f a -> HFree (t :: (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: LeftF :: f a -> LeftF f g a
+ Data.Functor.Combinator: LeftF :: f a -> LeftF (f :: k -> Type) (g :: k1) (a :: k)
- Data.Functor.Combinator: ListF :: [f a] -> ListF f a
+ Data.Functor.Combinator: ListF :: [f a] -> ListF (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: MapF :: Map k (f a) -> MapF k f a
+ Data.Functor.Combinator: MapF :: Map k1 (f a) -> MapF k1 (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: MaybeF :: Maybe (f a) -> MaybeF f a
+ Data.Functor.Combinator: MaybeF :: Maybe (f a) -> MaybeF (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: NEMapF :: NEMap k (f a) -> NEMapF k f a
+ Data.Functor.Combinator: NEMapF :: NEMap k1 (f a) -> NEMapF k1 (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: NonEmptyF :: NonEmpty (f a) -> NonEmptyF f a
+ Data.Functor.Combinator: NonEmptyF :: NonEmpty (f a) -> NonEmptyF (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: ProxyF :: ProxyF f a
+ Data.Functor.Combinator: ProxyF :: ProxyF (f :: k) (a :: k1)
- Data.Functor.Combinator: RightF :: g a -> RightF f g a
+ Data.Functor.Combinator: RightF :: g a -> RightF (f :: k) (g :: k1 -> Type) (a :: k1)
- Data.Functor.Combinator: Step :: Natural -> f a -> Step f a
+ Data.Functor.Combinator: Step :: Natural -> f a -> Step (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: Steps :: NEMap Natural (f a) -> Steps f a
+ Data.Functor.Combinator: Steps :: NEMap Natural (f a) -> Steps (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: [Ap1] :: f a -> Ap f (a -> b) -> Ap1 f b
+ Data.Functor.Combinator: [Ap1] :: forall (a :: Type -> Type) a1 b. a a1 -> Ap a (a1 -> b) -> Ap1 a b
- Data.Functor.Combinator: [Night] :: f b -> g c -> (b -> a) -> (c -> a) -> (a -> Either b c) -> Night f g a
+ Data.Functor.Combinator: [Night] :: forall (a :: Type -> Type) b1 (b :: Type -> Type) c1 c. a b1 -> b c1 -> (b1 -> c) -> (c1 -> c) -> (c -> Either b1 c1) -> Night a b c
- Data.Functor.Combinator: [flaggedFlag] :: Flagged f a -> Bool
+ Data.Functor.Combinator: [flaggedFlag] :: Flagged (f :: k -> Type) (a :: k) -> Bool
- Data.Functor.Combinator: [flaggedVal] :: Flagged f a -> f a
+ Data.Functor.Combinator: [flaggedVal] :: Flagged (f :: k -> Type) (a :: k) -> f a
- Data.Functor.Combinator: [getAltConst] :: AltConst w a -> w
+ Data.Functor.Combinator: [getAltConst] :: AltConst w (a :: k) -> w
- Data.Functor.Combinator: [getConstF] :: ConstF e f a -> e
+ Data.Functor.Combinator: [getConstF] :: ConstF e (f :: k) (a :: k1) -> e
- Data.Functor.Combinator: [getSteps] :: Steps f a -> NEMap Natural (f a)
+ Data.Functor.Combinator: [getSteps] :: Steps (f :: k -> Type) (a :: k) -> NEMap Natural (f a)
- Data.Functor.Combinator: [runFinal] :: Final c f a -> forall g. c g => (forall x. f x -> g x) -> g a
+ Data.Functor.Combinator: [runFinal] :: Final (c :: (k -> Type) -> Constraint) (f :: k -> Type) (a :: k) -> forall (g :: k -> Type). c g => (forall (x :: k). () => f x -> g x) -> g a
- Data.Functor.Combinator: [runLeftF] :: LeftF f g a -> f a
+ Data.Functor.Combinator: [runLeftF] :: LeftF (f :: k -> Type) (g :: k1) (a :: k) -> f a
- Data.Functor.Combinator: [runListF] :: ListF f a -> [f a]
+ Data.Functor.Combinator: [runListF] :: ListF (f :: k -> Type) (a :: k) -> [f a]
- Data.Functor.Combinator: [runMapF] :: MapF k f a -> Map k (f a)
+ Data.Functor.Combinator: [runMapF] :: MapF k1 (f :: k -> Type) (a :: k) -> Map k1 (f a)
- Data.Functor.Combinator: [runMaybeF] :: MaybeF f a -> Maybe (f a)
+ Data.Functor.Combinator: [runMaybeF] :: MaybeF (f :: k -> Type) (a :: k) -> Maybe (f a)
- Data.Functor.Combinator: [runNEMapF] :: NEMapF k f a -> NEMap k (f a)
+ Data.Functor.Combinator: [runNEMapF] :: NEMapF k1 (f :: k -> Type) (a :: k) -> NEMap k1 (f a)
- Data.Functor.Combinator: [runNonEmptyF] :: NonEmptyF f a -> NonEmpty (f a)
+ Data.Functor.Combinator: [runNonEmptyF] :: NonEmptyF (f :: k -> Type) (a :: k) -> NonEmpty (f a)
- Data.Functor.Combinator: [runRightF] :: RightF f g a -> g a
+ Data.Functor.Combinator: [runRightF] :: RightF (f :: k) (g :: k1 -> Type) (a :: k1) -> g a
- Data.Functor.Combinator: [stepPos] :: Step f a -> Natural
+ Data.Functor.Combinator: [stepPos] :: Step (f :: k -> Type) (a :: k) -> Natural
- Data.Functor.Combinator: [stepVal] :: Step f a -> f a
+ Data.Functor.Combinator: [stepVal] :: Step (f :: k -> Type) (a :: k) -> f a
- Data.Functor.Combinator: absorb :: f ~> Proxy
+ Data.Functor.Combinator: absorb :: forall {k} f (x :: k). f x -> Proxy x
- Data.Functor.Combinator: appendLB :: Tensor t i => t (ListBy t f) (ListBy t f) ~> ListBy t f
+ Data.Functor.Combinator: appendLB :: forall (f :: Type -> Type). Tensor t i => t (ListBy t f) (ListBy t f) ~> ListBy t f
- Data.Functor.Combinator: appendNE :: Associative t => t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
+ Data.Functor.Combinator: appendNE :: forall (f :: Type -> Type). Associative t => t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
- Data.Functor.Combinator: associating :: (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) => t f (t g h) <~> t (t f g) h
+ Data.Functor.Combinator: associating :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) => t f (t g h) <~> t (t f g) h
- Data.Functor.Combinator: biapply :: SemigroupIn t (Op b) => (forall x. f x -> x -> b) -> (forall x. g x -> x -> b) -> t f g a -> a -> b
+ Data.Functor.Combinator: biapply :: SemigroupIn t (Op b) => (forall x. () => f x -> x -> b) -> (forall x. () => g x -> x -> b) -> t f g a -> a -> b
- Data.Functor.Combinator: biget :: SemigroupIn t (AltConst b) => (forall x. f x -> b) -> (forall x. g x -> b) -> t f g a -> b
+ Data.Functor.Combinator: biget :: SemigroupIn t (AltConst b :: Type -> Type) => (forall x. () => f x -> b) -> (forall x. () => g x -> b) -> t f g a -> b
- Data.Functor.Combinator: binterpret :: (SemigroupIn t f, Interpret (NonEmptyBy t) f) => (g ~> f) -> (h ~> f) -> t g h ~> f
+ Data.Functor.Combinator: binterpret :: forall (g :: Type -> Type) (h :: Type -> Type). SemigroupIn t f => (g ~> f) -> (h ~> f) -> t g h ~> f
- Data.Functor.Combinator: biretract :: (SemigroupIn t f, Interpret (NonEmptyBy t) f) => t f f ~> f
+ Data.Functor.Combinator: biretract :: SemigroupIn t f => t f f ~> f
- Data.Functor.Combinator: class (HBifunctor t, Inject (NonEmptyBy t)) => Associative t where {
+ Data.Functor.Combinator: class (HBifunctor t, Inject NonEmptyBy t) => Associative (t :: Type -> Type -> Type -> Type -> Type -> Type) where {
- Data.Functor.Combinator: class FreeOf c t | t -> c where {
+ Data.Functor.Combinator: class FreeOf (c :: Type -> Type -> Constraint) (t :: Type -> Type -> Type -> Type) | t -> c where {
- Data.Functor.Combinator: class HBifunctor (t :: (k -> Type) -> (k -> Type) -> k -> Type)
+ Data.Functor.Combinator: class HBifunctor (t :: k -> Type -> k -> Type -> k -> Type)
- Data.Functor.Combinator: class HFunctor t
+ Data.Functor.Combinator: class HFunctor (t :: k -> Type -> k1 -> Type)
- Data.Functor.Combinator: class HFunctor t => HTraversable t
+ Data.Functor.Combinator: class HFunctor t => HTraversable (t :: k -> Type -> k1 -> Type)
- Data.Functor.Combinator: class HTraversable t => HTraversable1 t
+ Data.Functor.Combinator: class HTraversable t => HTraversable1 (t :: k -> Type -> k1 -> Type)
- Data.Functor.Combinator: class HFunctor t => Inject t
+ Data.Functor.Combinator: class HFunctor t => Inject (t :: k -> Type -> k -> Type)
- Data.Functor.Combinator: class Inject t => Interpret t f
+ Data.Functor.Combinator: class Inject t => Interpret (t :: k -> Type -> k -> Type) (f :: k -> Type)
- Data.Functor.Combinator: class (Tensor t i, SemigroupIn t f) => MonoidIn t i f
+ Data.Functor.Combinator: class (Tensor t i, SemigroupIn t f) => MonoidIn (t :: Type -> Type -> Type -> Type -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type)
- Data.Functor.Combinator: class (Associative t, FunctorBy t f) => SemigroupIn t f
+ Data.Functor.Combinator: class (Associative t, FunctorBy t f) => SemigroupIn (t :: Type -> Type -> Type -> Type -> Type -> Type) (f :: Type -> Type)
- Data.Functor.Combinator: class (Associative t, Inject (ListBy t)) => Tensor t i | t -> i where {
+ Data.Functor.Combinator: class (Associative t, Inject ListBy t) => Tensor (t :: Type -> Type -> Type -> Type -> Type -> Type) (i :: Type -> Type) | t -> i where {
- Data.Functor.Combinator: collectI :: (forall m. Monoid m => Interpret t (AltConst m)) => (forall x. f x -> b) -> t f a -> [b]
+ Data.Functor.Combinator: collectI :: forall {k} t f b (a :: k). (forall m. Monoid m => Interpret t (AltConst m :: k -> Type)) => (forall (x :: k). () => f x -> b) -> t f a -> [b]
- Data.Functor.Combinator: concludeN :: Conclude f => NP f as -> f (NS I as)
+ Data.Functor.Combinator: concludeN :: forall f (as :: [Type]). Conclude f => NP f as -> f (NS I as)
- Data.Functor.Combinator: consLB :: Tensor t i => t f (ListBy t f) ~> ListBy t f
+ Data.Functor.Combinator: consLB :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => t f (ListBy t f) ~> ListBy t f
- Data.Functor.Combinator: consNE :: Associative t => t f (NonEmptyBy t f) ~> NonEmptyBy t f
+ Data.Functor.Combinator: consNE :: forall (f :: Type -> Type). Associative t => t f (NonEmptyBy t f) ~> NonEmptyBy t f
- Data.Functor.Combinator: data () => ( (f :: k -> Type) :+: (g :: k -> Type) ) (p :: k)
+ Data.Functor.Combinator: data ( (f :: k -> Type) :+: (g :: k -> Type) ) (p :: k)
- Data.Functor.Combinator: data () => Alt (f :: Type -> Type) a
+ Data.Functor.Combinator: data Alt (f :: Type -> Type) a
- Data.Functor.Combinator: data () => Ap (f :: Type -> Type) a
+ Data.Functor.Combinator: data Ap (f :: Type -> Type) a
- Data.Functor.Combinator: data Ap1 :: (Type -> Type) -> Type -> Type
+ Data.Functor.Combinator: data Ap1 (a :: Type -> Type) b
- Data.Functor.Combinator: data Comp f g a
+ Data.Functor.Combinator: data Comp (f :: Type -> Type) (g :: k -> Type) (a :: k)
- Data.Functor.Combinator: data () => Coyoneda (f :: Type -> Type) a
+ Data.Functor.Combinator: data Coyoneda (f :: Type -> Type) a
- Data.Functor.Combinator: data () => Day (f :: Type -> Type) (g :: Type -> Type) a
+ Data.Functor.Combinator: data Day (f :: Type -> Type) (g :: Type -> Type) a
- Data.Functor.Combinator: data () => EnvT e (w :: Type -> Type) a
+ Data.Functor.Combinator: data EnvT e (w :: Type -> Type) a
- Data.Functor.Combinator: data Flagged f a
+ Data.Functor.Combinator: data Flagged (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: data Free f a
+ Data.Functor.Combinator: data Free (f :: Type -> Type) a
- Data.Functor.Combinator: data Free1 f a
+ Data.Functor.Combinator: data Free1 (f :: Type -> Type) a
- Data.Functor.Combinator: data HFree t f a
+ Data.Functor.Combinator: data HFree (t :: k -> Type -> k -> Type) (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: data HLift t f a
+ Data.Functor.Combinator: data HLift (t :: k -> Type -> k -> Type) (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: data () => Lift (f :: Type -> Type) a
+ Data.Functor.Combinator: data Lift (f :: Type -> Type) a
- Data.Functor.Combinator: data Night :: (Type -> Type) -> (Type -> Type) -> (Type -> Type)
+ Data.Functor.Combinator: data Night (a :: Type -> Type) (b :: Type -> Type) c
- Data.Functor.Combinator: data ProxyF f a
+ Data.Functor.Combinator: data ProxyF (f :: k) (a :: k1)
- Data.Functor.Combinator: data Step f a
+ Data.Functor.Combinator: data Step (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: data () => These1 (f :: Type -> Type) (g :: Type -> Type) a
+ Data.Functor.Combinator: data These1 (f :: Type -> Type) (g :: Type -> Type) a
- Data.Functor.Combinator: data () => V1 (p :: k)
+ Data.Functor.Combinator: data V1 (p :: k)
- Data.Functor.Combinator: data Void2 a b
+ Data.Functor.Combinator: data Void2 (a :: k) (b :: k1)
- Data.Functor.Combinator: decideN :: Decide f => NP f (a ': as) -> f (NS I (a ': as))
+ Data.Functor.Combinator: decideN :: forall f a (as :: [Type]). Decide f => NP f (a ': as) -> f (NS I (a ': as))
- Data.Functor.Combinator: elim1 :: (Tensor t i, FunctorBy t f) => t f i ~> f
+ Data.Functor.Combinator: elim1 :: forall (f :: Type -> Type). (Tensor t i, FunctorBy t f) => t f i ~> f
- Data.Functor.Combinator: elim2 :: (Tensor t i, FunctorBy t g) => t i g ~> g
+ Data.Functor.Combinator: elim2 :: forall (g :: Type -> Type). (Tensor t i, FunctorBy t g) => t i g ~> g
- Data.Functor.Combinator: forI :: Interpret t f => t g a -> (g ~> f) -> f a
+ Data.Functor.Combinator: forI :: forall {k} t f (g :: k -> Type) (a :: k). Interpret t f => t g a -> (g ~> f) -> f a
- Data.Functor.Combinator: fromFree :: (FreeOf c t, Interpret t (Final c f)) => t f ~> Final c f
+ Data.Functor.Combinator: fromFree :: forall (f :: Type -> Type). FreeOf c t => t f ~> Final c f
- Data.Functor.Combinator: fromNE :: Tensor t i => NonEmptyBy t f ~> ListBy t f
+ Data.Functor.Combinator: fromNE :: forall (f :: Type -> Type). Tensor t i => NonEmptyBy t f ~> ListBy t f
- Data.Functor.Combinator: generalize :: Applicative f => Identity ~> f
+ Data.Functor.Combinator: generalize :: forall (f :: Type -> Type). Applicative f => Identity ~> f
- Data.Functor.Combinator: getI :: Interpret t (AltConst b) => (forall x. f x -> b) -> t f a -> b
+ Data.Functor.Combinator: getI :: forall {k} t b f (a :: k). Interpret t (AltConst b :: k -> Type) => (forall (x :: k). () => f x -> b) -> t f a -> b
- Data.Functor.Combinator: hbimap :: HBifunctor t => (f ~> j) -> (g ~> l) -> t f g ~> t j l
+ Data.Functor.Combinator: hbimap :: forall (f :: k -> Type) (j :: k -> Type) (g :: k -> Type) (l :: k -> Type). HBifunctor t => (f ~> j) -> (g ~> l) -> t f g ~> t j l
- Data.Functor.Combinator: hfoldMap :: (HTraversable t, Monoid m) => (forall x. f x -> m) -> t f a -> m
+ Data.Functor.Combinator: hfoldMap :: forall {k} {k1} t m f (a :: k1). (HTraversable t, Monoid m) => (forall (x :: k). () => f x -> m) -> t f a -> m
- Data.Functor.Combinator: hfoldMap1 :: (HTraversable1 t, Semigroup m) => (forall x. f x -> m) -> t f a -> m
+ Data.Functor.Combinator: hfoldMap1 :: forall {k} {k1} t m f (a :: k1). (HTraversable1 t, Semigroup m) => (forall (x :: k). () => f x -> m) -> t f a -> m
- Data.Functor.Combinator: hleft :: HBifunctor t => (f ~> j) -> t f g ~> t j g
+ Data.Functor.Combinator: hleft :: forall (f :: k -> Type) (j :: k -> Type) (g :: k -> Type). HBifunctor t => (f ~> j) -> t f g ~> t j g
- Data.Functor.Combinator: hmap :: HFunctor t => (f ~> g) -> t f ~> t g
+ Data.Functor.Combinator: hmap :: forall (f :: k -> Type) (g :: k -> Type). HFunctor t => (f ~> g) -> t f ~> t g
- Data.Functor.Combinator: hright :: HBifunctor t => (g ~> l) -> t f g ~> t f l
+ Data.Functor.Combinator: hright :: forall (g :: k -> Type) (l :: k -> Type) (f :: k -> Type). HBifunctor t => (g ~> l) -> t f g ~> t f l
- Data.Functor.Combinator: hsequence :: (HTraversable t, Applicative h) => t (h :.: f) a -> h (t f a)
+ Data.Functor.Combinator: hsequence :: forall {k} {k1} t h (f :: k -> Type) (a :: k1). (HTraversable t, Applicative h) => t (h :.: f) a -> h (t f a)
- Data.Functor.Combinator: hsequence1 :: (HTraversable1 t, Apply h) => t (h :.: f) a -> h (t f a)
+ Data.Functor.Combinator: hsequence1 :: forall {k} {k1} t h (f :: k -> Type) (a :: k1). (HTraversable1 t, Apply h) => t (h :.: f) a -> h (t f a)
- Data.Functor.Combinator: htoList :: HTraversable t => (forall x. f x -> b) -> t f a -> [b]
+ Data.Functor.Combinator: htoList :: forall {k} {k1} t f b (a :: k1). HTraversable t => (forall (x :: k). () => f x -> b) -> t f a -> [b]
- Data.Functor.Combinator: htoNonEmpty :: HTraversable1 t => (forall x. f x -> b) -> t f a -> NonEmpty b
+ Data.Functor.Combinator: htoNonEmpty :: forall {k} {k1} t f b (a :: k1). HTraversable1 t => (forall (x :: k). () => f x -> b) -> t f a -> NonEmpty b
- Data.Functor.Combinator: htraverse :: (HTraversable t, Applicative h) => (forall x. f x -> h (g x)) -> t f a -> h (t g a)
+ Data.Functor.Combinator: htraverse :: forall h f g (a :: k1). (HTraversable t, Applicative h) => (forall (x :: k). () => f x -> h (g x)) -> t f a -> h (t g a)
- Data.Functor.Combinator: htraverse1 :: (HTraversable1 t, Apply h) => (forall x. f x -> h (g x)) -> t f a -> h (t g a)
+ Data.Functor.Combinator: htraverse1 :: forall h f g (a :: k1). (HTraversable1 t, Apply h) => (forall (x :: k). () => f x -> h (g x)) -> t f a -> h (t g a)
- Data.Functor.Combinator: iapply :: Interpret t (Op b) => (forall x. f x -> x -> b) -> t f a -> a -> b
+ Data.Functor.Combinator: iapply :: Interpret t (Op b) => (forall x. () => f x -> x -> b) -> t f a -> a -> b
- Data.Functor.Combinator: icollect :: (forall m. Monoid m => Interpret t (AltConst m)) => (forall x. f x -> b) -> t f a -> [b]
+ Data.Functor.Combinator: icollect :: forall {k} t f b (a :: k). (forall m. Monoid m => Interpret t (AltConst m :: k -> Type)) => (forall (x :: k). () => f x -> b) -> t f a -> [b]
- Data.Functor.Combinator: icollect1 :: (forall m. Semigroup m => Interpret t (AltConst m)) => (forall x. f x -> b) -> t f a -> NonEmpty b
+ Data.Functor.Combinator: icollect1 :: forall {k} t f b (a :: k). (forall m. Semigroup m => Interpret t (AltConst m :: k -> Type)) => (forall (x :: k). () => f x -> b) -> t f a -> NonEmpty b
- Data.Functor.Combinator: ifanout :: (forall m. Monoid m => Interpret t (Op m)) => (forall x. f x -> x -> b) -> t f a -> a -> [b]
+ Data.Functor.Combinator: ifanout :: (forall m. Monoid m => Interpret t (Op m)) => (forall x. () => f x -> x -> b) -> t f a -> a -> [b]
- Data.Functor.Combinator: ifanout1 :: (forall m. Semigroup m => Interpret t (Op m)) => (forall x. f x -> x -> b) -> t f a -> a -> NonEmpty b
+ Data.Functor.Combinator: ifanout1 :: (forall m. Semigroup m => Interpret t (Op m)) => (forall x. () => f x -> x -> b) -> t f a -> a -> NonEmpty b
- Data.Functor.Combinator: iget :: Interpret t (AltConst b) => (forall x. f x -> b) -> t f a -> b
+ Data.Functor.Combinator: iget :: forall {k} t b f (a :: k). Interpret t (AltConst b :: k -> Type) => (forall (x :: k). () => f x -> b) -> t f a -> b
- Data.Functor.Combinator: inL :: forall t i f g. MonoidIn t i g => f ~> t f g
+ Data.Functor.Combinator: inL :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). MonoidIn t i g => f ~> t f g
- Data.Functor.Combinator: inR :: forall t i f g. MonoidIn t i f => g ~> t f g
+ Data.Functor.Combinator: inR :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). MonoidIn t i f => g ~> t f g
- Data.Functor.Combinator: inject :: Inject t => f ~> t f
+ Data.Functor.Combinator: inject :: forall (f :: k -> Type). Inject t => f ~> t f
- Data.Functor.Combinator: interpret :: Interpret t f => (g ~> f) -> t g ~> f
+ Data.Functor.Combinator: interpret :: forall (g :: k -> Type). Interpret t f => (g ~> f) -> t g ~> f
- Data.Functor.Combinator: intro1 :: Tensor t i => f ~> t f i
+ Data.Functor.Combinator: intro1 :: forall (f :: Type -> Type). Tensor t i => f ~> t f i
- Data.Functor.Combinator: intro2 :: Tensor t i => g ~> t i g
+ Data.Functor.Combinator: intro2 :: forall (g :: Type -> Type). Tensor t i => g ~> t i g
- Data.Functor.Combinator: matchNE :: (Associative t, FunctorBy t f) => NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
+ Data.Functor.Combinator: matchNE :: forall (f :: Type -> Type). (Associative t, FunctorBy t f) => NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
- Data.Functor.Combinator: newtype AltConst w a
+ Data.Functor.Combinator: newtype AltConst w (a :: k)
- Data.Functor.Combinator: newtype () => ComposeT (f :: Type -> Type -> Type -> Type) (g :: Type -> Type -> Type -> Type) (m :: Type -> Type) a
+ Data.Functor.Combinator: newtype ComposeT (f :: Type -> Type -> Type -> Type) (g :: Type -> Type -> Type -> Type) (m :: Type -> Type) a
- Data.Functor.Combinator: newtype Final c f a
+ Data.Functor.Combinator: newtype Final (c :: k -> Type -> Constraint) (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: newtype () => IdentityT (f :: k -> Type) (a :: k)
+ Data.Functor.Combinator: newtype IdentityT (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: newtype LeftF f g a
+ Data.Functor.Combinator: newtype LeftF (f :: k -> Type) (g :: k1) (a :: k)
- Data.Functor.Combinator: newtype ListF f a
+ Data.Functor.Combinator: newtype ListF (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: newtype MapF k f a
+ Data.Functor.Combinator: newtype MapF k1 (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: newtype MaybeF f a
+ Data.Functor.Combinator: newtype MaybeF (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: newtype NEMapF k f a
+ Data.Functor.Combinator: newtype NEMapF k1 (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: newtype NonEmptyF f a
+ Data.Functor.Combinator: newtype NonEmptyF (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: newtype () => ReaderT r (m :: Type -> Type) a
+ Data.Functor.Combinator: newtype ReaderT r (m :: Type -> Type) a
- Data.Functor.Combinator: newtype RightF f g a
+ Data.Functor.Combinator: newtype RightF (f :: k) (g :: k1 -> Type) (a :: k1)
- Data.Functor.Combinator: newtype Steps f a
+ Data.Functor.Combinator: newtype Steps (f :: k -> Type) (a :: k)
- Data.Functor.Combinator: nilLB :: forall t i f. Tensor t i => i ~> ListBy t f
+ Data.Functor.Combinator: nilLB :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => i ~> ListBy t f
- Data.Functor.Combinator: outL :: (Tensor t Proxy, FunctorBy t f) => t f g ~> f
+ Data.Functor.Combinator: outL :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) (g :: Type -> Type). (Tensor t (Proxy :: Type -> Type), FunctorBy t f) => t f g ~> f
- Data.Functor.Combinator: outR :: (Tensor t Proxy, FunctorBy t g) => t f g ~> g
+ Data.Functor.Combinator: outR :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (g :: Type -> Type) (f :: Type -> Type). (Tensor t (Proxy :: Type -> Type), FunctorBy t g) => t f g ~> g
- Data.Functor.Combinator: pattern Comp :: Functor f => f (g a) -> Comp f g a
+ Data.Functor.Combinator: pattern Comp :: forall {k} f g a. Functor f => f (g a) -> Comp f g a
- Data.Functor.Combinator: prodOutL :: (f :*: g) ~> f
+ Data.Functor.Combinator: prodOutL :: forall {k} f (g :: k -> Type) (x :: k). (f :*: g) x -> f x
- Data.Functor.Combinator: prodOutR :: (f :*: g) ~> g
+ Data.Functor.Combinator: prodOutR :: forall {k} (f :: k -> Type) g (x :: k). (f :*: g) x -> g x
- Data.Functor.Combinator: pureT :: (MonoidIn t i f, Interpret (ListBy t) f) => i ~> f
+ Data.Functor.Combinator: pureT :: MonoidIn t i f => i ~> f
- Data.Functor.Combinator: splitNE :: Tensor t i => NonEmptyBy t f ~> t f (ListBy t f)
+ Data.Functor.Combinator: splitNE :: forall (f :: Type -> Type). Tensor t i => NonEmptyBy t f ~> t f (ListBy t f)
- Data.Functor.Combinator: splittingLB :: Tensor t i => ListBy t f <~> (i :+: t f (ListBy t f))
+ Data.Functor.Combinator: splittingLB :: forall (f :: Type -> Type). Tensor t i => ListBy t f <~> (i :+: t f (ListBy t f))
- Data.Functor.Combinator: toFree :: (FreeOf c t, Inject t, c (t f)) => Final c f ~> t f
+ Data.Functor.Combinator: toFree :: forall (f :: Type -> Type). (FreeOf c t, FreeFunctorBy t f) => Final c f ~> t f
- Data.Functor.Combinator: toListBy :: Tensor t i => t f f ~> ListBy t f
+ Data.Functor.Combinator: toListBy :: forall (f :: Type -> Type). Tensor t i => t f f ~> ListBy t f
- Data.Functor.Combinator: toNonEmptyBy :: Associative t => t f f ~> NonEmptyBy t f
+ Data.Functor.Combinator: toNonEmptyBy :: forall (f :: Type -> Type). Associative t => t f f ~> NonEmptyBy t f
- Data.Functor.Combinator: type FreeFunctorBy t = Unconstrained;
+ Data.Functor.Combinator: type FreeFunctorBy t :: Type -> Type -> Type -> Type = Unconstrained :: Type -> Type -> Constraint;
- Data.Functor.Combinator: type FunctorBy t = Unconstrained;
+ Data.Functor.Combinator: type FunctorBy t :: Type -> Type -> Type -> Type -> Type -> Type = Unconstrained :: Type -> Type -> Constraint;
- Data.Functor.Combinator: type ListBy t :: (Type -> Type) -> Type -> Type;
+ Data.Functor.Combinator: type ListBy (t :: Type -> Type -> Type -> Type -> Type -> Type) :: Type -> Type -> Type -> Type;
- Data.Functor.Combinator: type NonEmptyBy t :: (Type -> Type) -> Type -> Type;
+ Data.Functor.Combinator: type NonEmptyBy (t :: Type -> Type -> Type -> Type -> Type -> Type) :: Type -> Type -> Type -> Type;
- Data.Functor.Combinator: type f <~> g = forall p a. Profunctor p => p (g a) (g a) -> p (f a) (f a)
+ Data.Functor.Combinator: type (f :: k -> Type) <~> (g :: k -> Type) = forall (p :: Type -> Type -> Type) (a :: k). Profunctor p => p g a g a -> p f a f a
- Data.Functor.Combinator.Unsafe: unsafeApply :: forall f proxy r. Applicative f => proxy f -> (Apply f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeApply :: forall (f :: Type -> Type) proxy r. Applicative f => proxy f -> (Apply f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafeBind :: forall f proxy r. Monad f => proxy f -> (Bind f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeBind :: forall (f :: Type -> Type) proxy r. Monad f => proxy f -> (Bind f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafeConclude :: forall f proxy r. Decidable f => proxy f -> (Conclude f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeConclude :: forall (f :: Type -> Type) proxy r. Decidable f => proxy f -> (Conclude f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafeDivise :: forall f proxy r. Divisible f => proxy f -> (Divise f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeDivise :: forall (f :: Type -> Type) proxy r. Divisible f => proxy f -> (Divise f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafeInplicativeCo :: forall f proxy r. (Applicative f, Invariant f) => proxy f -> (Inplicative f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeInplicativeCo :: forall (f :: Type -> Type) proxy r. (Applicative f, Invariant f) => proxy f -> (Inplicative f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafeInplicativeContra :: forall f proxy r. (Divisible f, Invariant f) => proxy f -> (Inplicative f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeInplicativeContra :: forall (f :: Type -> Type) proxy r. (Divisible f, Invariant f) => proxy f -> (Inplicative f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafeInplyCo :: forall f proxy r. Apply f => proxy f -> (Inply f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeInplyCo :: forall (f :: Type -> Type) proxy r. Apply f => proxy f -> (Inply f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafeInplyContra :: forall f proxy r. Divise f => proxy f -> (Inply f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeInplyContra :: forall (f :: Type -> Type) proxy r. Divise f => proxy f -> (Inply f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafeInvariantCo :: forall f proxy r. Functor f => proxy f -> (Invariant f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeInvariantCo :: forall (f :: Type -> Type) proxy r. Functor f => proxy f -> (Invariant f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafeInvariantContra :: forall f proxy r. Contravariant f => proxy f -> (Invariant f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafeInvariantContra :: forall (f :: Type -> Type) proxy r. Contravariant f => proxy f -> (Invariant f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafePlus :: forall f proxy r. Alternative f => proxy f -> (Plus f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafePlus :: forall (f :: Type -> Type) proxy r. Alternative f => proxy f -> (Plus f => r) -> r
- Data.Functor.Combinator.Unsafe: unsafePointed :: forall f proxy r. Applicative f => proxy f -> (Pointed f => r) -> r
+ Data.Functor.Combinator.Unsafe: unsafePointed :: forall (f :: Type -> Type) proxy r. Applicative f => proxy f -> (Pointed f => r) -> r
- Data.Functor.Contravariant.Conclude: class Decide f => Conclude f
+ Data.Functor.Contravariant.Conclude: class Decide f => Conclude (f :: Type -> Type)
- Data.Functor.Contravariant.Decide: class Contravariant f => Decide f
+ Data.Functor.Contravariant.Decide: class Contravariant f => Decide (f :: Type -> Type)
- Data.Functor.Contravariant.Divise: WrapDivisible :: f a -> WrappedDivisible f a
+ Data.Functor.Contravariant.Divise: WrapDivisible :: f a -> WrappedDivisible (f :: k -> Type) (a :: k)
- Data.Functor.Contravariant.Divise: [unwrapDivisible] :: WrappedDivisible f a -> f a
+ Data.Functor.Contravariant.Divise: [unwrapDivisible] :: WrappedDivisible (f :: k -> Type) (a :: k) -> f a
- Data.Functor.Contravariant.Divise: class Contravariant f => Divise f
+ Data.Functor.Contravariant.Divise: class Contravariant f => Divise (f :: Type -> Type)
- Data.Functor.Contravariant.Divise: newtype WrappedDivisible f a
+ Data.Functor.Contravariant.Divise: newtype WrappedDivisible (f :: k -> Type) (a :: k)
- Data.Functor.Contravariant.Divisible.Free: Div :: [Coyoneda f a] -> Div f a
+ Data.Functor.Contravariant.Divisible.Free: Div :: [Coyoneda f a] -> Div (f :: Type -> Type) a
- Data.Functor.Contravariant.Divisible.Free: Div1 :: NonEmpty (Coyoneda f a) -> Div1 f a
+ Data.Functor.Contravariant.Divisible.Free: Div1 :: NonEmpty (Coyoneda f a) -> Div1 (f :: Type -> Type) a
- Data.Functor.Contravariant.Divisible.Free: [Choose] :: (a -> Either b c) -> f b -> Dec f c -> Dec f a
+ Data.Functor.Contravariant.Divisible.Free: [Choose] :: forall b b1 c (a :: Type -> Type). (b -> Either b1 c) -> a b1 -> Dec a c -> Dec a b
- Data.Functor.Contravariant.Divisible.Free: [Dec1] :: (a -> Either b c) -> f b -> Dec f c -> Dec1 f a
+ Data.Functor.Contravariant.Divisible.Free: [Dec1] :: forall b b1 c (a :: Type -> Type). (b -> Either b1 c) -> a b1 -> Dec a c -> Dec1 a b
- Data.Functor.Contravariant.Divisible.Free: [Lose] :: (a -> Void) -> Dec f a
+ Data.Functor.Contravariant.Divisible.Free: [Lose] :: forall b (a :: Type -> Type). (b -> Void) -> Dec a b
- Data.Functor.Contravariant.Divisible.Free: [unDiv1] :: Div1 f a -> NonEmpty (Coyoneda f a)
+ Data.Functor.Contravariant.Divisible.Free: [unDiv1] :: Div1 (f :: Type -> Type) a -> NonEmpty (Coyoneda f a)
- Data.Functor.Contravariant.Divisible.Free: [unDiv] :: Div f a -> [Coyoneda f a]
+ Data.Functor.Contravariant.Divisible.Free: [unDiv] :: Div (f :: Type -> Type) a -> [Coyoneda f a]
- Data.Functor.Contravariant.Divisible.Free: data Dec :: (Type -> Type) -> Type -> Type
+ Data.Functor.Contravariant.Divisible.Free: data Dec (a :: Type -> Type) b
- Data.Functor.Contravariant.Divisible.Free: data Dec1 :: (Type -> Type) -> Type -> Type
+ Data.Functor.Contravariant.Divisible.Free: data Dec1 (a :: Type -> Type) b
- Data.Functor.Contravariant.Divisible.Free: div1NonEmptyF :: Contravariant f => Div1 f ~> NonEmptyF f
+ Data.Functor.Contravariant.Divisible.Free: div1NonEmptyF :: forall (f :: Type -> Type). Contravariant f => Div1 f ~> NonEmptyF f
- Data.Functor.Contravariant.Divisible.Free: divListF :: forall f. Contravariant f => Div f ~> ListF f
+ Data.Functor.Contravariant.Divisible.Free: divListF :: forall (f :: Type -> Type). Contravariant f => Div f ~> ListF f
- Data.Functor.Contravariant.Divisible.Free: hoistDec :: forall f g. (f ~> g) -> Dec f ~> Dec g
+ Data.Functor.Contravariant.Divisible.Free: hoistDec :: forall (f :: Type -> Type) (g :: Type -> Type). (f ~> g) -> Dec f ~> Dec g
- Data.Functor.Contravariant.Divisible.Free: hoistDec1 :: forall f g. (f ~> g) -> Dec1 f ~> Dec1 g
+ Data.Functor.Contravariant.Divisible.Free: hoistDec1 :: forall (f :: Type -> Type) (g :: Type -> Type). (f ~> g) -> Dec1 f ~> Dec1 g
- Data.Functor.Contravariant.Divisible.Free: hoistDiv :: forall f g. (f ~> g) -> Div f ~> Div g
+ Data.Functor.Contravariant.Divisible.Free: hoistDiv :: forall (f :: Type -> Type) (g :: Type -> Type). (f ~> g) -> Div f ~> Div g
- Data.Functor.Contravariant.Divisible.Free: hoistDiv1 :: (f ~> g) -> Div1 f ~> Div1 g
+ Data.Functor.Contravariant.Divisible.Free: hoistDiv1 :: forall (f :: Type -> Type) (g :: Type -> Type). (f ~> g) -> Div1 f ~> Div1 g
- Data.Functor.Contravariant.Divisible.Free: liftDec :: f ~> Dec f
+ Data.Functor.Contravariant.Divisible.Free: liftDec :: f x -> Dec f x
- Data.Functor.Contravariant.Divisible.Free: liftDec1 :: f ~> Dec1 f
+ Data.Functor.Contravariant.Divisible.Free: liftDec1 :: f x -> Dec1 f x
- Data.Functor.Contravariant.Divisible.Free: liftDiv :: f ~> Div f
+ Data.Functor.Contravariant.Divisible.Free: liftDiv :: f x -> Div f x
- Data.Functor.Contravariant.Divisible.Free: liftDiv1 :: f ~> Div1 f
+ Data.Functor.Contravariant.Divisible.Free: liftDiv1 :: f x -> Div1 f x
- Data.Functor.Contravariant.Divisible.Free: listFDiv :: ListF f ~> Div f
+ Data.Functor.Contravariant.Divisible.Free: listFDiv :: forall (f :: Type -> Type) x. ListF f x -> Div f x
- Data.Functor.Contravariant.Divisible.Free: newtype Div f a
+ Data.Functor.Contravariant.Divisible.Free: newtype Div (f :: Type -> Type) a
- Data.Functor.Contravariant.Divisible.Free: newtype Div1 f a
+ Data.Functor.Contravariant.Divisible.Free: newtype Div1 (f :: Type -> Type) a
- Data.Functor.Contravariant.Divisible.Free: nonEmptyFDiv1 :: NonEmptyF f ~> Div1 f
+ Data.Functor.Contravariant.Divisible.Free: nonEmptyFDiv1 :: forall (f :: Type -> Type) x. NonEmptyF f x -> Div1 f x
- Data.Functor.Contravariant.Divisible.Free: runDec :: forall f g. Conclude g => (f ~> g) -> Dec f ~> g
+ Data.Functor.Contravariant.Divisible.Free: runDec :: forall (f :: Type -> Type) (g :: Type -> Type). Conclude g => (f ~> g) -> Dec f ~> g
- Data.Functor.Contravariant.Divisible.Free: runDec1 :: Decide g => (f ~> g) -> Dec1 f ~> g
+ Data.Functor.Contravariant.Divisible.Free: runDec1 :: forall (g :: Type -> Type) (f :: Type -> Type). Decide g => (f ~> g) -> Dec1 f ~> g
- Data.Functor.Contravariant.Divisible.Free: runDiv :: forall f g. Divisible g => (f ~> g) -> Div f ~> g
+ Data.Functor.Contravariant.Divisible.Free: runDiv :: forall (f :: Type -> Type) (g :: Type -> Type). Divisible g => (f ~> g) -> Div f ~> g
- Data.Functor.Contravariant.Divisible.Free: runDiv1 :: Divise g => (f ~> g) -> Div1 f ~> g
+ Data.Functor.Contravariant.Divisible.Free: runDiv1 :: forall (g :: Type -> Type) (f :: Type -> Type). Divise g => (f ~> g) -> Div1 f ~> g
- Data.Functor.Contravariant.Divisible.Free: toDec :: Dec1 f a -> Dec f a
+ Data.Functor.Contravariant.Divisible.Free: toDec :: forall (f :: Type -> Type) a. Dec1 f a -> Dec f a
- Data.Functor.Contravariant.Divisible.Free: toDiv :: Div1 f ~> Div f
+ Data.Functor.Contravariant.Divisible.Free: toDiv :: forall (f :: Type -> Type) x. Div1 f x -> Div f x
- Data.Functor.Contravariant.Night: [Night] :: f b -> g c -> (a -> Either b c) -> Night f g a
+ Data.Functor.Contravariant.Night: [Night] :: forall (a :: Type -> Type) b1 (b :: Type -> Type) c1 c. a b1 -> b c1 -> (c -> Either b1 c1) -> Night a b c
- Data.Functor.Contravariant.Night: assoc :: Night f (Night g h) ~> Night (Night f g) h
+ Data.Functor.Contravariant.Night: assoc :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type) x. Night f (Night g h) x -> Night (Night f g) h x
- Data.Functor.Contravariant.Night: data Night :: (Type -> Type) -> (Type -> Type) -> (Type -> Type)
+ Data.Functor.Contravariant.Night: data Night (a :: Type -> Type) (b :: Type -> Type) c
- Data.Functor.Contravariant.Night: elim1 :: Contravariant g => Night Not g ~> g
+ Data.Functor.Contravariant.Night: elim1 :: forall (g :: Type -> Type). Contravariant g => Night Not g ~> g
- Data.Functor.Contravariant.Night: elim2 :: Contravariant f => Night f Not ~> f
+ Data.Functor.Contravariant.Night: elim2 :: forall (f :: Type -> Type). Contravariant f => Night f Not ~> f
- Data.Functor.Contravariant.Night: intro1 :: g ~> Night Not g
+ Data.Functor.Contravariant.Night: intro1 :: g x -> Night Not g x
- Data.Functor.Contravariant.Night: intro2 :: f ~> Night f Not
+ Data.Functor.Contravariant.Night: intro2 :: f x -> Night f Not x
- Data.Functor.Contravariant.Night: necide :: Decide f => Night f f ~> f
+ Data.Functor.Contravariant.Night: necide :: forall (f :: Type -> Type). Decide f => Night f f ~> f
- Data.Functor.Contravariant.Night: runNight :: Decide h => (f ~> h) -> (g ~> h) -> Night f g ~> h
+ Data.Functor.Contravariant.Night: runNight :: forall (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). Decide h => (f ~> h) -> (g ~> h) -> Night f g ~> h
- Data.Functor.Contravariant.Night: swapped :: Night f g ~> Night g f
+ Data.Functor.Contravariant.Night: swapped :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> Night g f x
- Data.Functor.Contravariant.Night: trans1 :: (f ~> h) -> Night f g ~> Night h g
+ Data.Functor.Contravariant.Night: trans1 :: forall (f :: Type -> Type) (h :: Type -> Type) (g :: Type -> Type). (f ~> h) -> Night f g ~> Night h g
- Data.Functor.Contravariant.Night: trans2 :: (g ~> h) -> Night f g ~> Night f h
+ Data.Functor.Contravariant.Night: trans2 :: forall (g :: Type -> Type) (h :: Type -> Type) (f :: Type -> Type). (g ~> h) -> Night f g ~> Night f h
- Data.Functor.Contravariant.Night: unassoc :: Night (Night f g) h ~> Night f (Night g h)
+ Data.Functor.Contravariant.Night: unassoc :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type) x. Night (Night f g) h x -> Night f (Night g h) x
- Data.Functor.Invariant.Inplicative: WrapApplicativeOnly :: f a -> WrappedApplicativeOnly f a
+ Data.Functor.Invariant.Inplicative: WrapApplicativeOnly :: f a -> WrappedApplicativeOnly (f :: k -> Type) (a :: k)
- Data.Functor.Invariant.Inplicative: WrapDivisibleOnly :: f a -> WrappedDivisibleOnly f a
+ Data.Functor.Invariant.Inplicative: WrapDivisibleOnly :: f a -> WrappedDivisibleOnly (f :: k -> Type) (a :: k)
- Data.Functor.Invariant.Inplicative: [unwrapApplicativeOnly] :: WrappedApplicativeOnly f a -> f a
+ Data.Functor.Invariant.Inplicative: [unwrapApplicativeOnly] :: WrappedApplicativeOnly (f :: k -> Type) (a :: k) -> f a
- Data.Functor.Invariant.Inplicative: [unwrapDivisibleOnly] :: WrappedDivisibleOnly f a -> f a
+ Data.Functor.Invariant.Inplicative: [unwrapDivisibleOnly] :: WrappedDivisibleOnly (f :: k -> Type) (a :: k) -> f a
- Data.Functor.Invariant.Inplicative: class Inply f => Inplicative f
+ Data.Functor.Invariant.Inplicative: class Inply f => Inplicative (f :: Type -> Type)
- Data.Functor.Invariant.Inplicative: class Invariant f => Inply f
+ Data.Functor.Invariant.Inplicative: class Invariant f => Inply (f :: Type -> Type)
- Data.Functor.Invariant.Inplicative: dather :: Inply f => Day f f ~> f
+ Data.Functor.Invariant.Inplicative: dather :: forall (f :: Type -> Type). Inply f => Day f f ~> f
- Data.Functor.Invariant.Inplicative: gatherN :: forall f as b. (Inplicative f, IsoXRec Identity as, RecordCurry as) => Curried as b -> (b -> XRec Identity as) -> CurriedF f as (f b)
+ Data.Functor.Invariant.Inplicative: gatherN :: forall (f :: Type -> Type) (as :: [Type]) b. (Inplicative f, IsoXRec Identity as, RecordCurry as) => Curried as b -> (b -> XRec Identity as) -> CurriedF f as (f b)
- Data.Functor.Invariant.Inplicative: gatherN1 :: forall f a as b. (Inply f, IsoXRec Identity as, RecordCurry as) => Curried (a ': as) b -> (b -> XRec Identity (a ': as)) -> CurriedF f (a ': as) (f b)
+ Data.Functor.Invariant.Inplicative: gatherN1 :: forall (f :: Type -> Type) a (as :: [Type]) b. (Inply f, IsoXRec Identity as, RecordCurry as) => Curried (a ': as) b -> (b -> XRec Identity (a ': as)) -> CurriedF f (a ': as) (f b)
- Data.Functor.Invariant.Inplicative: gatheredN :: Inplicative f => NP f as -> f (NP I as)
+ Data.Functor.Invariant.Inplicative: gatheredN :: forall f (as :: [Type]). Inplicative f => NP f as -> f (NP I as)
- Data.Functor.Invariant.Inplicative: gatheredN1 :: Inply f => NP f (a ': as) -> f (NP I (a ': as))
+ Data.Functor.Invariant.Inplicative: gatheredN1 :: forall f a (as :: [Type]). Inply f => NP f (a ': as) -> f (NP I (a ': as))
- Data.Functor.Invariant.Inplicative: gatheredN1Map :: Inplicative f => (NP I (a ': as) -> b) -> (b -> NP I (a ': as)) -> NP f (a ': as) -> f b
+ Data.Functor.Invariant.Inplicative: gatheredN1Map :: forall f a (as :: [Type]) b. Inplicative f => (NP I (a ': as) -> b) -> (b -> NP I (a ': as)) -> NP f (a ': as) -> f b
- Data.Functor.Invariant.Inplicative: gatheredN1MapRec :: Inplicative f => (XRec Identity (a ': as) -> b) -> (b -> XRec Identity (a ': as)) -> Rec f (a ': as) -> f b
+ Data.Functor.Invariant.Inplicative: gatheredN1MapRec :: forall f a (as :: [Type]) b. Inplicative f => (XRec Identity (a ': as) -> b) -> (b -> XRec Identity (a ': as)) -> Rec f (a ': as) -> f b
- Data.Functor.Invariant.Inplicative: gatheredN1Rec :: Inply f => Rec f (a ': as) -> f (XRec Identity (a ': as))
+ Data.Functor.Invariant.Inplicative: gatheredN1Rec :: forall f a (as :: [Type]). Inply f => Rec f (a ': as) -> f (XRec Identity (a ': as))
- Data.Functor.Invariant.Inplicative: gatheredNMap :: Inplicative f => (NP I as -> b) -> (b -> NP I as) -> NP f as -> f b
+ Data.Functor.Invariant.Inplicative: gatheredNMap :: forall f (as :: [Type]) b. Inplicative f => (NP I as -> b) -> (b -> NP I as) -> NP f as -> f b
- Data.Functor.Invariant.Inplicative: gatheredNMapRec :: Inplicative f => (XRec Identity as -> b) -> (b -> XRec Identity as) -> Rec f as -> f b
+ Data.Functor.Invariant.Inplicative: gatheredNMapRec :: forall f (as :: [Type]) b. Inplicative f => (XRec Identity as -> b) -> (b -> XRec Identity as) -> Rec f as -> f b
- Data.Functor.Invariant.Inplicative: gatheredNRec :: Inplicative f => Rec f as -> f (XRec Identity as)
+ Data.Functor.Invariant.Inplicative: gatheredNRec :: forall f (as :: [Type]). Inplicative f => Rec f as -> f (XRec Identity as)
- Data.Functor.Invariant.Inplicative: newtype WrappedApplicativeOnly f a
+ Data.Functor.Invariant.Inplicative: newtype WrappedApplicativeOnly (f :: k -> Type) (a :: k)
- Data.Functor.Invariant.Inplicative: newtype WrappedDivisibleOnly f a
+ Data.Functor.Invariant.Inplicative: newtype WrappedDivisibleOnly (f :: k -> Type) (a :: k)
- Data.Functor.Invariant.Inplicative: runDay :: Inply h => (f ~> h) -> (g ~> h) -> Day f g ~> h
+ Data.Functor.Invariant.Inplicative: runDay :: forall (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). Inply h => (f ~> h) -> (g ~> h) -> Day f g ~> h
- Data.Functor.Invariant.Inplicative: runDayApply :: forall f g h. Apply h => (f ~> h) -> (g ~> h) -> Day f g ~> h
+ Data.Functor.Invariant.Inplicative: runDayApply :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). Apply h => (f ~> h) -> (g ~> h) -> Day f g ~> h
- Data.Functor.Invariant.Inplicative: runDayDivise :: forall f g h. Divise h => (f ~> h) -> (g ~> h) -> Day f g ~> h
+ Data.Functor.Invariant.Inplicative: runDayDivise :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). Divise h => (f ~> h) -> (g ~> h) -> Day f g ~> h
- Data.Functor.Invariant.Inplicative.Free: DivAp :: Chain Day Identity f a -> DivAp f a
+ Data.Functor.Invariant.Inplicative.Free: DivAp :: Chain Day Identity f a -> DivAp (f :: Type -> Type) a
- Data.Functor.Invariant.Inplicative.Free: DivAp1_ :: Chain1 Day f a -> DivAp1 f a
+ Data.Functor.Invariant.Inplicative.Free: DivAp1_ :: Chain1 Day f a -> DivAp1 (f :: Type -> Type) a
- Data.Functor.Invariant.Inplicative.Free: [unDivAp1] :: DivAp1 f a -> Chain1 Day f a
+ Data.Functor.Invariant.Inplicative.Free: [unDivAp1] :: DivAp1 (f :: Type -> Type) a -> Chain1 Day f a
- Data.Functor.Invariant.Inplicative.Free: [unDivAp] :: DivAp f a -> Chain Day Identity f a
+ Data.Functor.Invariant.Inplicative.Free: [unDivAp] :: DivAp (f :: Type -> Type) a -> Chain Day Identity f a
- Data.Functor.Invariant.Inplicative.Free: assembleDivAp :: NP f as -> DivAp f (NP I as)
+ Data.Functor.Invariant.Inplicative.Free: assembleDivAp :: forall (f :: Type -> Type) (as :: [Type]). NP f as -> DivAp f (NP I as)
- Data.Functor.Invariant.Inplicative.Free: assembleDivAp1 :: Invariant f => NP f (a ': as) -> DivAp1 f (NP I (a ': as))
+ Data.Functor.Invariant.Inplicative.Free: assembleDivAp1 :: forall (f :: Type -> Type) a (as :: [Type]). Invariant f => NP f (a ': as) -> DivAp1 f (NP I (a ': as))
- Data.Functor.Invariant.Inplicative.Free: assembleDivAp1Rec :: Invariant f => Rec f (a ': as) -> DivAp1 f (XRec Identity (a ': as))
+ Data.Functor.Invariant.Inplicative.Free: assembleDivAp1Rec :: forall (f :: Type -> Type) a (as :: [Type]). Invariant f => Rec f (a ': as) -> DivAp1 f (XRec Identity (a ': as))
- Data.Functor.Invariant.Inplicative.Free: assembleDivApRec :: Rec f as -> DivAp f (XRec Identity as)
+ Data.Functor.Invariant.Inplicative.Free: assembleDivApRec :: forall (f :: Type -> Type) (as :: [Type]). Rec f as -> DivAp f (XRec Identity as)
- Data.Functor.Invariant.Inplicative.Free: divApAp :: DivAp f ~> Ap f
+ Data.Functor.Invariant.Inplicative.Free: divApAp :: forall (f :: Type -> Type) x. DivAp f x -> Ap f x
- Data.Functor.Invariant.Inplicative.Free: divApAp1 :: DivAp1 f ~> Ap1 f
+ Data.Functor.Invariant.Inplicative.Free: divApAp1 :: forall (f :: Type -> Type) x. DivAp1 f x -> Ap1 f x
- Data.Functor.Invariant.Inplicative.Free: divApDiv :: DivAp f ~> Div f
+ Data.Functor.Invariant.Inplicative.Free: divApDiv :: forall (f :: Type -> Type) x. DivAp f x -> Div f x
- Data.Functor.Invariant.Inplicative.Free: divApDiv1 :: DivAp1 f ~> Div1 f
+ Data.Functor.Invariant.Inplicative.Free: divApDiv1 :: forall (f :: Type -> Type) x. DivAp1 f x -> Div1 f x
- Data.Functor.Invariant.Inplicative.Free: foldDivAp :: (forall x. x -> g x) -> (Day f g ~> g) -> DivAp f ~> g
+ Data.Functor.Invariant.Inplicative.Free: foldDivAp :: forall g (f :: Type -> Type). (forall x. () => x -> g x) -> (Day f g ~> g) -> DivAp f ~> g
- Data.Functor.Invariant.Inplicative.Free: foldDivAp1 :: (f ~> g) -> (Day f g ~> g) -> DivAp1 f ~> g
+ Data.Functor.Invariant.Inplicative.Free: foldDivAp1 :: forall (f :: Type -> Type) (g :: Type -> Type). (f ~> g) -> (Day f g ~> g) -> DivAp1 f ~> g
- Data.Functor.Invariant.Inplicative.Free: newtype DivAp f a
+ Data.Functor.Invariant.Inplicative.Free: newtype DivAp (f :: Type -> Type) a
- Data.Functor.Invariant.Inplicative.Free: newtype DivAp1 f a
+ Data.Functor.Invariant.Inplicative.Free: newtype DivAp1 (f :: Type -> Type) a
- Data.Functor.Invariant.Inplicative.Free: pattern DivAp1 :: Invariant f => (b -> c -> a) -> (a -> (b, c)) -> f b -> DivAp f c -> DivAp1 f a
+ Data.Functor.Invariant.Inplicative.Free: pattern DivAp1 :: forall f a b c. Invariant f => (b -> c -> a) -> (a -> (b, c)) -> f b -> DivAp f c -> DivAp1 f a
- Data.Functor.Invariant.Inplicative.Free: runCoDivAp :: forall f g. Applicative g => (f ~> g) -> DivAp f ~> g
+ Data.Functor.Invariant.Inplicative.Free: runCoDivAp :: forall (f :: Type -> Type) (g :: Type -> Type). Applicative g => (f ~> g) -> DivAp f ~> g
- Data.Functor.Invariant.Inplicative.Free: runCoDivAp1 :: forall f g. Apply g => (f ~> g) -> DivAp1 f ~> g
+ Data.Functor.Invariant.Inplicative.Free: runCoDivAp1 :: forall (f :: Type -> Type) (g :: Type -> Type). Apply g => (f ~> g) -> DivAp1 f ~> g
- Data.Functor.Invariant.Inplicative.Free: runContraDivAp :: forall f g. Divisible g => (f ~> g) -> DivAp f ~> g
+ Data.Functor.Invariant.Inplicative.Free: runContraDivAp :: forall (f :: Type -> Type) (g :: Type -> Type). Divisible g => (f ~> g) -> DivAp f ~> g
- Data.Functor.Invariant.Inplicative.Free: runContraDivAp1 :: forall f g. Divise g => (f ~> g) -> DivAp1 f ~> g
+ Data.Functor.Invariant.Inplicative.Free: runContraDivAp1 :: forall (f :: Type -> Type) (g :: Type -> Type). Divise g => (f ~> g) -> DivAp1 f ~> g
- Data.Functor.Invariant.Internative: class Invariant f => Inalt f
+ Data.Functor.Invariant.Internative: class Invariant f => Inalt (f :: Type -> Type)
- Data.Functor.Invariant.Internative: class Inalt f => Inplus f
+ Data.Functor.Invariant.Internative: class Inalt f => Inplus (f :: Type -> Type)
- Data.Functor.Invariant.Internative: class (Inplus f, Inplicative f) => Internative f
+ Data.Functor.Invariant.Internative: class (Inplus f, Inplicative f) => Internative (f :: Type -> Type)
- Data.Functor.Invariant.Internative: swervedN :: Inplus f => NP f as -> f (NS I as)
+ Data.Functor.Invariant.Internative: swervedN :: forall f (as :: [Type]). Inplus f => NP f as -> f (NS I as)
- Data.Functor.Invariant.Internative: swervedN1 :: Inalt f => NP f (a ': as) -> f (NS I (a ': as))
+ Data.Functor.Invariant.Internative: swervedN1 :: forall f a (as :: [Type]). Inalt f => NP f (a ': as) -> f (NS I (a ': as))
- Data.Functor.Invariant.Internative: swervedN1Map :: Inalt f => (NS I (a ': as) -> b) -> (b -> NS I (a ': as)) -> NP f (a ': as) -> f b
+ Data.Functor.Invariant.Internative: swervedN1Map :: forall f a (as :: [Type]) b. Inalt f => (NS I (a ': as) -> b) -> (b -> NS I (a ': as)) -> NP f (a ': as) -> f b
- Data.Functor.Invariant.Internative: swervedNMap :: Inplus f => (NS I as -> b) -> (b -> NS I as) -> NP f as -> f b
+ Data.Functor.Invariant.Internative: swervedNMap :: forall f (as :: [Type]) b. Inplus f => (NS I as -> b) -> (b -> NS I as) -> NP f as -> f b
- Data.Functor.Invariant.Internative.Free: DecAlt :: Chain Night Not f a -> DecAlt f a
+ Data.Functor.Invariant.Internative.Free: DecAlt :: Chain Night Not f a -> DecAlt (f :: Type -> Type) a
- Data.Functor.Invariant.Internative.Free: DecAlt1_ :: Chain1 Night f a -> DecAlt1 f a
+ Data.Functor.Invariant.Internative.Free: DecAlt1_ :: Chain1 Night f a -> DecAlt1 (f :: Type -> Type) a
- Data.Functor.Invariant.Internative.Free: [unDecAlt1] :: DecAlt1 f a -> Chain1 Night f a
+ Data.Functor.Invariant.Internative.Free: [unDecAlt1] :: DecAlt1 (f :: Type -> Type) a -> Chain1 Night f a
- Data.Functor.Invariant.Internative.Free: [unDecAlt] :: DecAlt f a -> Chain Night Not f a
+ Data.Functor.Invariant.Internative.Free: [unDecAlt] :: DecAlt (f :: Type -> Type) a -> Chain Night Not f a
- Data.Functor.Invariant.Internative.Free: assembleDecAlt :: NP f as -> DecAlt f (NS I as)
+ Data.Functor.Invariant.Internative.Free: assembleDecAlt :: forall (f :: Type -> Type) (as :: [Type]). NP f as -> DecAlt f (NS I as)
- Data.Functor.Invariant.Internative.Free: assembleDecAlt1 :: Invariant f => NP f (a ': as) -> DecAlt1 f (NS I (a ': as))
+ Data.Functor.Invariant.Internative.Free: assembleDecAlt1 :: forall (f :: Type -> Type) a (as :: [Type]). Invariant f => NP f (a ': as) -> DecAlt1 f (NS I (a ': as))
- Data.Functor.Invariant.Internative.Free: decAltDec :: DecAlt f ~> Dec f
+ Data.Functor.Invariant.Internative.Free: decAltDec :: forall (f :: Type -> Type) x. DecAlt f x -> Dec f x
- Data.Functor.Invariant.Internative.Free: decAltDec1 :: DecAlt1 f ~> Dec1 f
+ Data.Functor.Invariant.Internative.Free: decAltDec1 :: forall (f :: Type -> Type) x. DecAlt1 f x -> Dec1 f x
- Data.Functor.Invariant.Internative.Free: decAltListF :: Functor f => DecAlt f ~> ListF f
+ Data.Functor.Invariant.Internative.Free: decAltListF :: forall (f :: Type -> Type). Functor f => DecAlt f ~> ListF f
- Data.Functor.Invariant.Internative.Free: decAltListF_ :: DecAlt f ~> ComposeT ListF Coyoneda f
+ Data.Functor.Invariant.Internative.Free: decAltListF_ :: forall (f :: Type -> Type) x. DecAlt f x -> ComposeT (ListF :: (Type -> Type) -> Type -> Type) Coyoneda f x
- Data.Functor.Invariant.Internative.Free: decAltNonEmptyF :: Functor f => DecAlt1 f ~> NonEmptyF f
+ Data.Functor.Invariant.Internative.Free: decAltNonEmptyF :: forall (f :: Type -> Type). Functor f => DecAlt1 f ~> NonEmptyF f
- Data.Functor.Invariant.Internative.Free: decAltNonEmptyF_ :: DecAlt1 f ~> ComposeT NonEmptyF Coyoneda f
+ Data.Functor.Invariant.Internative.Free: decAltNonEmptyF_ :: forall (f :: Type -> Type) x. DecAlt1 f x -> ComposeT (NonEmptyF :: (Type -> Type) -> Type -> Type) Coyoneda f x
- Data.Functor.Invariant.Internative.Free: foldDecAlt :: (forall x. (x -> Void) -> g x) -> (Night f g ~> g) -> DecAlt f ~> g
+ Data.Functor.Invariant.Internative.Free: foldDecAlt :: forall g (f :: Type -> Type). (forall x. () => (x -> Void) -> g x) -> (Night f g ~> g) -> DecAlt f ~> g
- Data.Functor.Invariant.Internative.Free: foldDecAlt1 :: (f ~> g) -> (Night f g ~> g) -> DecAlt1 f ~> g
+ Data.Functor.Invariant.Internative.Free: foldDecAlt1 :: forall (f :: Type -> Type) (g :: Type -> Type). (f ~> g) -> (Night f g ~> g) -> DecAlt1 f ~> g
- Data.Functor.Invariant.Internative.Free: newtype DecAlt f a
+ Data.Functor.Invariant.Internative.Free: newtype DecAlt (f :: Type -> Type) a
- Data.Functor.Invariant.Internative.Free: newtype DecAlt1 f a
+ Data.Functor.Invariant.Internative.Free: newtype DecAlt1 (f :: Type -> Type) a
- Data.Functor.Invariant.Internative.Free: pattern DecAlt1 :: Invariant f => (b -> a) -> (c -> a) -> (a -> Either b c) -> f b -> DecAlt f c -> DecAlt1 f a
+ Data.Functor.Invariant.Internative.Free: pattern DecAlt1 :: forall f a b c. Invariant f => (b -> a) -> (c -> a) -> (a -> Either b c) -> f b -> DecAlt f c -> DecAlt1 f a
- Data.Functor.Invariant.Internative.Free: runCoDecAlt :: forall f g. Plus g => (f ~> g) -> DecAlt f ~> g
+ Data.Functor.Invariant.Internative.Free: runCoDecAlt :: forall (f :: Type -> Type) (g :: Type -> Type). Plus g => (f ~> g) -> DecAlt f ~> g
- Data.Functor.Invariant.Internative.Free: runCoDecAlt1 :: forall f g. Alt g => (f ~> g) -> DecAlt1 f ~> g
+ Data.Functor.Invariant.Internative.Free: runCoDecAlt1 :: forall (f :: Type -> Type) (g :: Type -> Type). Alt g => (f ~> g) -> DecAlt1 f ~> g
- Data.Functor.Invariant.Internative.Free: runContraDecAlt :: forall f g. Conclude g => (f ~> g) -> DecAlt f ~> g
+ Data.Functor.Invariant.Internative.Free: runContraDecAlt :: forall (f :: Type -> Type) (g :: Type -> Type). Conclude g => (f ~> g) -> DecAlt f ~> g
- Data.Functor.Invariant.Internative.Free: runContraDecAlt1 :: forall f g. Decide g => (f ~> g) -> DecAlt1 f ~> g
+ Data.Functor.Invariant.Internative.Free: runContraDecAlt1 :: forall (f :: Type -> Type) (g :: Type -> Type). Decide g => (f ~> g) -> DecAlt1 f ~> g
- Data.Functor.Invariant.Night: [Night] :: f b -> g c -> (b -> a) -> (c -> a) -> (a -> Either b c) -> Night f g a
+ Data.Functor.Invariant.Night: [Night] :: forall (a :: Type -> Type) b1 (b :: Type -> Type) c1 c. a b1 -> b c1 -> (b1 -> c) -> (c1 -> c) -> (c -> Either b1 c1) -> Night a b c
- Data.Functor.Invariant.Night: assoc :: Night f (Night g h) ~> Night (Night f g) h
+ Data.Functor.Invariant.Night: assoc :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type) x. Night f (Night g h) x -> Night (Night f g) h x
- Data.Functor.Invariant.Night: data Night :: (Type -> Type) -> (Type -> Type) -> (Type -> Type)
+ Data.Functor.Invariant.Night: data Night (a :: Type -> Type) (b :: Type -> Type) c
- Data.Functor.Invariant.Night: elim1 :: Invariant g => Night Not g ~> g
+ Data.Functor.Invariant.Night: elim1 :: forall (g :: Type -> Type). Invariant g => Night Not g ~> g
- Data.Functor.Invariant.Night: elim2 :: Invariant f => Night f Not ~> f
+ Data.Functor.Invariant.Night: elim2 :: forall (f :: Type -> Type). Invariant f => Night f Not ~> f
- Data.Functor.Invariant.Night: intro1 :: g ~> Night Not g
+ Data.Functor.Invariant.Night: intro1 :: g x -> Night Not g x
- Data.Functor.Invariant.Night: intro2 :: f ~> Night f Not
+ Data.Functor.Invariant.Night: intro2 :: f x -> Night f Not x
- Data.Functor.Invariant.Night: nerve :: Inalt f => Night f f ~> f
+ Data.Functor.Invariant.Night: nerve :: forall (f :: Type -> Type). Inalt f => Night f f ~> f
- Data.Functor.Invariant.Night: runNight :: Inalt h => (f ~> h) -> (g ~> h) -> Night f g ~> h
+ Data.Functor.Invariant.Night: runNight :: forall (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). Inalt h => (f ~> h) -> (g ~> h) -> Night f g ~> h
- Data.Functor.Invariant.Night: runNightAlt :: forall f g h. Alt h => (f ~> h) -> (g ~> h) -> Night f g ~> h
+ Data.Functor.Invariant.Night: runNightAlt :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). Alt h => (f ~> h) -> (g ~> h) -> Night f g ~> h
- Data.Functor.Invariant.Night: runNightDecide :: forall f g h. Decide h => (f ~> h) -> (g ~> h) -> Night f g ~> h
+ Data.Functor.Invariant.Night: runNightDecide :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). Decide h => (f ~> h) -> (g ~> h) -> Night f g ~> h
- Data.Functor.Invariant.Night: swapped :: Night f g ~> Night g f
+ Data.Functor.Invariant.Night: swapped :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> Night g f x
- Data.Functor.Invariant.Night: toCoNight :: (Functor f, Functor g) => Night f g ~> (f :*: g)
+ Data.Functor.Invariant.Night: toCoNight :: forall (f :: Type -> Type) (g :: Type -> Type). (Functor f, Functor g) => Night f g ~> (f :*: g)
- Data.Functor.Invariant.Night: toCoNight_ :: Night f g ~> (Coyoneda f :*: Coyoneda g)
+ Data.Functor.Invariant.Night: toCoNight_ :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> (Coyoneda f :*: Coyoneda g) x
- Data.Functor.Invariant.Night: toContraNight :: Night f g ~> Night f g
+ Data.Functor.Invariant.Night: toContraNight :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> Night f g x
- Data.Functor.Invariant.Night: trans1 :: (f ~> h) -> Night f g ~> Night h g
+ Data.Functor.Invariant.Night: trans1 :: forall (f :: Type -> Type) (h :: Type -> Type) (g :: Type -> Type). (f ~> h) -> Night f g ~> Night h g
- Data.Functor.Invariant.Night: trans2 :: (g ~> h) -> Night f g ~> Night f h
+ Data.Functor.Invariant.Night: trans2 :: forall (g :: Type -> Type) (h :: Type -> Type) (f :: Type -> Type). (g ~> h) -> Night f g ~> Night f h
- Data.Functor.Invariant.Night: unassoc :: Night (Night f g) h ~> Night f (Night g h)
+ Data.Functor.Invariant.Night: unassoc :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type) x. Night (Night f g) h x -> Night f (Night g h) x
- Data.HBifunctor: LeftF :: f a -> LeftF f g a
+ Data.HBifunctor: LeftF :: f a -> LeftF (f :: k -> Type) (g :: k1) (a :: k)
- Data.HBifunctor: RightF :: g a -> RightF f g a
+ Data.HBifunctor: RightF :: g a -> RightF (f :: k) (g :: k1 -> Type) (a :: k1)
- Data.HBifunctor: WrapHBifunctor :: t f g a -> WrappedHBifunctor t (f :: k -> Type) (g :: k -> Type) (a :: k)
+ Data.HBifunctor: WrapHBifunctor :: t f g a -> WrappedHBifunctor (t :: (k -> Type) -> (k -> Type) -> k -> Type) (f :: k -> Type) (g :: k -> Type) (a :: k)
- Data.HBifunctor: [runLeftF] :: LeftF f g a -> f a
+ Data.HBifunctor: [runLeftF] :: LeftF (f :: k -> Type) (g :: k1) (a :: k) -> f a
- Data.HBifunctor: [runRightF] :: RightF f g a -> g a
+ Data.HBifunctor: [runRightF] :: RightF (f :: k) (g :: k1 -> Type) (a :: k1) -> g a
- Data.HBifunctor: [unwrapHBifunctor] :: WrappedHBifunctor t (f :: k -> Type) (g :: k -> Type) (a :: k) -> t f g a
+ Data.HBifunctor: [unwrapHBifunctor] :: WrappedHBifunctor (t :: (k -> Type) -> (k -> Type) -> k -> Type) (f :: k -> Type) (g :: k -> Type) (a :: k) -> t f g a
- Data.HBifunctor: class HBifunctor (t :: (k -> Type) -> (k -> Type) -> k -> Type)
+ Data.HBifunctor: class HBifunctor (t :: k -> Type -> k -> Type -> k -> Type)
- Data.HBifunctor: hbimap :: HBifunctor t => (f ~> j) -> (g ~> l) -> t f g ~> t j l
+ Data.HBifunctor: hbimap :: forall (f :: k -> Type) (j :: k -> Type) (g :: k -> Type) (l :: k -> Type). HBifunctor t => (f ~> j) -> (g ~> l) -> t f g ~> t j l
- Data.HBifunctor: hleft :: HBifunctor t => (f ~> j) -> t f g ~> t j g
+ Data.HBifunctor: hleft :: forall (f :: k -> Type) (j :: k -> Type) (g :: k -> Type). HBifunctor t => (f ~> j) -> t f g ~> t j g
- Data.HBifunctor: hright :: HBifunctor t => (g ~> l) -> t f g ~> t f l
+ Data.HBifunctor: hright :: forall (g :: k -> Type) (l :: k -> Type) (f :: k -> Type). HBifunctor t => (g ~> l) -> t f g ~> t f l
- Data.HBifunctor: newtype LeftF f g a
+ Data.HBifunctor: newtype LeftF (f :: k -> Type) (g :: k1) (a :: k)
- Data.HBifunctor: newtype RightF f g a
+ Data.HBifunctor: newtype RightF (f :: k) (g :: k1 -> Type) (a :: k1)
- Data.HBifunctor: newtype WrappedHBifunctor t (f :: k -> Type) (g :: k -> Type) (a :: k)
+ Data.HBifunctor: newtype WrappedHBifunctor (t :: k -> Type -> k -> Type -> k -> Type) (f :: k -> Type) (g :: k -> Type) (a :: k)
- Data.HBifunctor: overHBifunctor :: HBifunctor t => (f <~> f') -> (g <~> g') -> t f g <~> t f' g'
+ Data.HBifunctor: overHBifunctor :: forall {k} (t :: (k -> Type) -> (k -> Type) -> k -> Type) (f :: k -> Type) (f' :: k -> Type) (g :: k -> Type) (g' :: k -> Type). HBifunctor t => (f <~> f') -> (g <~> g') -> t f g <~> t f' g'
- Data.HBifunctor.Associative: (!$!) :: SemigroupIn t (AltConst b) => (forall x. f x -> b) -> (forall x. g x -> b) -> t f g a -> b
+ Data.HBifunctor.Associative: (!$!) :: SemigroupIn t (AltConst b :: Type -> Type) => (forall x. () => f x -> b) -> (forall x. () => g x -> b) -> t f g a -> b
- Data.HBifunctor.Associative: (!*!) :: SemigroupIn t h => (f ~> h) -> (g ~> h) -> t f g ~> h
+ Data.HBifunctor.Associative: (!*!) :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). SemigroupIn t h => (f ~> h) -> (g ~> h) -> t f g ~> h
- Data.HBifunctor.Associative: (!+!) :: (f ~> h) -> (g ~> h) -> (f :+: g) ~> h
+ Data.HBifunctor.Associative: (!+!) :: forall {k} (f :: k -> Type) (h :: k -> Type) (g :: k -> Type). (f ~> h) -> (g ~> h) -> (f :+: g) ~> h
- Data.HBifunctor.Associative: WrapHBF :: t f g a -> WrapHBF t f g a
+ Data.HBifunctor.Associative: WrapHBF :: t f g a -> WrapHBF (t :: k -> k1 -> k2 -> Type) (f :: k) (g :: k1) (a :: k2)
- Data.HBifunctor.Associative: WrapNE :: NonEmptyBy t f a -> WrapNE t f a
+ Data.HBifunctor.Associative: WrapNE :: NonEmptyBy t f a -> WrapNE (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) a
- Data.HBifunctor.Associative: [unwrapHBF] :: WrapHBF t f g a -> t f g a
+ Data.HBifunctor.Associative: [unwrapHBF] :: WrapHBF (t :: k -> k1 -> k2 -> Type) (f :: k) (g :: k1) (a :: k2) -> t f g a
- Data.HBifunctor.Associative: [unwrapNE] :: WrapNE t f a -> NonEmptyBy t f a
+ Data.HBifunctor.Associative: [unwrapNE] :: WrapNE (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) a -> NonEmptyBy t f a
- Data.HBifunctor.Associative: appendNE :: Associative t => t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
+ Data.HBifunctor.Associative: appendNE :: forall (f :: Type -> Type). Associative t => t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
- Data.HBifunctor.Associative: assoc :: (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) => t f (t g h) ~> t (t f g) h
+ Data.HBifunctor.Associative: assoc :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) => t f (t g h) ~> t (t f g) h
- Data.HBifunctor.Associative: associating :: (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) => t f (t g h) <~> t (t f g) h
+ Data.HBifunctor.Associative: associating :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) => t f (t g h) <~> t (t f g) h
- Data.HBifunctor.Associative: biapply :: SemigroupIn t (Op b) => (forall x. f x -> x -> b) -> (forall x. g x -> x -> b) -> t f g a -> a -> b
+ Data.HBifunctor.Associative: biapply :: SemigroupIn t (Op b) => (forall x. () => f x -> x -> b) -> (forall x. () => g x -> x -> b) -> t f g a -> a -> b
- Data.HBifunctor.Associative: biget :: SemigroupIn t (AltConst b) => (forall x. f x -> b) -> (forall x. g x -> b) -> t f g a -> b
+ Data.HBifunctor.Associative: biget :: SemigroupIn t (AltConst b :: Type -> Type) => (forall x. () => f x -> b) -> (forall x. () => g x -> b) -> t f g a -> b
- Data.HBifunctor.Associative: binterpret :: (SemigroupIn t f, Interpret (NonEmptyBy t) f) => (g ~> f) -> (h ~> f) -> t g h ~> f
+ Data.HBifunctor.Associative: binterpret :: forall (g :: Type -> Type) (h :: Type -> Type). SemigroupIn t f => (g ~> f) -> (h ~> f) -> t g h ~> f
- Data.HBifunctor.Associative: biretract :: (SemigroupIn t f, Interpret (NonEmptyBy t) f) => t f f ~> f
+ Data.HBifunctor.Associative: biretract :: SemigroupIn t f => t f f ~> f
- Data.HBifunctor.Associative: class (HBifunctor t, Inject (NonEmptyBy t)) => Associative t where {
+ Data.HBifunctor.Associative: class (HBifunctor t, Inject NonEmptyBy t) => Associative (t :: Type -> Type -> Type -> Type -> Type -> Type) where {
- Data.HBifunctor.Associative: class (Associative t, FunctorBy t f) => SemigroupIn t f
+ Data.HBifunctor.Associative: class (Associative t, FunctorBy t f) => SemigroupIn (t :: Type -> Type -> Type -> Type -> Type -> Type) (f :: Type -> Type)
- Data.HBifunctor.Associative: consNE :: Associative t => t f (NonEmptyBy t f) ~> NonEmptyBy t f
+ Data.HBifunctor.Associative: consNE :: forall (f :: Type -> Type). Associative t => t f (NonEmptyBy t f) ~> NonEmptyBy t f
- Data.HBifunctor.Associative: disassoc :: (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) => t (t f g) h ~> t f (t g h)
+ Data.HBifunctor.Associative: disassoc :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) => t (t f g) h ~> t f (t g h)
- Data.HBifunctor.Associative: interpretNE :: forall t g f. SemigroupIn t f => (g ~> f) -> NonEmptyBy t g ~> f
+ Data.HBifunctor.Associative: interpretNE :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (g :: Type -> Type) (f :: Type -> Type). SemigroupIn t f => (g ~> f) -> NonEmptyBy t g ~> f
- Data.HBifunctor.Associative: matchNE :: (Associative t, FunctorBy t f) => NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
+ Data.HBifunctor.Associative: matchNE :: forall (f :: Type -> Type). (Associative t, FunctorBy t f) => NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
- Data.HBifunctor.Associative: matchingNE :: (Associative t, FunctorBy t f) => NonEmptyBy t f <~> (f :+: t f (NonEmptyBy t f))
+ Data.HBifunctor.Associative: matchingNE :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type). (Associative t, FunctorBy t f) => NonEmptyBy t f <~> (f :+: t f (NonEmptyBy t f))
- Data.HBifunctor.Associative: newtype WrapHBF t f g a
+ Data.HBifunctor.Associative: newtype WrapHBF (t :: k -> k1 -> k2 -> Type) (f :: k) (g :: k1) (a :: k2)
- Data.HBifunctor.Associative: newtype WrapNE t f a
+ Data.HBifunctor.Associative: newtype WrapNE (t :: Type -> Type -> Type -> Type -> Type -> Type) (f :: Type -> Type) a
- Data.HBifunctor.Associative: retractNE :: forall t f. SemigroupIn t f => NonEmptyBy t f ~> f
+ Data.HBifunctor.Associative: retractNE :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type). SemigroupIn t f => NonEmptyBy t f ~> f
- Data.HBifunctor.Associative: toNonEmptyBy :: Associative t => t f f ~> NonEmptyBy t f
+ Data.HBifunctor.Associative: toNonEmptyBy :: forall (f :: Type -> Type). Associative t => t f f ~> NonEmptyBy t f
- Data.HBifunctor.Associative: type FunctorBy t = Unconstrained;
+ Data.HBifunctor.Associative: type FunctorBy t :: Type -> Type -> Type -> Type -> Type -> Type = Unconstrained :: Type -> Type -> Constraint;
- Data.HBifunctor.Associative: type NonEmptyBy t :: (Type -> Type) -> Type -> Type;
+ Data.HBifunctor.Associative: type NonEmptyBy (t :: Type -> Type -> Type -> Type -> Type -> Type) :: Type -> Type -> Type -> Type;
- Data.HBifunctor.Tensor: WrapF :: f a -> WrapF f a
+ Data.HBifunctor.Tensor: WrapF :: f a -> WrapF (f :: k -> Type) (a :: k)
- Data.HBifunctor.Tensor: WrapLB :: ListBy t f a -> WrapLB t f a
+ Data.HBifunctor.Tensor: WrapLB :: ListBy t f a -> WrapLB (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) a
- Data.HBifunctor.Tensor: [unwrapF] :: WrapF f a -> f a
+ Data.HBifunctor.Tensor: [unwrapF] :: WrapF (f :: k -> Type) (a :: k) -> f a
- Data.HBifunctor.Tensor: [unwrapLB] :: WrapLB t f a -> ListBy t f a
+ Data.HBifunctor.Tensor: [unwrapLB] :: WrapLB (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) a -> ListBy t f a
- Data.HBifunctor.Tensor: appendLB :: Tensor t i => t (ListBy t f) (ListBy t f) ~> ListBy t f
+ Data.HBifunctor.Tensor: appendLB :: forall (f :: Type -> Type). Tensor t i => t (ListBy t f) (ListBy t f) ~> ListBy t f
- Data.HBifunctor.Tensor: class Tensor t i => Matchable t i
+ Data.HBifunctor.Tensor: class Tensor t i => Matchable (t :: Type -> Type -> Type -> Type -> Type -> Type) (i :: Type -> Type)
- Data.HBifunctor.Tensor: class (Tensor t i, SemigroupIn t f) => MonoidIn t i f
+ Data.HBifunctor.Tensor: class (Tensor t i, SemigroupIn t f) => MonoidIn (t :: Type -> Type -> Type -> Type -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type)
- Data.HBifunctor.Tensor: class (Associative t, Inject (ListBy t)) => Tensor t i | t -> i where {
+ Data.HBifunctor.Tensor: class (Associative t, Inject ListBy t) => Tensor (t :: Type -> Type -> Type -> Type -> Type -> Type) (i :: Type -> Type) | t -> i where {
- Data.HBifunctor.Tensor: consLB :: Tensor t i => t f (ListBy t f) ~> ListBy t f
+ Data.HBifunctor.Tensor: consLB :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => t f (ListBy t f) ~> ListBy t f
- Data.HBifunctor.Tensor: elim1 :: (Tensor t i, FunctorBy t f) => t f i ~> f
+ Data.HBifunctor.Tensor: elim1 :: forall (f :: Type -> Type). (Tensor t i, FunctorBy t f) => t f i ~> f
- Data.HBifunctor.Tensor: elim2 :: (Tensor t i, FunctorBy t g) => t i g ~> g
+ Data.HBifunctor.Tensor: elim2 :: forall (g :: Type -> Type). (Tensor t i, FunctorBy t g) => t i g ~> g
- Data.HBifunctor.Tensor: fromNE :: Tensor t i => NonEmptyBy t f ~> ListBy t f
+ Data.HBifunctor.Tensor: fromNE :: forall (f :: Type -> Type). Tensor t i => NonEmptyBy t f ~> ListBy t f
- Data.HBifunctor.Tensor: inL :: forall t i f g. MonoidIn t i g => f ~> t f g
+ Data.HBifunctor.Tensor: inL :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). MonoidIn t i g => f ~> t f g
- Data.HBifunctor.Tensor: inR :: forall t i f g. MonoidIn t i f => g ~> t f g
+ Data.HBifunctor.Tensor: inR :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). MonoidIn t i f => g ~> t f g
- Data.HBifunctor.Tensor: interpretLB :: forall t i g f. MonoidIn t i f => (g ~> f) -> ListBy t g ~> f
+ Data.HBifunctor.Tensor: interpretLB :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (g :: Type -> Type) (f :: Type -> Type). MonoidIn t i f => (g ~> f) -> ListBy t g ~> f
- Data.HBifunctor.Tensor: intro1 :: Tensor t i => f ~> t f i
+ Data.HBifunctor.Tensor: intro1 :: forall (f :: Type -> Type). Tensor t i => f ~> t f i
- Data.HBifunctor.Tensor: intro2 :: Tensor t i => g ~> t i g
+ Data.HBifunctor.Tensor: intro2 :: forall (g :: Type -> Type). Tensor t i => g ~> t i g
- Data.HBifunctor.Tensor: leftIdentity :: (Tensor t i, FunctorBy t g) => g <~> t i g
+ Data.HBifunctor.Tensor: leftIdentity :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (g :: Type -> Type). (Tensor t i, FunctorBy t g) => g <~> t i g
- Data.HBifunctor.Tensor: matchLB :: (Matchable t i, FunctorBy t f) => ListBy t f ~> (i :+: NonEmptyBy t f)
+ Data.HBifunctor.Tensor: matchLB :: forall (f :: Type -> Type). (Matchable t i, FunctorBy t f) => ListBy t f ~> (i :+: NonEmptyBy t f)
- Data.HBifunctor.Tensor: matchingLB :: forall t i f. (Matchable t i, FunctorBy t f) => ListBy t f <~> (i :+: NonEmptyBy t f)
+ Data.HBifunctor.Tensor: matchingLB :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). (Matchable t i, FunctorBy t f) => ListBy t f <~> (i :+: NonEmptyBy t f)
- Data.HBifunctor.Tensor: newtype WrapF f a
+ Data.HBifunctor.Tensor: newtype WrapF (f :: k -> Type) (a :: k)
- Data.HBifunctor.Tensor: newtype WrapLB t f a
+ Data.HBifunctor.Tensor: newtype WrapLB (t :: Type -> Type -> Type -> Type -> Type -> Type) (f :: Type -> Type) a
- Data.HBifunctor.Tensor: nilLB :: forall t i f. Tensor t i => i ~> ListBy t f
+ Data.HBifunctor.Tensor: nilLB :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => i ~> ListBy t f
- Data.HBifunctor.Tensor: outL :: (Tensor t Proxy, FunctorBy t f) => t f g ~> f
+ Data.HBifunctor.Tensor: outL :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) (g :: Type -> Type). (Tensor t (Proxy :: Type -> Type), FunctorBy t f) => t f g ~> f
- Data.HBifunctor.Tensor: outR :: (Tensor t Proxy, FunctorBy t g) => t f g ~> g
+ Data.HBifunctor.Tensor: outR :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (g :: Type -> Type) (f :: Type -> Type). (Tensor t (Proxy :: Type -> Type), FunctorBy t g) => t f g ~> g
- Data.HBifunctor.Tensor: prodLeftIdentity :: f <~> (Proxy :*: f)
+ Data.HBifunctor.Tensor: prodLeftIdentity :: forall {k} f p (a :: k). Profunctor p => p (((Proxy :: k -> Type) :*: f) a) (((Proxy :: k -> Type) :*: f) a) -> p (f a) (f a)
- Data.HBifunctor.Tensor: prodOutL :: (f :*: g) ~> f
+ Data.HBifunctor.Tensor: prodOutL :: forall {k} f (g :: k -> Type) (x :: k). (f :*: g) x -> f x
- Data.HBifunctor.Tensor: prodOutR :: (f :*: g) ~> g
+ Data.HBifunctor.Tensor: prodOutR :: forall {k} (f :: k -> Type) g (x :: k). (f :*: g) x -> g x
- Data.HBifunctor.Tensor: prodRightIdentity :: g <~> (g :*: Proxy)
+ Data.HBifunctor.Tensor: prodRightIdentity :: forall {k} g p (a :: k). Profunctor p => p ((g :*: (Proxy :: k -> Type)) a) ((g :*: (Proxy :: k -> Type)) a) -> p (g a) (g a)
- Data.HBifunctor.Tensor: pureT :: (MonoidIn t i f, Interpret (ListBy t) f) => i ~> f
+ Data.HBifunctor.Tensor: pureT :: MonoidIn t i f => i ~> f
- Data.HBifunctor.Tensor: retractLB :: forall t i f. MonoidIn t i f => ListBy t f ~> f
+ Data.HBifunctor.Tensor: retractLB :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). MonoidIn t i f => ListBy t f ~> f
- Data.HBifunctor.Tensor: rightIdentity :: (Tensor t i, FunctorBy t f) => f <~> t f i
+ Data.HBifunctor.Tensor: rightIdentity :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). (Tensor t i, FunctorBy t f) => f <~> t f i
- Data.HBifunctor.Tensor: splitNE :: Tensor t i => NonEmptyBy t f ~> t f (ListBy t f)
+ Data.HBifunctor.Tensor: splitNE :: forall (f :: Type -> Type). Tensor t i => NonEmptyBy t f ~> t f (ListBy t f)
- Data.HBifunctor.Tensor: splittingLB :: Tensor t i => ListBy t f <~> (i :+: t f (ListBy t f))
+ Data.HBifunctor.Tensor: splittingLB :: forall (f :: Type -> Type). Tensor t i => ListBy t f <~> (i :+: t f (ListBy t f))
- Data.HBifunctor.Tensor: splittingNE :: (Matchable t i, FunctorBy t f) => NonEmptyBy t f <~> t f (ListBy t f)
+ Data.HBifunctor.Tensor: splittingNE :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). (Matchable t i, FunctorBy t f) => NonEmptyBy t f <~> t f (ListBy t f)
- Data.HBifunctor.Tensor: sumLeftIdentity :: f <~> (V1 :+: f)
+ Data.HBifunctor.Tensor: sumLeftIdentity :: forall {k} f p (a :: k). Profunctor p => p (((V1 :: k -> Type) :+: f) a) (((V1 :: k -> Type) :+: f) a) -> p (f a) (f a)
- Data.HBifunctor.Tensor: sumRightIdentity :: f <~> (f :+: V1)
+ Data.HBifunctor.Tensor: sumRightIdentity :: forall {k} f p (a :: k). Profunctor p => p ((f :+: (V1 :: k -> Type)) a) ((f :+: (V1 :: k -> Type)) a) -> p (f a) (f a)
- Data.HBifunctor.Tensor: toListBy :: Tensor t i => t f f ~> ListBy t f
+ Data.HBifunctor.Tensor: toListBy :: forall (f :: Type -> Type). Tensor t i => t f f ~> ListBy t f
- Data.HBifunctor.Tensor: type ListBy t :: (Type -> Type) -> Type -> Type;
+ Data.HBifunctor.Tensor: type ListBy (t :: Type -> Type -> Type -> Type -> Type -> Type) :: Type -> Type -> Type -> Type;
- Data.HBifunctor.Tensor: unconsLB :: Tensor t i => ListBy t f ~> (i :+: t f (ListBy t f))
+ Data.HBifunctor.Tensor: unconsLB :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => ListBy t f ~> (i :+: t f (ListBy t f))
- Data.HBifunctor.Tensor: unsplitNE :: (Matchable t i, FunctorBy t f) => t f (ListBy t f) ~> NonEmptyBy t f
+ Data.HBifunctor.Tensor: unsplitNE :: forall (f :: Type -> Type). (Matchable t i, FunctorBy t f) => t f (ListBy t f) ~> NonEmptyBy t f
- Data.HFunctor: ConstF :: e -> ConstF e f a
+ Data.HFunctor: ConstF :: e -> ConstF e (f :: k) (a :: k1)
- Data.HFunctor: HJoin :: t (HFree t f) a -> HFree t f a
+ Data.HFunctor: HJoin :: t (HFree t f) a -> HFree (t :: (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.HFunctor: HOther :: t f a -> HLift t f a
+ Data.HFunctor: HOther :: t f a -> HLift (t :: (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.HFunctor: HPure :: f a -> HLift t f a
+ Data.HFunctor: HPure :: f a -> HLift (t :: (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.HFunctor: HReturn :: f a -> HFree t f a
+ Data.HFunctor: HReturn :: f a -> HFree (t :: (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.HFunctor: ProxyF :: ProxyF f a
+ Data.HFunctor: ProxyF :: ProxyF (f :: k) (a :: k1)
- Data.HFunctor: [getConstF] :: ConstF e f a -> e
+ Data.HFunctor: [getConstF] :: ConstF e (f :: k) (a :: k1) -> e
- Data.HFunctor: class Inject t => HBind t
+ Data.HFunctor: class Inject t => HBind (t :: k -> Type -> k -> Type)
- Data.HFunctor: class HFunctor t
+ Data.HFunctor: class HFunctor (t :: k -> Type -> k1 -> Type)
- Data.HFunctor: class HFunctor t => Inject t
+ Data.HFunctor: class HFunctor t => Inject (t :: k -> Type -> k -> Type)
- Data.HFunctor: data HFree t f a
+ Data.HFunctor: data HFree (t :: k -> Type -> k -> Type) (f :: k -> Type) (a :: k)
- Data.HFunctor: data HLift t f a
+ Data.HFunctor: data HLift (t :: k -> Type -> k -> Type) (f :: k -> Type) (a :: k)
- Data.HFunctor: data ProxyF f a
+ Data.HFunctor: data ProxyF (f :: k) (a :: k1)
- Data.HFunctor: foldHFree :: forall t f g. HFunctor t => (f ~> g) -> (t g ~> g) -> HFree t f ~> g
+ Data.HFunctor: foldHFree :: forall {k} (t :: (k -> Type) -> k -> Type) (f :: k -> Type) (g :: k -> Type). HFunctor t => (f ~> g) -> (t g ~> g) -> HFree t f ~> g
- Data.HFunctor: hbind :: HBind t => (f ~> t g) -> t f ~> t g
+ Data.HFunctor: hbind :: forall (f :: k -> Type) (g :: k -> Type). HBind t => (f ~> t g) -> t f ~> t g
- Data.HFunctor: hjoin :: HBind t => t (t f) ~> t f
+ Data.HFunctor: hjoin :: forall (f :: k -> Type). HBind t => t (t f) ~> t f
- Data.HFunctor: hmap :: HFunctor t => (f ~> g) -> t f ~> t g
+ Data.HFunctor: hmap :: forall (f :: k -> Type) (g :: k -> Type). HFunctor t => (f ~> g) -> t f ~> t g
- Data.HFunctor: inject :: Inject t => f ~> t f
+ Data.HFunctor: inject :: forall (f :: k -> Type). Inject t => f ~> t f
- Data.HFunctor: overHFunctor :: HFunctor t => (f <~> g) -> t f <~> t g
+ Data.HFunctor: overHFunctor :: forall {k1} {k2} (t :: (k1 -> Type) -> k2 -> Type) (f :: k1 -> Type) (g :: k1 -> Type). HFunctor t => (f <~> g) -> t f <~> t g
- Data.HFunctor: retractHFree :: HBind t => HFree t f a -> t f a
+ Data.HFunctor: retractHFree :: forall {k} t (f :: k -> Type) (a :: k). HBind t => HFree t f a -> t f a
- Data.HFunctor: retractHLift :: Inject t => HLift t f a -> t f a
+ Data.HFunctor: retractHLift :: forall {k} t (f :: k -> Type) (a :: k). Inject t => HLift t f a -> t f a
- Data.HFunctor.Chain: Done :: i a -> Chain t i f a
+ Data.HFunctor.Chain: Done :: i a -> Chain (t :: k -> (k1 -> Type) -> k1 -> Type) (i :: k1 -> Type) (f :: k) (a :: k1)
- Data.HFunctor.Chain: Done1 :: f a -> Chain1 t f a
+ Data.HFunctor.Chain: Done1 :: f a -> Chain1 (t :: (k -> Type) -> (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.HFunctor.Chain: More :: t f (Chain t i f) a -> Chain t i f a
+ Data.HFunctor.Chain: More :: t f (Chain t i f) a -> Chain (t :: k -> (k1 -> Type) -> k1 -> Type) (i :: k1 -> Type) (f :: k) (a :: k1)
- Data.HFunctor.Chain: More1 :: t f (Chain1 t f) a -> Chain1 t f a
+ Data.HFunctor.Chain: More1 :: t f (Chain1 t f) a -> Chain1 (t :: (k -> Type) -> (k -> Type) -> k -> Type) (f :: k -> Type) (a :: k)
- Data.HFunctor.Chain: appendChain :: forall t i f. Tensor t i => t (Chain t i f) (Chain t i f) ~> Chain t i f
+ Data.HFunctor.Chain: appendChain :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => t (Chain t i f) (Chain t i f) ~> Chain t i f
- Data.HFunctor.Chain: appendChain1 :: forall t f. (Associative t, FunctorBy t f) => t (Chain1 t f) (Chain1 t f) ~> Chain1 t f
+ Data.HFunctor.Chain: appendChain1 :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type). (Associative t, FunctorBy t f) => t (Chain1 t f) (Chain1 t f) ~> Chain1 t f
- Data.HFunctor.Chain: data Chain t i f a
+ Data.HFunctor.Chain: data Chain (t :: k -> k1 -> Type -> k1 -> Type) (i :: k1 -> Type) (f :: k) (a :: k1)
- Data.HFunctor.Chain: data Chain1 t f a
+ Data.HFunctor.Chain: data Chain1 (t :: k -> Type -> k -> Type -> k -> Type) (f :: k -> Type) (a :: k)
- Data.HFunctor.Chain: foldChain :: forall t i f g. HBifunctor t => (i ~> g) -> (t f g ~> g) -> Chain t i f ~> g
+ Data.HFunctor.Chain: foldChain :: forall {k} (t :: (k -> Type) -> (k -> Type) -> k -> Type) (i :: k -> Type) (f :: k -> Type) (g :: k -> Type). HBifunctor t => (i ~> g) -> (t f g ~> g) -> Chain t i f ~> g
- Data.HFunctor.Chain: foldChain1 :: forall t f g. HBifunctor t => (f ~> g) -> (t f g ~> g) -> Chain1 t f ~> g
+ Data.HFunctor.Chain: foldChain1 :: forall {k} (t :: (k -> Type) -> (k -> Type) -> k -> Type) (f :: k -> Type) (g :: k -> Type). HBifunctor t => (f ~> g) -> (t f g ~> g) -> Chain1 t f ~> g
- Data.HFunctor.Chain: 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)
+ Data.HFunctor.Chain: foldChain1A :: forall {k} t h f g (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)
- Data.HFunctor.Chain: 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)
+ Data.HFunctor.Chain: foldChainA :: forall {k} t h i g (f :: k -> Type) (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)
- Data.HFunctor.Chain: fromChain1 :: Tensor t i => Chain1 t f ~> Chain t i f
+ Data.HFunctor.Chain: fromChain1 :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => Chain1 t f ~> Chain t i f
- Data.HFunctor.Chain: injectChain :: Tensor t i => f ~> Chain t i f
+ Data.HFunctor.Chain: injectChain :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => f ~> Chain t i f
- Data.HFunctor.Chain: injectChain1 :: f ~> Chain1 t f
+ Data.HFunctor.Chain: injectChain1 :: forall {k} f (t :: (k -> Type) -> (k -> Type) -> k -> Type) (x :: k). f x -> Chain1 t f x
- Data.HFunctor.Chain: matchChain1 :: Chain1 t f ~> (f :+: t f (Chain1 t f))
+ Data.HFunctor.Chain: matchChain1 :: forall {k} (t :: (k -> Type) -> (k -> Type) -> k -> Type) (f :: k -> Type) (x :: k). Chain1 t f x -> (f :+: t f (Chain1 t f)) x
- Data.HFunctor.Chain: matchingChain :: forall t i f. (Matchable t i, FunctorBy t f) => Chain t i f <~> (i :+: Chain1 t f)
+ Data.HFunctor.Chain: matchingChain :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). (Matchable t i, FunctorBy t f) => Chain t i f <~> (i :+: Chain1 t f)
- Data.HFunctor.Chain: reroll :: forall t i f. Tensor t i => Chain t i f ~> ListBy t f
+ Data.HFunctor.Chain: reroll :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => Chain t i f ~> ListBy t f
- Data.HFunctor.Chain: rerollNE :: Associative t => Chain1 t f ~> NonEmptyBy t f
+ Data.HFunctor.Chain: rerollNE :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type). Associative t => Chain1 t f ~> NonEmptyBy t f
- Data.HFunctor.Chain: splitChain1 :: forall t i f. Tensor t i => Chain1 t f ~> t f (Chain t i f)
+ Data.HFunctor.Chain: splitChain1 :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => Chain1 t f ~> t f (Chain t i f)
- Data.HFunctor.Chain: splittingChain :: Chain t i f <~> (i :+: t f (Chain t i f))
+ Data.HFunctor.Chain: splittingChain :: forall {k1} {k2} (t :: k1 -> (k2 -> Type) -> k2 -> Type) (i :: k2 -> Type) (f :: k1) p (a :: k2). Profunctor p => p ((i :+: t f (Chain t i f)) a) ((i :+: t f (Chain t i f)) a) -> p (Chain t i f a) (Chain t i f a)
- Data.HFunctor.Chain: splittingChain1 :: forall t i f. (Matchable t i, FunctorBy t f) => Chain1 t f <~> t f (Chain t i f)
+ Data.HFunctor.Chain: splittingChain1 :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). (Matchable t i, FunctorBy t f) => Chain1 t f <~> t f (Chain t i f)
- Data.HFunctor.Chain: toChain :: Tensor t i => t f f ~> Chain t i f
+ Data.HFunctor.Chain: toChain :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => t f f ~> Chain t i f
- Data.HFunctor.Chain: toChain1 :: HBifunctor t => t f f ~> Chain1 t f
+ Data.HFunctor.Chain: toChain1 :: forall {k} (t :: (k -> Type) -> (k -> Type) -> k -> Type) (f :: k -> Type). HBifunctor t => t f f ~> Chain1 t f
- Data.HFunctor.Chain: unconsChain :: Chain t i f ~> (i :+: t f (Chain t i f))
+ Data.HFunctor.Chain: unconsChain :: forall {k1} {k2} (t :: k1 -> (k2 -> Type) -> k2 -> Type) (i :: k2 -> Type) (f :: k1) (x :: k2). Chain t i f x -> (i :+: t f (Chain t i f)) x
- Data.HFunctor.Chain: unfoldChain :: forall t f (g :: Type -> Type) i. HBifunctor t => (g ~> (i :+: t f g)) -> g ~> Chain t i f
+ Data.HFunctor.Chain: unfoldChain :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) (g :: Type -> Type) (i :: Type -> Type). HBifunctor t => (g ~> (i :+: t f g)) -> g ~> Chain t i f
- Data.HFunctor.Chain: unfoldChain1 :: forall t f (g :: Type -> Type). HBifunctor t => (g ~> (f :+: t f g)) -> g ~> Chain1 t f
+ Data.HFunctor.Chain: unfoldChain1 :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type) (g :: Type -> Type). HBifunctor t => (g ~> (f :+: t f g)) -> g ~> Chain1 t f
- Data.HFunctor.Chain: unmatchChain :: forall t i f. Tensor t i => (i :+: Chain1 t f) ~> Chain t i f
+ Data.HFunctor.Chain: unmatchChain :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => (i :+: Chain1 t f) ~> Chain t i f
- Data.HFunctor.Chain: unroll :: Tensor t i => ListBy t f ~> Chain t i f
+ Data.HFunctor.Chain: unroll :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => ListBy t f ~> Chain t i f
- Data.HFunctor.Chain: unrollNE :: (Associative t, FunctorBy t f) => NonEmptyBy t f ~> Chain1 t f
+ Data.HFunctor.Chain: unrollNE :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type). (Associative t, FunctorBy t f) => NonEmptyBy t f ~> Chain1 t f
- Data.HFunctor.Chain: unrolling :: Tensor t i => ListBy t f <~> Chain t i f
+ Data.HFunctor.Chain: unrolling :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (i :: Type -> Type) (f :: Type -> Type). Tensor t i => ListBy t f <~> Chain t i f
- Data.HFunctor.Chain: unrollingNE :: forall t f. (Associative t, FunctorBy t f) => NonEmptyBy t f <~> Chain1 t f
+ Data.HFunctor.Chain: unrollingNE :: forall (t :: (Type -> Type) -> (Type -> Type) -> Type -> Type) (f :: Type -> Type). (Associative t, FunctorBy t f) => NonEmptyBy t f <~> Chain1 t f
- Data.HFunctor.Final: Final :: (forall g. c g => (forall x. f x -> g x) -> g a) -> Final c f a
+ Data.HFunctor.Final: Final :: (forall (g :: k -> Type). c g => (forall (x :: k). () => f x -> g x) -> g a) -> Final (c :: (k -> Type) -> Constraint) (f :: k -> Type) (a :: k)
- Data.HFunctor.Final: [runFinal] :: Final c f a -> forall g. c g => (forall x. f x -> g x) -> g a
+ Data.HFunctor.Final: [runFinal] :: Final (c :: (k -> Type) -> Constraint) (f :: k -> Type) (a :: k) -> forall (g :: k -> Type). c g => (forall (x :: k). () => f x -> g x) -> g a
- Data.HFunctor.Final: class FreeOf c t | t -> c where {
+ Data.HFunctor.Final: class FreeOf (c :: Type -> Type -> Constraint) (t :: Type -> Type -> Type -> Type) | t -> c where {
- Data.HFunctor.Final: finalizing :: (FreeOf c t, FreeFunctorBy t f) => t f <~> Final c f
+ Data.HFunctor.Final: finalizing :: forall (c :: (Type -> Type) -> Constraint) (t :: (Type -> Type) -> Type -> Type) (f :: Type -> Type). (FreeOf c t, FreeFunctorBy t f) => t f <~> Final c f
- Data.HFunctor.Final: fromFinal :: (Inject t, c (t f)) => Final c f ~> t f
+ Data.HFunctor.Final: fromFinal :: forall {k} (t :: (k -> Type) -> k -> Type) (c :: (k -> Type) -> Constraint) (f :: k -> Type). (Inject t, c (t f)) => Final c f ~> t f
- Data.HFunctor.Final: fromFree :: (FreeOf c t, Interpret t (Final c f)) => t f ~> Final c f
+ Data.HFunctor.Final: fromFree :: forall (f :: Type -> Type). FreeOf c t => t f ~> Final c f
- Data.HFunctor.Final: hoistFinalC :: (forall g x. (c g => g x) -> d g => g x) -> Final c f a -> Final d f a
+ Data.HFunctor.Final: hoistFinalC :: forall {k} c d (f :: k -> Type) (a :: k). (forall (g :: k -> Type) (x :: k). () => (c g => g x) -> d g => g x) -> Final c f a -> Final d f a
- Data.HFunctor.Final: liftFinal0 :: (forall g. c g => g a) -> Final c f a
+ Data.HFunctor.Final: liftFinal0 :: forall {k} c (a :: k) (f :: k -> Type). (forall (g :: k -> Type). c g => g a) -> Final c f a
- Data.HFunctor.Final: liftFinal1 :: (forall g. c g => g a -> g b) -> Final c f a -> Final c f b
+ Data.HFunctor.Final: liftFinal1 :: forall {k} c (a :: k) (b :: k) (f :: k -> Type). (forall (g :: k -> Type). c g => g a -> g b) -> Final c f a -> Final c f b
- Data.HFunctor.Final: liftFinal2 :: (forall g. c g => g a -> g b -> g d) -> Final c f a -> Final c f b -> Final c f d
+ Data.HFunctor.Final: liftFinal2 :: forall {k} c (a :: k) (b :: k) (d :: k) (f :: k -> Type). (forall (g :: k -> Type). c g => g a -> g b -> g d) -> Final c f a -> Final c f b -> Final c f d
- Data.HFunctor.Final: newtype Final c f a
+ Data.HFunctor.Final: newtype Final (c :: k -> Type -> Constraint) (f :: k -> Type) (a :: k)
- Data.HFunctor.Final: toFinal :: Interpret t (Final c f) => t f ~> Final c f
+ Data.HFunctor.Final: toFinal :: forall {k} (t :: (k -> Type) -> k -> Type) (c :: (k -> Type) -> Constraint) (f :: k -> Type). Interpret t (Final c f) => t f ~> Final c f
- Data.HFunctor.Final: toFree :: (FreeOf c t, Inject t, c (t f)) => Final c f ~> t f
+ Data.HFunctor.Final: toFree :: forall (f :: Type -> Type). (FreeOf c t, FreeFunctorBy t f) => Final c f ~> t f
- Data.HFunctor.Final: type FreeFunctorBy t = Unconstrained;
+ Data.HFunctor.Final: type FreeFunctorBy t :: Type -> Type -> Type -> Type = Unconstrained :: Type -> Type -> Constraint;
- Data.HFunctor.HTraversable: class HFunctor t => HTraversable t
+ Data.HFunctor.HTraversable: class HFunctor t => HTraversable (t :: k -> Type -> k1 -> Type)
- Data.HFunctor.HTraversable: class HTraversable t => HTraversable1 t
+ Data.HFunctor.HTraversable: class HTraversable t => HTraversable1 (t :: k -> Type -> k1 -> Type)
- Data.HFunctor.HTraversable: hfoldMap :: (HTraversable t, Monoid m) => (forall x. f x -> m) -> t f a -> m
+ Data.HFunctor.HTraversable: hfoldMap :: forall {k} {k1} t m f (a :: k1). (HTraversable t, Monoid m) => (forall (x :: k). () => f x -> m) -> t f a -> m
- Data.HFunctor.HTraversable: hfoldMap1 :: (HTraversable1 t, Semigroup m) => (forall x. f x -> m) -> t f a -> m
+ Data.HFunctor.HTraversable: hfoldMap1 :: forall {k} {k1} t m f (a :: k1). (HTraversable1 t, Semigroup m) => (forall (x :: k). () => f x -> m) -> t f a -> m
- Data.HFunctor.HTraversable: hfor :: (HTraversable t, Applicative h) => t f a -> (forall x. f x -> h (g x)) -> h (t g a)
+ Data.HFunctor.HTraversable: hfor :: forall {k} {k1} t h f (a :: k1) g. (HTraversable t, Applicative h) => t f a -> (forall (x :: k). () => f x -> h (g x)) -> h (t g a)
- Data.HFunctor.HTraversable: hfor1 :: (HTraversable1 t, Apply h) => t f a -> (forall x. f x -> h (g x)) -> h (t g a)
+ Data.HFunctor.HTraversable: hfor1 :: forall {k} {k1} t h f (a :: k1) g. (HTraversable1 t, Apply h) => t f a -> (forall (x :: k). () => f x -> h (g x)) -> h (t g a)
- Data.HFunctor.HTraversable: hmapDefault :: HTraversable t => (f ~> g) -> t f ~> t g
+ Data.HFunctor.HTraversable: hmapDefault :: forall {k1} {k2} (t :: (k1 -> Type) -> k2 -> Type) (f :: k1 -> Type) (g :: k1 -> Type). HTraversable t => (f ~> g) -> t f ~> t g
- Data.HFunctor.HTraversable: hsequence :: (HTraversable t, Applicative h) => t (h :.: f) a -> h (t f a)
+ Data.HFunctor.HTraversable: hsequence :: forall {k} {k1} t h (f :: k -> Type) (a :: k1). (HTraversable t, Applicative h) => t (h :.: f) a -> h (t f a)
- Data.HFunctor.HTraversable: hsequence1 :: (HTraversable1 t, Apply h) => t (h :.: f) a -> h (t f a)
+ Data.HFunctor.HTraversable: hsequence1 :: forall {k} {k1} t h (f :: k -> Type) (a :: k1). (HTraversable1 t, Apply h) => t (h :.: f) a -> h (t f a)
- Data.HFunctor.HTraversable: htoList :: HTraversable t => (forall x. f x -> b) -> t f a -> [b]
+ Data.HFunctor.HTraversable: htoList :: forall {k} {k1} t f b (a :: k1). HTraversable t => (forall (x :: k). () => f x -> b) -> t f a -> [b]
- Data.HFunctor.HTraversable: htoNonEmpty :: HTraversable1 t => (forall x. f x -> b) -> t f a -> NonEmpty b
+ Data.HFunctor.HTraversable: htoNonEmpty :: forall {k} {k1} t f b (a :: k1). HTraversable1 t => (forall (x :: k). () => f x -> b) -> t f a -> NonEmpty b
- Data.HFunctor.HTraversable: htraverse :: (HTraversable t, Applicative h) => (forall x. f x -> h (g x)) -> t f a -> h (t g a)
+ Data.HFunctor.HTraversable: htraverse :: forall h f g (a :: k1). (HTraversable t, Applicative h) => (forall (x :: k). () => f x -> h (g x)) -> t f a -> h (t g a)
- Data.HFunctor.HTraversable: htraverse1 :: (HTraversable1 t, Apply h) => (forall x. f x -> h (g x)) -> t f a -> h (t g a)
+ Data.HFunctor.HTraversable: htraverse1 :: forall h f g (a :: k1). (HTraversable1 t, Apply h) => (forall (x :: k). () => f x -> h (g x)) -> t f a -> h (t g a)
- Data.HFunctor.Interpret: AltConst :: w -> AltConst w a
+ Data.HFunctor.Interpret: AltConst :: w -> AltConst w (a :: k)
- Data.HFunctor.Interpret: WrapHF :: t f a -> WrapHF t f a
+ Data.HFunctor.Interpret: WrapHF :: t f a -> WrapHF (t :: k -> k1 -> Type) (f :: k) (a :: k1)
- Data.HFunctor.Interpret: [getAltConst] :: AltConst w a -> w
+ Data.HFunctor.Interpret: [getAltConst] :: AltConst w (a :: k) -> w
- Data.HFunctor.Interpret: [unwrapHF] :: WrapHF t f a -> t f a
+ Data.HFunctor.Interpret: [unwrapHF] :: WrapHF (t :: k -> k1 -> Type) (f :: k) (a :: k1) -> t f a
- Data.HFunctor.Interpret: class (c a, d a) => AndC c d a
+ Data.HFunctor.Interpret: class (c a, d a) => AndC (c :: k -> Constraint) (d :: k -> Constraint) (a :: k)
- Data.HFunctor.Interpret: class Inject t => Interpret t f
+ Data.HFunctor.Interpret: class Inject t => Interpret (t :: k -> Type -> k -> Type) (f :: k -> Type)
- Data.HFunctor.Interpret: collectI :: (forall m. Monoid m => Interpret t (AltConst m)) => (forall x. f x -> b) -> t f a -> [b]
+ Data.HFunctor.Interpret: collectI :: forall {k} t f b (a :: k). (forall m. Monoid m => Interpret t (AltConst m :: k -> Type)) => (forall (x :: k). () => f x -> b) -> t f a -> [b]
- Data.HFunctor.Interpret: forI :: Interpret t f => t g a -> (g ~> f) -> f a
+ Data.HFunctor.Interpret: forI :: forall {k} t f (g :: k -> Type) (a :: k). Interpret t f => t g a -> (g ~> f) -> f a
- Data.HFunctor.Interpret: getI :: Interpret t (AltConst b) => (forall x. f x -> b) -> t f a -> b
+ Data.HFunctor.Interpret: getI :: forall {k} t b f (a :: k). Interpret t (AltConst b :: k -> Type) => (forall (x :: k). () => f x -> b) -> t f a -> b
- Data.HFunctor.Interpret: iapply :: Interpret t (Op b) => (forall x. f x -> x -> b) -> t f a -> a -> b
+ Data.HFunctor.Interpret: iapply :: Interpret t (Op b) => (forall x. () => f x -> x -> b) -> t f a -> a -> b
- Data.HFunctor.Interpret: icollect :: (forall m. Monoid m => Interpret t (AltConst m)) => (forall x. f x -> b) -> t f a -> [b]
+ Data.HFunctor.Interpret: icollect :: forall {k} t f b (a :: k). (forall m. Monoid m => Interpret t (AltConst m :: k -> Type)) => (forall (x :: k). () => f x -> b) -> t f a -> [b]
- Data.HFunctor.Interpret: icollect1 :: (forall m. Semigroup m => Interpret t (AltConst m)) => (forall x. f x -> b) -> t f a -> NonEmpty b
+ Data.HFunctor.Interpret: icollect1 :: forall {k} t f b (a :: k). (forall m. Semigroup m => Interpret t (AltConst m :: k -> Type)) => (forall (x :: k). () => f x -> b) -> t f a -> NonEmpty b
- Data.HFunctor.Interpret: ifanout :: (forall m. Monoid m => Interpret t (Op m)) => (forall x. f x -> x -> b) -> t f a -> a -> [b]
+ Data.HFunctor.Interpret: ifanout :: (forall m. Monoid m => Interpret t (Op m)) => (forall x. () => f x -> x -> b) -> t f a -> a -> [b]
- Data.HFunctor.Interpret: ifanout1 :: (forall m. Semigroup m => Interpret t (Op m)) => (forall x. f x -> x -> b) -> t f a -> a -> NonEmpty b
+ Data.HFunctor.Interpret: ifanout1 :: (forall m. Semigroup m => Interpret t (Op m)) => (forall x. () => f x -> x -> b) -> t f a -> a -> NonEmpty b
- Data.HFunctor.Interpret: iget :: Interpret t (AltConst b) => (forall x. f x -> b) -> t f a -> b
+ Data.HFunctor.Interpret: iget :: forall {k} t b f (a :: k). Interpret t (AltConst b :: k -> Type) => (forall (x :: k). () => f x -> b) -> t f a -> b
- Data.HFunctor.Interpret: interpret :: Interpret t f => (g ~> f) -> t g ~> f
+ Data.HFunctor.Interpret: interpret :: forall (g :: k -> Type). Interpret t f => (g ~> f) -> t g ~> f
- Data.HFunctor.Interpret: itraverse :: (Functor h, Interpret t (Comp h (t g))) => (forall x. f x -> h (g x)) -> t f a -> h (t g a)
+ Data.HFunctor.Interpret: itraverse :: forall {k} h t g f (a :: k). (Functor h, Interpret t (Comp h (t g))) => (forall (x :: k). () => f x -> h (g x)) -> t f a -> h (t g a)
- Data.HFunctor.Interpret: newtype AltConst w a
+ Data.HFunctor.Interpret: newtype AltConst w (a :: k)
- Data.HFunctor.Interpret: newtype WrapHF t f a
+ Data.HFunctor.Interpret: newtype WrapHF (t :: k -> k1 -> Type) (f :: k) (a :: k1)
- Data.HFunctor.Route: (:<$>:) :: (b -> a) -> f b -> Post a f b
+ Data.HFunctor.Route: (:<$>:) :: (b -> a) -> f b -> Post a (f :: Type -> Type) b
- Data.HFunctor.Route: (:>$<:) :: (a -> b) -> f b -> Pre a f b
+ Data.HFunctor.Route: (:>$<:) :: (a -> b) -> f b -> Pre a (f :: Type -> Type) b
- Data.HFunctor.Route: PostT :: t (Post a f) a -> PostT t f a
+ Data.HFunctor.Route: PostT :: t (Post a f) a -> PostT (t :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) a
- Data.HFunctor.Route: PreT :: t (Pre a f) a -> PreT t f a
+ Data.HFunctor.Route: PreT :: t (Pre a f) a -> PreT (t :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) a
- Data.HFunctor.Route: [unPostT] :: PostT t f a -> t (Post a f) a
+ Data.HFunctor.Route: [unPostT] :: PostT (t :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) a -> t (Post a f) a
- Data.HFunctor.Route: [unPreT] :: PreT t f a -> t (Pre a f) a
+ Data.HFunctor.Route: [unPreT] :: PreT (t :: (Type -> Type) -> Type -> Type) (f :: Type -> Type) a -> t (Pre a f) a
- Data.HFunctor.Route: data Post a f b
+ Data.HFunctor.Route: data Post a (f :: Type -> Type) b
- Data.HFunctor.Route: data Pre a f b
+ Data.HFunctor.Route: data Pre a (f :: Type -> Type) b
- Data.HFunctor.Route: interpretPost :: Functor g => (f ~> g) -> Post a f b -> g a
+ Data.HFunctor.Route: interpretPost :: forall g (f :: Type -> Type) a b. Functor g => (f ~> g) -> Post a f b -> g a
- Data.HFunctor.Route: interpretPre :: Contravariant g => (f ~> g) -> Pre a f b -> g a
+ Data.HFunctor.Route: interpretPre :: forall g (f :: Type -> Type) a b. Contravariant g => (f ~> g) -> Pre a f b -> g a
- Data.HFunctor.Route: mapPost :: (a -> c) -> Post a f b -> Post c f b
+ Data.HFunctor.Route: mapPost :: forall a c (f :: Type -> Type) b. (a -> c) -> Post a f b -> Post c f b
- Data.HFunctor.Route: mapPre :: (c -> a) -> Pre a f b -> Pre c f b
+ Data.HFunctor.Route: mapPre :: forall c a (f :: Type -> Type) b. (c -> a) -> Pre a f b -> Pre c f b
- Data.HFunctor.Route: newtype PostT t f a
+ Data.HFunctor.Route: newtype PostT (t :: Type -> Type -> Type -> Type) (f :: Type -> Type) a
- Data.HFunctor.Route: newtype PreT t f a
+ Data.HFunctor.Route: newtype PreT (t :: Type -> Type -> Type -> Type) (f :: Type -> Type) a
- Data.HFunctor.Route: postAlt :: (forall m. Semigroup m => Interpret t (AltConst m), Alt g) => (f ~> g) -> t (Post a f) b -> g a
+ Data.HFunctor.Route: postAlt :: forall t g (f :: Type -> Type) a b. (forall m. Semigroup m => Interpret t (AltConst m :: Type -> Type), Alt g) => (f ~> g) -> t (Post a f) b -> g a
- Data.HFunctor.Route: postAltT :: (forall m. Semigroup m => Interpret t (AltConst m), Alt g) => (f ~> g) -> PostT t f ~> g
+ Data.HFunctor.Route: postAltT :: forall (t :: (Type -> Type) -> Type -> Type) (g :: Type -> Type) (f :: Type -> Type). (forall m. Semigroup m => Interpret t (AltConst m :: Type -> Type), Alt g) => (f ~> g) -> PostT t f ~> g
- Data.HFunctor.Route: postFunctor :: (forall m. Interpret t (AltConst m), Functor g) => (f ~> g) -> t (Post a f) b -> g a
+ Data.HFunctor.Route: postFunctor :: forall t g (f :: Type -> Type) a b. (forall m. () => Interpret t (AltConst m :: Type -> Type), Functor g) => (f ~> g) -> t (Post a f) b -> g a
- Data.HFunctor.Route: postFunctorT :: (forall m. Interpret t (AltConst m), Functor g) => (f ~> g) -> PostT t f ~> g
+ Data.HFunctor.Route: postFunctorT :: forall (t :: (Type -> Type) -> Type -> Type) (g :: Type -> Type) (f :: Type -> Type). (forall m. () => Interpret t (AltConst m :: Type -> Type), Functor g) => (f ~> g) -> PostT t f ~> g
- Data.HFunctor.Route: postPlus :: (forall m. Monoid m => Interpret t (AltConst m), Plus g) => (f ~> g) -> t (Post a f) b -> g a
+ Data.HFunctor.Route: postPlus :: forall t g (f :: Type -> Type) a b. (forall m. Monoid m => Interpret t (AltConst m :: Type -> Type), Plus g) => (f ~> g) -> t (Post a f) b -> g a
- Data.HFunctor.Route: postPlusT :: (forall m. Monoid m => Interpret t (AltConst m), Plus g) => (f ~> g) -> PostT t f ~> g
+ Data.HFunctor.Route: postPlusT :: forall (t :: (Type -> Type) -> Type -> Type) (g :: Type -> Type) (f :: Type -> Type). (forall m. Monoid m => Interpret t (AltConst m :: Type -> Type), Plus g) => (f ~> g) -> PostT t f ~> g
- Data.HFunctor.Route: preContravariant :: (forall m. Interpret t (AltConst m), Contravariant g) => (f ~> g) -> t (Pre a f) b -> g a
+ Data.HFunctor.Route: preContravariant :: forall t g (f :: Type -> Type) a b. (forall m. () => Interpret t (AltConst m :: Type -> Type), Contravariant g) => (f ~> g) -> t (Pre a f) b -> g a
- Data.HFunctor.Route: preContravariantT :: (forall m. Interpret t (AltConst m), Contravariant g) => (f ~> g) -> PreT t f ~> g
+ Data.HFunctor.Route: preContravariantT :: forall (t :: (Type -> Type) -> Type -> Type) (g :: Type -> Type) (f :: Type -> Type). (forall m. () => Interpret t (AltConst m :: Type -> Type), Contravariant g) => (f ~> g) -> PreT t f ~> g
- Data.HFunctor.Route: preDivise :: (forall m. Semigroup m => Interpret t (AltConst m), Divise g) => (f ~> g) -> t (Pre a f) b -> g a
+ Data.HFunctor.Route: preDivise :: forall t g (f :: Type -> Type) a b. (forall m. Semigroup m => Interpret t (AltConst m :: Type -> Type), Divise g) => (f ~> g) -> t (Pre a f) b -> g a
- Data.HFunctor.Route: preDiviseT :: (forall m. Semigroup m => Interpret t (AltConst m), Divise g) => (f ~> g) -> PreT t f ~> g
+ Data.HFunctor.Route: preDiviseT :: forall (t :: (Type -> Type) -> Type -> Type) (g :: Type -> Type) (f :: Type -> Type). (forall m. Semigroup m => Interpret t (AltConst m :: Type -> Type), Divise g) => (f ~> g) -> PreT t f ~> g
- Data.HFunctor.Route: preDivisible :: (forall m. Monoid m => Interpret t (AltConst m), Divisible g) => (f ~> g) -> t (Pre a f) b -> g a
+ Data.HFunctor.Route: preDivisible :: forall t g (f :: Type -> Type) a b. (forall m. Monoid m => Interpret t (AltConst m :: Type -> Type), Divisible g) => (f ~> g) -> t (Pre a f) b -> g a
- Data.HFunctor.Route: preDivisibleT :: (forall m. Monoid m => Interpret t (AltConst m), Divisible g) => (f ~> g) -> PreT t f ~> g
+ Data.HFunctor.Route: preDivisibleT :: forall (t :: (Type -> Type) -> Type -> Type) (g :: Type -> Type) (f :: Type -> Type). (forall m. Monoid m => Interpret t (AltConst m :: Type -> Type), Divisible g) => (f ~> g) -> PreT t f ~> g
Files
- CHANGELOG.md +9/−0
- functor-combinators.cabal +176/−89
- src/Control/Applicative/ListF.hs +144/−126
- src/Control/Applicative/Step.hs +123/−116
- src/Control/Monad/Freer/Church.hs +233/−185
- src/Control/Natural/IsoF.hs +28/−23
- src/Data/Functor/Apply/Free.hs +56/−54
- src/Data/Functor/Combinator.hs +156/−119
- src/Data/Functor/Combinator/Unsafe.hs +43/−42
- src/Data/Functor/Contravariant/Conclude.hs +9/−10
- src/Data/Functor/Contravariant/Decide.hs +61/−37
- src/Data/Functor/Contravariant/Divise.hs +62/−52
- src/Data/Functor/Contravariant/Divisible/Free.hs +114/−97
- src/Data/Functor/Contravariant/Night.hs +50/−43
- src/Data/Functor/Invariant/Inplicative.hs +419/−265
- src/Data/Functor/Invariant/Inplicative/Free.hs +131/−114
- src/Data/Functor/Invariant/Internative.hs +211/−134
- src/Data/Functor/Invariant/Internative/Free.hs +107/−94
- src/Data/Functor/Invariant/Night.hs +79/−69
- src/Data/HBifunctor.hs +41/−39
- src/Data/HBifunctor/Associative.hs +471/−449
- src/Data/HBifunctor/Tensor.hs +391/−378
- src/Data/HBifunctor/Tensor/Internal.hs +131/−129
- src/Data/HFunctor.hs +269/−246
- src/Data/HFunctor/Chain.hs +153/−141
- src/Data/HFunctor/Chain/Internal.hs +212/−181
- src/Data/HFunctor/Final.hs +251/−198
- src/Data/HFunctor/HTraversable.hs +189/−178
- src/Data/HFunctor/Internal.hs +196/−193
- src/Data/HFunctor/Interpret.hs +218/−214
- src/Data/HFunctor/Route.hs +188/−143
- test/Spec.hs +10/−8
- test/Tests/HBifunctor.hs +528/−430
- test/Tests/HFunctor.hs +232/−213
- test/Tests/Util.hs +199/−177
CHANGELOG.md view
@@ -1,6 +1,15 @@ Changelog ========= +Version 0.4.1.4+---------------++*June 12, 2025*++<https://github.com/mstksg/functor-combinators/releases/tag/v0.4.1.4>++* Optimize `(.>)` for `Final` (#10) (@rhendric)+ Version 0.4.1.3 ---------------
functor-combinators.cabal view
@@ -1,4 +1,4 @@-cabal-version: 1.12+cabal-version: 1.24 -- This file has been generated from package.yaml by hpack version 0.33.0. --@@ -6,85 +6,128 @@ -- -- hash: c98f05061d45352f630dd964c7671a2a414e5708a12f8f4f8a39d61b986f6f5d -name: functor-combinators-version: 0.4.1.3-synopsis: Tools for functor combinator-based program design-description: Tools for working with /functor combinators/: types that take functors (or- other indexed types) and returns a new functor that "enhances" or "mixes"- them in some way. In the process, you can design featureful programs by- composing smaller "primitives" using basic unversal combinators.- .- The main entry point is "Data.Functor.Combinators", but more fine-grained- functionality and extra combinators (some of them re-implementations for- compatibility) are available in other modules as well.- .- This library does not define new functor combinators for the most part,- but rather re-exports them from different parts of the Haskell ecosystem- and provides a uniform interface.- .- See the README for a quick overview, and also- <https://blog.jle.im/entry/functor-combinatorpedia.html> for an in-depth- dive into the motivation behind functor combinator-driven development,- examples of the functor combinators in this library, and details about how- to use these abstractions!-category: Data-homepage: https://github.com/mstksg/functor-combinators#readme-bug-reports: https://github.com/mstksg/functor-combinators/issues-author: Justin Le-maintainer: justin@jle.im-copyright: (c) Justin Le 2019-license: BSD3-license-file: LICENSE-tested-with: GHC >= 8.6-build-type: Simple+name: functor-combinators+version: 0.4.1.4+synopsis: Tools for functor combinator-based program design+description:+ Tools for working with /functor combinators/: types that take functors (or+ other indexed types) and returns a new functor that "enhances" or "mixes"+ them in some way. In the process, you can design featureful programs by+ composing smaller "primitives" using basic unversal combinators.+ .+ The main entry point is "Data.Functor.Combinators", but more fine-grained+ functionality and extra combinators (some of them re-implementations for+ compatibility) are available in other modules as well.+ .+ This library does not define new functor combinators for the most part,+ but rather re-exports them from different parts of the Haskell ecosystem+ and provides a uniform interface.+ .+ See the README for a quick overview, and also+ <https://blog.jle.im/entry/functor-combinatorpedia.html> for an in-depth+ dive into the motivation behind functor combinator-driven development,+ examples of the functor combinators in this library, and details about how+ to use these abstractions!++category: Data+homepage: https://github.com/mstksg/functor-combinators#readme+bug-reports: https://github.com/mstksg/functor-combinators/issues+author: Justin Le+maintainer: justin@jle.im+copyright: (c) Justin Le 2025+license: BSD3+license-file: LICENSE+tested-with: GHC >=8.6+build-type: Simple extra-source-files:- README.md- CHANGELOG.md+ CHANGELOG.md+ README.md source-repository head- type: git+ type: git location: https://github.com/mstksg/functor-combinators library exposed-modules:- Control.Applicative.ListF- Control.Applicative.Step- Control.Monad.Freer.Church- Control.Natural.IsoF- Data.Functor.Apply.Free- Data.Functor.Combinator- Data.Functor.Combinator.Unsafe- Data.Functor.Contravariant.Conclude- Data.Functor.Contravariant.Decide- Data.Functor.Contravariant.Divise- Data.Functor.Contravariant.Divisible.Free- Data.Functor.Contravariant.Night- Data.Functor.Invariant.Inplicative- Data.Functor.Invariant.Inplicative.Free- Data.Functor.Invariant.Internative- Data.Functor.Invariant.Internative.Free- Data.Functor.Invariant.Night- Data.HBifunctor- Data.HBifunctor.Associative- Data.HBifunctor.Tensor- Data.HFunctor- Data.HFunctor.Chain- Data.HFunctor.Final- Data.HFunctor.HTraversable- Data.HFunctor.Interpret- Data.HFunctor.Route+ Control.Applicative.ListF+ Control.Applicative.Step+ Control.Monad.Freer.Church+ Control.Natural.IsoF+ Data.Functor.Apply.Free+ Data.Functor.Combinator+ Data.Functor.Combinator.Unsafe+ Data.Functor.Contravariant.Conclude+ Data.Functor.Contravariant.Decide+ Data.Functor.Contravariant.Divise+ Data.Functor.Contravariant.Divisible.Free+ Data.Functor.Contravariant.Night+ Data.Functor.Invariant.Inplicative+ Data.Functor.Invariant.Inplicative.Free+ Data.Functor.Invariant.Internative+ Data.Functor.Invariant.Internative.Free+ Data.Functor.Invariant.Night+ Data.HBifunctor+ Data.HBifunctor.Associative+ Data.HBifunctor.Tensor+ Data.HFunctor+ Data.HFunctor.Chain+ Data.HFunctor.Final+ Data.HFunctor.HTraversable+ Data.HFunctor.Interpret+ Data.HFunctor.Route+ other-modules:- Data.HFunctor.Internal- Data.HFunctor.Chain.Internal- Data.HBifunctor.Tensor.Internal- hs-source-dirs:- src- default-extensions: AllowAmbiguousTypes ConstraintKinds DataKinds DefaultSignatures DeriveDataTypeable DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable DerivingStrategies EmptyCase ExistentialQuantification ExplicitNamespaces FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving InstanceSigs KindSignatures LambdaCase MultiParamTypeClasses OverloadedStrings PatternSynonyms QuantifiedConstraints RankNTypes ScopedTypeVariables StandaloneDeriving TemplateHaskell TupleSections TypeApplications TypeFamilies PolyKinds TypeOperators UndecidableInstances UndecidableSuperClasses ViewPatterns- ghc-options: -Wall -Wcompat -Wredundant-constraints -Werror=incomplete-patterns+ Data.HBifunctor.Tensor.Internal+ Data.HFunctor.Chain.Internal+ Data.HFunctor.Internal++ hs-source-dirs: src+ default-extensions:+ AllowAmbiguousTypes+ ConstraintKinds+ DataKinds+ DefaultSignatures+ DeriveDataTypeable+ DeriveFoldable+ DeriveFunctor+ DeriveGeneric+ DeriveTraversable+ DerivingStrategies+ EmptyCase+ ExistentialQuantification+ ExplicitNamespaces+ FlexibleContexts+ FlexibleInstances+ FunctionalDependencies+ GADTs+ GeneralizedNewtypeDeriving+ InstanceSigs+ KindSignatures+ LambdaCase+ MultiParamTypeClasses+ OverloadedStrings+ PatternSynonyms+ PolyKinds+ QuantifiedConstraints+ RankNTypes+ ScopedTypeVariables+ StandaloneDeriving+ TemplateHaskell+ TupleSections+ TypeApplications+ TypeFamilies+ TypeOperators+ UndecidableInstances+ UndecidableSuperClasses+ ViewPatterns++ ghc-options:+ -Wall -Wcompat -Wredundant-constraints -Werror=incomplete-patterns+ -Wunused-packages+ build-depends:- StateVar- , assoc- , base >=4.12 && <5+ assoc+ , base >=4.12 && <5 , bifunctors , comonad , constraints@@ -98,42 +141,86 @@ , mmorph , mtl , natural-transformation- , nonempty-containers >=0.3.4.4+ , nonempty-containers >=0.3.4.4 , pointed , profunctors , semigroupoids , sop-core+ , StateVar , tagged , these , transformers- , trivial-constraint >=0.5+ , trivial-constraint >=0.5 , unordered-containers , vinyl- default-language: Haskell2010 + default-language: Haskell2010+ test-suite functor-combinators-test- type: exitcode-stdio-1.0- main-is: Spec.hs+ type: exitcode-stdio-1.0+ main-is: Spec.hs other-modules:- Tests.HBifunctor- Tests.HFunctor- Tests.Util- Paths_functor_combinators- hs-source-dirs:- test- default-extensions: AllowAmbiguousTypes ConstraintKinds DataKinds DefaultSignatures DeriveDataTypeable DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable DerivingStrategies EmptyCase ExistentialQuantification ExplicitNamespaces FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving InstanceSigs KindSignatures LambdaCase MultiParamTypeClasses OverloadedStrings PatternSynonyms QuantifiedConstraints RankNTypes ScopedTypeVariables StandaloneDeriving TemplateHaskell TupleSections TypeApplications TypeFamilies PolyKinds TypeOperators UndecidableInstances UndecidableSuperClasses ViewPatterns- ghc-options: -Wall -Wcompat -Wredundant-constraints -Werror=incomplete-patterns -threaded -rtsopts -with-rtsopts=-N+ Paths_functor_combinators+ Tests.HBifunctor+ Tests.HFunctor+ Tests.Util++ hs-source-dirs: test+ default-extensions:+ AllowAmbiguousTypes+ ConstraintKinds+ DataKinds+ DefaultSignatures+ DeriveDataTypeable+ DeriveFoldable+ DeriveFunctor+ DeriveGeneric+ DeriveTraversable+ DerivingStrategies+ EmptyCase+ ExistentialQuantification+ ExplicitNamespaces+ FlexibleContexts+ FlexibleInstances+ FunctionalDependencies+ GADTs+ GeneralizedNewtypeDeriving+ InstanceSigs+ KindSignatures+ LambdaCase+ MultiParamTypeClasses+ OverloadedStrings+ PatternSynonyms+ PolyKinds+ QuantifiedConstraints+ RankNTypes+ ScopedTypeVariables+ StandaloneDeriving+ TemplateHaskell+ TupleSections+ TypeApplications+ TypeFamilies+ TypeOperators+ UndecidableInstances+ UndecidableSuperClasses+ ViewPatterns++ ghc-options:+ -Wall -Wcompat -Wredundant-constraints -Werror=incomplete-patterns+ -threaded -rtsopts -with-rtsopts=-N -Wunused-packages+ build-depends:- base >=4.12 && <5+ base >=4.12 && <5 , bifunctors , dependent-sum , free , functor-combinators- , hedgehog >=0.6- , nonempty-containers >=0.3.4.4+ , hedgehog >=0.6+ , nonempty-containers >=0.3.4.4 , semigroupoids , tasty , tasty-hedgehog , transformers- , trivial-constraint >=0.5- default-language: Haskell2010+ , trivial-constraint >=0.5++ default-language: Haskell2010
src/Control/Applicative/ListF.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Control.Applicative.ListF--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -16,41 +16,49 @@ -- f :*: f :*: f@, etc. module Control.Applicative.ListF ( -- * 'ListF'- ListF(..), mapListF+ ListF (..),+ mapListF,+ -- * 'NonEmptyF'- , NonEmptyF(.., ProdNonEmpty, nonEmptyProd), mapNonEmptyF- , toListF, fromListF+ NonEmptyF (.., ProdNonEmpty, nonEmptyProd),+ mapNonEmptyF,+ toListF,+ fromListF,+ -- * 'MaybeF'- , MaybeF(..), mapMaybeF- , listToMaybeF, maybeToListF+ MaybeF (..),+ mapMaybeF,+ listToMaybeF,+ maybeToListF,+ -- * 'MapF'- , MapF(..)- , NEMapF(..)- ) where+ MapF (..),+ NEMapF (..),+) where -import Control.Applicative-import Control.Natural-import Data.Coerce-import Data.Data-import Data.Deriving-import Data.Foldable-import Data.Functor.Bind-import Data.Functor.Classes-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Invariant-import Data.Functor.Plus-import Data.List.NonEmpty (NonEmpty(..))-import Data.Maybe-import Data.Pointed-import Data.Semigroup.Foldable-import Data.Semigroup.Traversable-import GHC.Generics-import qualified Data.Map as M-import qualified Data.Map.NonEmpty as NEM+import Control.Applicative+import Control.Natural+import Data.Coerce+import Data.Data+import Data.Deriving+import Data.Foldable+import Data.Functor.Bind+import Data.Functor.Classes+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Invariant+import Data.Functor.Plus+import Data.List.NonEmpty (NonEmpty (..))+import qualified Data.Map as M+import qualified Data.Map.NonEmpty as NEM+import Data.Maybe+import Data.Pointed+import Data.Semigroup.Foldable+import Data.Semigroup.Traversable+import GHC.Generics -- | A list of @f a@s. Can be used to describe a product of many different -- values of type @f a@.@@ -59,7 +67,7 @@ -- -- Incidentally, if used with a 'Contravariant' @f@, this is instead the -- free 'Divisible'.-newtype ListF f a = ListF { runListF :: [f a] }+newtype ListF f a = ListF {runListF :: [f a]} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''ListF@@ -68,69 +76,72 @@ deriveOrd1 ''ListF instance Apply f => Apply (ListF f) where- ListF fs <.> ListF xs = ListF $ liftF2 (<.>) fs xs+ ListF fs <.> ListF xs = ListF $ liftF2 (<.>) fs xs instance Applicative f => Applicative (ListF f) where- pure = ListF . (:[]) . pure- ListF fs <*> ListF xs = ListF $ liftA2 (<*>) fs xs+ pure = ListF . (: []) . pure+ ListF fs <*> ListF xs = ListF $ liftA2 (<*>) fs xs instance Functor f => Alt (ListF f) where- (<!>) = (<>)+ (<!>) = (<>) instance Functor f => Plus (ListF f) where- zero = mempty+ zero = mempty instance Applicative f => Alternative (ListF f) where- empty = zero- (<|>) = (<!>)+ empty = zero+ (<|>) = (<!>) instance Semigroup (ListF f a) where- ListF xs <> ListF ys = ListF (xs ++ ys)+ ListF xs <> ListF ys = ListF (xs ++ ys) instance Monoid (ListF f a) where- mempty = ListF []+ mempty = ListF [] instance Pointed f => Pointed (ListF f) where- point = ListF . (: []) . point+ point = ListF . (: []) . point -- | @since 0.3.0.0 instance Contravariant f => Contravariant (ListF f) where- contramap f (ListF xs) = ListF ((map . contramap) f xs)+ contramap f (ListF xs) = ListF ((map . contramap) f xs) -- | @since 0.3.0.0 instance Invariant f => Invariant (ListF f) where- invmap f g (ListF xs) = ListF (map (invmap f g) xs)+ invmap f g (ListF xs) = ListF (map (invmap f g) xs) -- | @since 0.3.0.0 instance Contravariant f => Divise (ListF f) where- divise f (ListF xs) (ListF ys) = ListF $- (map . contramap) (fst . f) xs- <> (map . contramap) (snd . f) ys+ divise f (ListF xs) (ListF ys) =+ ListF $+ (map . contramap) (fst . f) xs+ <> (map . contramap) (snd . f) ys -- | @since 0.3.0.0 instance Contravariant f => Divisible (ListF f) where- divide = divise- conquer = ListF []+ divide = divise+ conquer = ListF [] -- | @since 0.3.0.0 instance Decide f => Decide (ListF f) where- decide f (ListF xs) (ListF ys) = ListF $- liftA2 (decide f) xs ys+ decide f (ListF xs) (ListF ys) =+ ListF $+ liftA2 (decide f) xs ys -- | @since 0.3.0.0 instance Conclude f => Conclude (ListF f) where- conclude f = ListF [conclude f]+ conclude f = ListF [conclude f] -- | @since 0.3.0.0 instance Decidable f => Decidable (ListF f) where- lose f = ListF [lose f]- choose f (ListF xs) (ListF ys) = ListF $- liftA2 (choose f) xs ys+ lose f = ListF [lose f]+ choose f (ListF xs) (ListF ys) =+ ListF $+ liftA2 (choose f) xs ys -- | Map a function over the inside of a 'ListF'.-mapListF- :: ([f a] -> [g b])- -> ListF f a- -> ListF g b+mapListF ::+ ([f a] -> [g b]) ->+ ListF f a ->+ ListF g b mapListF = coerce -- | A non-empty list of @f a@s. Can be used to describe a product between@@ -151,7 +162,7 @@ -- -- Incidentally, if used with a 'Contravariant' @f@, this is instead the -- free 'Divise'.-newtype NonEmptyF f a = NonEmptyF { runNonEmptyF :: NonEmpty (f a) }+newtype NonEmptyF f a = NonEmptyF {runNonEmptyF :: NonEmpty (f a)} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''NonEmptyF@@ -160,39 +171,44 @@ deriveOrd1 ''NonEmptyF instance Applicative f => Applicative (NonEmptyF f) where- pure = NonEmptyF . (:| []) . pure- NonEmptyF fs <*> NonEmptyF xs = NonEmptyF $ liftA2 (<*>) fs xs+ pure = NonEmptyF . (:| []) . pure+ NonEmptyF fs <*> NonEmptyF xs = NonEmptyF $ liftA2 (<*>) fs xs instance Functor f => Alt (NonEmptyF f) where- (<!>) = (<>)+ (<!>) = (<>) -- | @since 0.3.0.0 instance Contravariant f => Contravariant (NonEmptyF f) where- contramap f (NonEmptyF xs) = NonEmptyF (fmap (contramap f) xs)+ contramap f (NonEmptyF xs) = NonEmptyF (fmap (contramap f) xs)+ -- | @since 0.3.0.0 instance Invariant f => Invariant (NonEmptyF f) where- invmap f g (NonEmptyF xs) = NonEmptyF (fmap (invmap f g) xs)+ invmap f g (NonEmptyF xs) = NonEmptyF (fmap (invmap f g) xs)+ -- | @since 0.3.0.0 instance Contravariant f => Divise (NonEmptyF f) where- divise f (NonEmptyF xs) (NonEmptyF ys) = NonEmptyF $- (fmap . contramap) (fst . f) xs- <> (fmap . contramap) (snd . f) ys+ divise f (NonEmptyF xs) (NonEmptyF ys) =+ NonEmptyF $+ (fmap . contramap) (fst . f) xs+ <> (fmap . contramap) (snd . f) ys+ -- | @since 0.3.0.0 instance Decide f => Decide (NonEmptyF f) where- decide f (NonEmptyF xs) (NonEmptyF ys) = NonEmptyF $+ decide f (NonEmptyF xs) (NonEmptyF ys) =+ NonEmptyF $ decide f <$> xs <*> ys instance Semigroup (NonEmptyF f a) where- NonEmptyF xs <> NonEmptyF ys = NonEmptyF (xs <> ys)+ NonEmptyF xs <> NonEmptyF ys = NonEmptyF (xs <> ys) instance Pointed f => Pointed (NonEmptyF f) where- point = NonEmptyF . (:| []) . point+ point = NonEmptyF . (:| []) . point -- | Map a function over the inside of a 'NonEmptyF'.-mapNonEmptyF- :: (NonEmpty (f a) -> NonEmpty (g b))- -> NonEmptyF f a- -> NonEmptyF g b+mapNonEmptyF ::+ (NonEmpty (f a) -> NonEmpty (g b)) ->+ NonEmptyF f a ->+ NonEmptyF g b mapNonEmptyF = coerce -- | Convert a 'NonEmptyF' into a 'ListF' with at least one item.@@ -203,18 +219,18 @@ -- the list was empty. fromListF :: ListF f ~> (Proxy :+: NonEmptyF f) fromListF (ListF xs) = case xs of- [] -> L1 Proxy- y:ys -> R1 $ NonEmptyF (y :| ys)+ [] -> L1 Proxy+ y : ys -> R1 $ NonEmptyF (y :| ys) -- | Treat a @'NonEmptyF' f@ as a product between an @f@ and a @'ListF' f@. -- -- 'nonEmptyProd' is the record accessor. pattern ProdNonEmpty :: (f :*: ListF f) a -> NonEmptyF f a-pattern ProdNonEmpty { nonEmptyProd- }- <- ((\case NonEmptyF (x :| xs) -> x :*: ListF xs) -> nonEmptyProd)+pattern ProdNonEmpty{nonEmptyProd} <-+ (\case NonEmptyF (x :| xs) -> x :*: ListF xs -> nonEmptyProd) where ProdNonEmpty (x :*: ListF xs) = NonEmptyF (x :| xs)+ {-# COMPLETE ProdNonEmpty #-} -- | A maybe @f a@.@@ -223,7 +239,7 @@ -- -- This is the free structure for a "fail"-like typeclass that would only -- have @zero :: f a@.-newtype MaybeF f a = MaybeF { runMaybeF :: Maybe (f a) }+newtype MaybeF f a = MaybeF {runMaybeF :: Maybe (f a)} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''MaybeF@@ -232,68 +248,71 @@ deriveOrd1 ''MaybeF instance Applicative f => Applicative (MaybeF f) where- pure = MaybeF . Just . pure- MaybeF f <*> MaybeF x = MaybeF $ liftA2 (<*>) f x+ pure = MaybeF . Just . pure+ MaybeF f <*> MaybeF x = MaybeF $ liftA2 (<*>) f x instance Functor f => Alt (MaybeF f) where- (<!>) = (<>)+ (<!>) = (<>) instance Functor f => Plus (MaybeF f) where- zero = mempty+ zero = mempty instance Applicative f => Alternative (MaybeF f) where- empty = zero- (<|>) = (<!>)+ empty = zero+ (<|>) = (<!>) -- | @since 0.3.3.0 instance Contravariant f => Contravariant (MaybeF f) where- contramap f (MaybeF x) = MaybeF $ (fmap . contramap) f x+ contramap f (MaybeF x) = MaybeF $ (fmap . contramap) f x -- | @since 0.3.3.0 instance Invariant f => Invariant (MaybeF f) where- invmap f g (MaybeF x) = MaybeF $ fmap (invmap f g) x+ invmap f g (MaybeF x) = MaybeF $ fmap (invmap f g) x -- | @since 0.3.3.0 instance Contravariant f => Divise (MaybeF f) where- divise f (MaybeF x) (MaybeF y) = MaybeF $- (fmap . contramap) (fst . f) x- <|> (fmap . contramap) (snd . f) y+ divise f (MaybeF x) (MaybeF y) =+ MaybeF $+ (fmap . contramap) (fst . f) x+ <|> (fmap . contramap) (snd . f) y -- | @since 0.3.3.0 instance Contravariant f => Divisible (MaybeF f) where- divide = divise- conquer = MaybeF Nothing+ divide = divise+ conquer = MaybeF Nothing -- | @since 0.3.3.0 instance Decide f => Decide (MaybeF f) where- decide f (MaybeF x) (MaybeF y) = MaybeF $- liftA2 (decide f) x y+ decide f (MaybeF x) (MaybeF y) =+ MaybeF $+ liftA2 (decide f) x y -- | @since 0.3.3.0 instance Conclude f => Conclude (MaybeF f) where- conclude f = MaybeF (Just (conclude f))+ conclude f = MaybeF (Just (conclude f)) -- | @since 0.3.3.0 instance Decidable f => Decidable (MaybeF f) where- choose f (MaybeF x) (MaybeF y) = MaybeF $- liftA2 (choose f) x y- lose f = MaybeF (Just (lose f))+ choose f (MaybeF x) (MaybeF y) =+ MaybeF $+ liftA2 (choose f) x y+ lose f = MaybeF (Just (lose f)) -- | Picks the first 'Just'. instance Semigroup (MaybeF f a) where- MaybeF xs <> MaybeF ys = MaybeF (xs <!> ys)+ MaybeF xs <> MaybeF ys = MaybeF (xs <!> ys) instance Monoid (MaybeF f a) where- mempty = MaybeF Nothing+ mempty = MaybeF Nothing instance Pointed f => Pointed (MaybeF f) where- point = MaybeF . Just . point+ point = MaybeF . Just . point -- | Map a function over the inside of a 'MaybeF'.-mapMaybeF- :: (Maybe (f a) -> Maybe (g b))- -> MaybeF f a- -> MaybeF g b+mapMaybeF ::+ (Maybe (f a) -> Maybe (g b)) ->+ MaybeF f a ->+ MaybeF g b mapMaybeF = coerce -- | Convert a 'MaybeF' into a 'ListF' with zero or one items.@@ -333,7 +352,7 @@ -- -- See 'NEMapF' for a non-empty variant, if you want to enforce that your -- bag has at least one @f a@.-newtype MapF k f a = MapF { runMapF :: M.Map k (f a) }+newtype MapF k f a = MapF {runMapF :: M.Map k (f a)} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''MapF@@ -341,24 +360,24 @@ deriveOrd1 ''MapF instance (Ord k, Read k, Read1 f) => Read1 (MapF k f) where- liftReadsPrec = $(makeLiftReadsPrec ''MapF)+ liftReadsPrec = $(makeLiftReadsPrec ''MapF) -- | A union, combining matching keys with '<!>'. instance (Ord k, Alt f) => Semigroup (MapF k f a) where- MapF xs <> MapF ys = MapF $ M.unionWith (<!>) xs ys+ MapF xs <> MapF ys = MapF $ M.unionWith (<!>) xs ys instance (Ord k, Alt f) => Monoid (MapF k f a) where- mempty = MapF M.empty+ mempty = MapF M.empty -- | Left-biased union instance (Functor f, Ord k) => Alt (MapF k f) where- MapF xs <!> MapF ys = MapF $ M.union xs ys+ MapF xs <!> MapF ys = MapF $ M.union xs ys instance (Functor f, Ord k) => Plus (MapF k f) where- zero = MapF M.empty+ zero = MapF M.empty instance (Monoid k, Pointed f) => Pointed (MapF k f) where- point = MapF . M.singleton mempty . point+ point = MapF . M.singleton mempty . point -- | A non-empty map of @f a@s, indexed by keys of type @k@. It can be -- useful for represeting a product of many different values of type @f a@,@@ -371,7 +390,7 @@ -- keys. -- -- See 'MapF' for some use cases.-newtype NEMapF k f a = NEMapF { runNEMapF :: NEM.NEMap k (f a) }+newtype NEMapF k f a = NEMapF {runNEMapF :: NEM.NEMap k (f a)} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''NEMapF@@ -379,25 +398,24 @@ deriveOrd1 ''NEMapF instance (Ord k, Read k, Read1 f) => Read1 (NEMapF k f) where- liftReadsPrec = $(makeLiftReadsPrec ''NEMapF)+ liftReadsPrec = $(makeLiftReadsPrec ''NEMapF) instance Foldable1 f => Foldable1 (NEMapF k f) where- fold1 = foldMap1 fold1 . runNEMapF- foldMap1 f = (foldMap1 . foldMap1) f . runNEMapF- toNonEmpty = foldMap1 toNonEmpty . runNEMapF+ fold1 = foldMap1 fold1 . runNEMapF+ foldMap1 f = (foldMap1 . foldMap1) f . runNEMapF+ toNonEmpty = foldMap1 toNonEmpty . runNEMapF instance Traversable1 f => Traversable1 (NEMapF k f) where- traverse1 f = fmap NEMapF . (traverse1 . traverse1) f . runNEMapF- sequence1 = fmap NEMapF . traverse1 sequence1 . runNEMapF+ traverse1 f = fmap NEMapF . (traverse1 . traverse1) f . runNEMapF+ sequence1 = fmap NEMapF . traverse1 sequence1 . runNEMapF -- | A union, combining matching keys with '<!>'. instance (Ord k, Alt f) => Semigroup (NEMapF k f a) where- NEMapF xs <> NEMapF ys = NEMapF $ NEM.unionWith (<!>) xs ys+ NEMapF xs <> NEMapF ys = NEMapF $ NEM.unionWith (<!>) xs ys -- | Left-biased union instance (Functor f, Ord k) => Alt (NEMapF k f) where- NEMapF xs <!> NEMapF ys = NEMapF $ NEM.union xs ys+ NEMapF xs <!> NEMapF ys = NEMapF $ NEM.union xs ys instance (Monoid k, Pointed f) => Pointed (NEMapF k f) where- point = NEMapF . NEM.singleton mempty . point-+ point = NEMapF . NEM.singleton mempty . point
src/Control/Applicative/Step.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Control.Applicative.Step--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -16,47 +16,49 @@ -- ':+:' and 'Data.Functor.These.These1'. module Control.Applicative.Step ( -- * Fixed Points- Step(..)- , Steps(..)- , Flagged(..)+ Step (..),+ Steps (..),+ Flagged (..),+ -- ** Steppers- , stepUp- , stepDown- , stepping- , stepsUp- , stepsDown- , steppings+ stepUp,+ stepDown,+ stepping,+ stepsUp,+ stepsDown,+ steppings,+ -- * Void- , absurd1- , Void2- , absurd2- , Void3- , absurd3- ) where+ absurd1,+ Void2,+ absurd2,+ Void3,+ absurd3,+) where -import Control.Natural-import Control.Natural.IsoF-import Data.Bifunctor-import Data.Data-import Data.Deriving-import Data.Functor.Alt-import Data.Functor.Bind-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Invariant-import Data.Functor.These-import Data.Map.NonEmpty (NEMap)-import Data.Pointed-import Data.Semigroup-import Data.Semigroup.Foldable-import Data.Semigroup.Traversable-import Data.These-import GHC.Generics-import GHC.Natural-import qualified Data.Map.NonEmpty as NEM+import Control.Natural+import Control.Natural.IsoF+import Data.Bifunctor+import Data.Data+import Data.Deriving+import Data.Functor.Alt+import Data.Functor.Bind+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Invariant+import Data.Functor.These+import Data.Map.NonEmpty (NEMap)+import qualified Data.Map.NonEmpty as NEM+import Data.Pointed+import Data.Semigroup+import Data.Semigroup.Foldable+import Data.Semigroup.Traversable+import Data.These+import GHC.Generics+import GHC.Natural -- | An @f a@, along with a 'Natural' index. --@@ -79,7 +81,7 @@ -- -- Note that this type and its instances equivalent to -- @'Control.Comonad.Trans.Env.EnvT' ('Data.Semigroup.Sum' 'Natural')@.-data Step f a = Step { stepPos :: Natural, stepVal :: f a }+data Step f a = Step {stepPos :: Natural, stepVal :: f a} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''Step@@ -89,50 +91,53 @@ -- | @since 0.3.0.0 instance Apply f => Apply (Step f) where- Step n f <.> Step m x = Step (n + m) (f <.> x)+ Step n f <.> Step m x = Step (n + m) (f <.> x) instance Applicative f => Applicative (Step f) where- pure = Step 0 . pure- Step n f <*> Step m x = Step (n + m) (f <*> x)+ pure = Step 0 . pure+ Step n f <*> Step m x = Step (n + m) (f <*> x) -- | @since 0.3.0.0 instance Contravariant f => Contravariant (Step f) where- contramap f (Step x y) = Step x (contramap f y)+ contramap f (Step x y) = Step x (contramap f y) -- | @since 0.3.0.0 instance Divisible f => Divisible (Step f) where- divide f (Step n x) (Step m y) = Step (n + m) (divide f x y)- conquer = Step 0 conquer+ divide f (Step n x) (Step m y) = Step (n + m) (divide f x y)+ conquer = Step 0 conquer+ -- | @since 0.3.0.0 instance Divise f => Divise (Step f) where- divise f (Step n x) (Step m y) = Step (n + m) (divise f x y)+ divise f (Step n x) (Step m y) = Step (n + m) (divise f x y) -- | @since 0.3.0.0 instance Decide f => Decide (Step f) where- decide f (Step n x) (Step m y) = Step (n + m) (decide f x y)+ decide f (Step n x) (Step m y) = Step (n + m) (decide f x y)+ -- | @since 0.3.0.0 instance Conclude f => Conclude (Step f) where- conclude = Step 0 . conclude+ conclude = Step 0 . conclude+ -- | @since 0.3.0.0 instance Decidable f => Decidable (Step f) where- choose f (Step n x) (Step m y) = Step (n + m) (choose f x y)- lose = Step 0 . lose+ choose f (Step n x) (Step m y) = Step (n + m) (choose f x y)+ lose = Step 0 . lose -- | @since 0.3.0.0 instance Invariant f => Invariant (Step f) where- invmap f g (Step x y) = Step x (invmap f g y)+ invmap f g (Step x y) = Step x (invmap f g y) instance Pointed f => Pointed (Step f) where- point = Step 0 . point+ point = Step 0 . point instance Foldable1 f => Foldable1 (Step f) where- fold1 = fold1 . stepVal- foldMap1 f = foldMap1 f . stepVal- toNonEmpty = toNonEmpty . stepVal+ fold1 = fold1 . stepVal+ foldMap1 f = foldMap1 f . stepVal+ toNonEmpty = toNonEmpty . stepVal instance Traversable1 f => Traversable1 (Step f) where- traverse1 f (Step n x) = Step n <$> traverse1 f x- sequence1 (Step n x) = Step n <$> sequence1 x+ traverse1 f (Step n x) = Step n <$> traverse1 f x+ sequence1 (Step n x) = Step n <$> sequence1 x -- | "Uncons and cons" an @f@ branch before a 'Step'. This is basically -- a witness that 'stepDown' and 'stepUp' form an isomorphism.@@ -164,8 +169,8 @@ -- Forms an isomorphism with 'stepUp' (see 'stepping'). stepDown :: Step f ~> f :+: Step f stepDown (Step n x) = case minusNaturalMaybe n 1 of- Nothing -> L1 x- Just m -> R1 (Step m x)+ Nothing -> L1 x+ Just m -> R1 (Step m x) -- | Unshift an item into a 'Step'. Because a @'Step' f@ is @f :+: f :+: -- f :+: f :+: ...@ forever, this basically conses an additional@@ -193,8 +198,8 @@ -- Forms an isomorphism with 'stepDown' (see 'stepping'). stepUp :: f :+: Step f ~> Step f stepUp = \case- L1 x -> Step 0 x- R1 (Step n y) -> Step (n + 1) y+ L1 x -> Step 0 x+ R1 (Step n y) -> Step (n + 1) y -- | We have a natural transformation between 'V1' and any other -- functor @f@ with no constraints.@@ -230,7 +235,7 @@ -- -- This type is essentailly the same as @'Control.Applicative.ListF.NEMapF' -- ('Sum' 'Natural')@ (except with a different 'Semigroup' instance).-newtype Steps f a = Steps { getSteps :: NEMap Natural (f a) }+newtype Steps f a = Steps {getSteps :: NEMap Natural (f a)} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''Steps@@ -239,39 +244,39 @@ deriveOrd1 ''Steps instance Foldable1 f => Foldable1 (Steps f) where- fold1 = foldMap1 fold1 . getSteps- foldMap1 f = (foldMap1 . foldMap1) f . getSteps- toNonEmpty = foldMap1 toNonEmpty . getSteps+ fold1 = foldMap1 fold1 . getSteps+ foldMap1 f = (foldMap1 . foldMap1) f . getSteps+ toNonEmpty = foldMap1 toNonEmpty . getSteps instance Traversable1 f => Traversable1 (Steps f) where- traverse1 f = fmap Steps . (traverse1 . traverse1) f . getSteps- sequence1 = fmap Steps . traverse1 sequence1 . getSteps+ traverse1 f = fmap Steps . (traverse1 . traverse1) f . getSteps+ sequence1 = fmap Steps . traverse1 sequence1 . getSteps -- | Appends the items back-to-back, shifting all of the items in the -- second map. Matches the behavior as the fixed-point of 'These1'. instance Semigroup (Steps f a) where- Steps xs <> Steps ys = Steps $+ Steps xs <> Steps ys =+ Steps $ let (k, _) = NEM.findMax xs- in xs <> NEM.mapKeysMonotonic (+ (k + 1)) ys+ in xs <> NEM.mapKeysMonotonic (+ (k + 1)) ys -- | @since 0.3.0.0 instance Contravariant f => Contravariant (Steps f) where- contramap f (Steps xs) = Steps ((fmap . contramap) f xs)+ contramap f (Steps xs) = Steps ((fmap . contramap) f xs) -- TODO: consider what Divisible/Decidable should be. Maybe no need to -- rush into this. -- | @since 0.3.0.0 instance Invariant f => Invariant (Steps f) where- invmap f g (Steps xs) = Steps (fmap (invmap f g) xs)-+ invmap f g (Steps xs) = Steps (fmap (invmap f g) xs) -- | Left-biased untion instance Functor f => Alt (Steps f) where- Steps xs <!> Steps ys = Steps $ NEM.union xs ys+ Steps xs <!> Steps ys = Steps $ NEM.union xs ys instance Pointed f => Pointed (Steps f) where- point = Steps . NEM.singleton 0 . point+ point = Steps . NEM.singleton 0 . point -- | "Uncons and cons" an @f@ branch before a 'Steps'. This is basically -- a witness that 'stepsDown' and 'stepsUp' form an isomorphism.@@ -303,15 +308,16 @@ -- -- Forms an isomorphism with 'stepsUp' (see 'steppings'). stepsDown :: Steps f ~> These1 f (Steps f)-stepsDown = these This1 That1 These1- . bimap getFirst Steps- . NEM.foldMapWithKey decr- . getSteps+stepsDown =+ these This1 That1 These1+ . bimap getFirst Steps+ . NEM.foldMapWithKey decr+ . getSteps decr :: Natural -> f a -> These (First (f a)) (NEMap Natural (f a)) decr i x = case minusNaturalMaybe i 1 of- Nothing -> This $ First x- Just i' -> That $ NEM.singleton i' x+ Nothing -> This $ First x+ Just i' -> That $ NEM.singleton i' x -- | Unshift an item into a 'Steps'. Because a @'Steps' f@ is @f `These1` -- f `These1` f `These1` f `These1` ...@ forever, this basically conses an@@ -341,16 +347,19 @@ -- Forms an isomorphism with 'stepDown' (see 'stepping'). stepsUp :: These1 f (Steps f) ~> Steps f stepsUp = \case- This1 x -> Steps $ NEM.singleton 0 x- That1 xs -> Steps . NEM.mapKeysMonotonic (+ 1)- . getSteps- $ xs- These1 x xs -> Steps . NEM.insertMapMin 0 x- . NEM.toMap- . NEM.mapKeysMonotonic (+ 1)- . getSteps- $ xs-+ This1 x -> Steps $ NEM.singleton 0 x+ That1 xs ->+ Steps+ . NEM.mapKeysMonotonic (+ 1)+ . getSteps+ $ xs+ These1 x xs ->+ Steps+ . NEM.insertMapMin 0 x+ . NEM.toMap+ . NEM.mapKeysMonotonic (+ 1)+ . getSteps+ $ xs -- | An @f a@, along with a 'Bool' flag --@@ -377,7 +386,7 @@ -- -- * @'Data.HFunctor.HLift' 'Control.Monad.Trans.Identity.IdentityT'@ -- * @'Control.COmonad.Trans.Env.EnvT' 'Data.Semigroup.Any'@-data Flagged f a = Flagged { flaggedFlag :: Bool, flaggedVal :: f a }+data Flagged f a = Flagged {flaggedFlag :: Bool, flaggedVal :: f a} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''Flagged@@ -387,25 +396,21 @@ -- | Uses 'False' for 'pure', and '||' for '<*>'. instance Applicative f => Applicative (Flagged f) where- pure = Flagged False . pure- Flagged n f <*> Flagged m x = Flagged (n || m) (f <*> x)+ pure = Flagged False . pure+ Flagged n f <*> Flagged m x = Flagged (n || m) (f <*> x) -- | Uses 'False' for 'point'. instance Pointed f => Pointed (Flagged f) where- point = Flagged False . point+ point = Flagged False . point instance Foldable1 f => Foldable1 (Flagged f) where- fold1 = fold1 . flaggedVal- foldMap1 f = foldMap1 f . flaggedVal- toNonEmpty = toNonEmpty . flaggedVal+ fold1 = fold1 . flaggedVal+ foldMap1 f = foldMap1 f . flaggedVal+ toNonEmpty = toNonEmpty . flaggedVal instance Traversable1 f => Traversable1 (Flagged f) where- traverse1 f (Flagged n x) = Flagged n <$> traverse1 f x- sequence1 (Flagged n x) = Flagged n <$> sequence1 x----+ traverse1 f (Flagged n x) = Flagged n <$> traverse1 f x+ sequence1 (Flagged n x) = Flagged n <$> sequence1 x -- | @'Void2' a b@ is uninhabited for all @a@ and @b@. data Void2 a b@@ -417,23 +422,24 @@ deriveOrd1 ''Void2 instance Semigroup (Void2 a b) where- x <> _ = case x of {}+ x <> _ = case x of {} instance Alt (Void2 a) where- x <!> _ = absurd2 x+ x <!> _ = absurd2 x instance Bind (Void2 a) where- x >>- _ = case x of {}+ x >>- _ = case x of {} instance Apply (Void2 a) where- x <.> _ = case x of {}+ x <.> _ = case x of {} -- | @since 0.3.0.0 instance Contravariant (Void2 a) where- contramap _ = \case {}+ contramap _ = \case {}+ -- | @since 0.3.0.0 instance Invariant (Void2 a) where- invmap _ _ = \case {}+ invmap _ _ = \case {} -- | If you treat a @'Void2' f a@ as a functor combinator, then 'absurd2' -- lets you convert from a @'Void2' f a@ into a @t f a@ for any functor@@ -451,23 +457,24 @@ deriveOrd1 ''Void3 instance Semigroup (Void3 a b c) where- x <> _ = case x of {}+ x <> _ = case x of {} instance Alt (Void3 a b) where- x <!> _ = absurd3 x+ x <!> _ = absurd3 x instance Bind (Void3 a b) where- x >>- _ = case x of {}+ x >>- _ = case x of {} instance Apply (Void3 a b) where- x <.> _ = case x of {}+ x <.> _ = case x of {} -- | @since 0.3.0.0 instance Contravariant (Void3 a b) where- contramap _ = \case {}+ contramap _ = \case {}+ -- | @since 0.3.0.0 instance Invariant (Void3 a b) where- invmap _ _ = \case {}+ invmap _ _ = \case {} -- | If you treat a @'Void3' f a@ as a binary functor combinator, then -- 'absurd3' lets you convert from a @'Void3' f a@ into a @t f a@ for any
src/Control/Monad/Freer/Church.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Control.Monad.Freer.Church--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -17,40 +17,61 @@ -- 'Data.Functor.Tensor.HBifunctor' and the related typeclasses. module Control.Monad.Freer.Church ( -- * 'Free'- Free(..), reFree+ Free (..),+ reFree,+ -- ** Interpretation- , liftFree, interpretFree, retractFree, hoistFree+ liftFree,+ interpretFree,+ retractFree,+ hoistFree,+ -- ** Folding- , foldFree, foldFree', foldFreeC+ foldFree,+ foldFree',+ foldFreeC,+ -- * 'Free1'- , Free1(.., DoneF1, MoreF1)- , reFree1, toFree+ Free1 (.., DoneF1, MoreF1),+ reFree1,+ toFree,+ -- ** Interpretation- , liftFree1, interpretFree1, retractFree1, hoistFree1+ liftFree1,+ interpretFree1,+ retractFree1,+ hoistFree1,+ -- ** Conversion- , free1Comp, matchFree1+ free1Comp,+ matchFree1,+ -- ** Folding- , foldFree1, foldFree1', foldFree1C+ foldFree1,+ foldFree1',+ foldFree1C,+ -- * 'Comp'- , Comp(.., Comp, unComp), comp- ) where+ Comp (.., Comp, unComp),+ comp,+) where -import Control.Applicative-import Control.Monad-import Control.Natural-import Data.Foldable-import Data.Functor-import Data.Functor.Bind-import Data.Functor.Classes-import Data.Functor.Coyoneda-import Data.Functor.Invariant-import Data.Functor.Plus-import Data.Pointed-import Data.Semigroup.Foldable-import Data.Semigroup.Traversable-import GHC.Generics-import Text.Read-import qualified Control.Monad.Free as M+import Control.Applicative+import Control.Monad+import qualified Control.Monad.Free as M+import Control.Natural+import Data.Foldable+import Data.Functor+import Data.Functor.Bind+import Data.Functor.Classes+import Data.Functor.Coyoneda+import Data.Functor.Invariant+import Data.Functor.Plus+import Data.Pointed+import Data.Semigroup.Foldable+import Data.Semigroup.Traversable+import GHC.Generics+import Text.Read -- | A @'Free' f@ is @f@ enhanced with "sequential binding" capabilities. -- It allows you to sequence multiple @f@s one after the other, and also to@@ -86,84 +107,87 @@ -- a way that is compatible with 'Data.Functor.HFunctor.HFunctor' and -- 'Data.Functor.HFunctor.Interpret'. newtype Free f a = Free- { runFree :: forall r. (a -> r) -> (forall s. f s -> (s -> r) -> r) -> r- }+ { runFree :: forall r. (a -> r) -> (forall s. f s -> (s -> r) -> r) -> r+ } instance Functor (Free f) where- fmap f x = Free $ \p b -> runFree x (p . f) b+ fmap f x = Free $ \p b -> runFree x (p . f) b -- | @since 0.4.1.2 instance Invariant (Free f) where- invmap f _ = fmap f+ invmap f _ = fmap f instance Apply (Free f) where- (<.>) = ap+ (<.>) = ap instance Applicative (Free f) where- pure x = Free $ \p _ -> p x- (<*>) = (<.>)+ pure x = Free $ \p _ -> p x+ (<*>) = (<.>) instance Pointed (Free f) where- point = pure+ point = pure instance Bind (Free f) where- x >>- f = Free $ \p b -> runFree x (\y -> runFree (f y) p b) b+ x >>- f = Free $ \p b -> runFree x (\y -> runFree (f y) p b) b instance Monad (Free f) where- (>>=) = (>>-)+ (>>=) = (>>-) instance M.MonadFree f (Free f) where- wrap x = Free $ \p b -> b x $ \y -> runFree y p b+ wrap x = Free $ \p b -> b x $ \y -> runFree y p b instance Foldable f => Foldable (Free f) where- foldMap f = foldFreeC f fold+ foldMap f = foldFreeC f fold instance Traversable f => Traversable (Free f) where- traverse f = foldFree (fmap pure . f )- (fmap M.wrap . sequenceA)+ traverse f =+ foldFree+ (fmap pure . f)+ (fmap M.wrap . sequenceA) instance (Functor f, Eq1 f) => Eq1 (Free f) where- liftEq eq x y = liftEq @(M.Free f) eq (reFree x) (reFree y)+ liftEq eq x y = liftEq @(M.Free f) eq (reFree x) (reFree y) instance (Functor f, Ord1 f) => Ord1 (Free f) where- liftCompare c x y = liftCompare @(M.Free f) c (reFree x) (reFree y)+ liftCompare c x y = liftCompare @(M.Free f) c (reFree x) (reFree y) instance (Functor f, Eq1 f, Eq a) => Eq (Free f a) where- (==) = eq1+ (==) = eq1 instance (Functor f, Ord1 f, Ord a) => Ord (Free f a) where- compare = compare1+ compare = compare1 instance (Functor f, Show1 f) => Show1 (Free f) where- liftShowsPrec sp sl d x = case reFree x of- M.Pure y -> showsUnaryWith sp "pure" d y- M.Free ys -> showsUnaryWith (liftShowsPrec sp' sl') "wrap" d ys- where- sp' = liftShowsPrec sp sl- sl' = liftShowList sp sl+ liftShowsPrec sp sl d x = case reFree x of+ M.Pure y -> showsUnaryWith sp "pure" d y+ M.Free ys -> showsUnaryWith (liftShowsPrec sp' sl') "wrap" d ys+ where+ sp' = liftShowsPrec sp sl+ sl' = liftShowList sp sl -- | Show in terms of 'pure' and 'M.wrap'. instance (Functor f, Show1 f, Show a) => Show (Free f a) where- showsPrec = liftShowsPrec showsPrec showList+ showsPrec = liftShowsPrec showsPrec showList instance (Functor f, Read1 f) => Read1 (Free f) where- liftReadsPrec rp rl = go- where- go = readsData $- readsUnaryWith rp "pure" pure- <> readsUnaryWith (liftReadsPrec go (liftReadList rp rl)) "wrap" M.wrap+ liftReadsPrec rp rl = go+ where+ go =+ readsData $+ readsUnaryWith rp "pure" pure+ <> readsUnaryWith (liftReadsPrec go (liftReadList rp rl)) "wrap" M.wrap -- | Read in terms of 'pure' and 'M.wrap'. instance (Functor f, Read1 f, Read a) => Read (Free f a) where- readPrec = readPrec1- readListPrec = readListPrecDefault- readList = readListDefault+ readPrec = readPrec1+ readListPrec = readListPrecDefault+ readList = readListDefault -- | Convert a @'Free' f@ into any instance of @'M.MonadFree' f@.-reFree- :: (M.MonadFree f m, Functor f)- => Free f a- -> m a+reFree ::+ (M.MonadFree f m, Functor f) =>+ Free f a ->+ m a reFree = foldFree pure M.wrap -- | Lift an @f@ into @'Free' f@, so you can use it as a 'Monad'.@@ -193,20 +217,22 @@ -- | A version of 'foldFree' that doesn't require @'Functor' f@, by taking -- a RankN folding function. This is essentially a flipped 'runFree'.-foldFree'- :: (a -> r)- -> (forall s. f s -> (s -> r) -> r)- -> Free f a- -> r+foldFree' ::+ (a -> r) ->+ (forall s. f s -> (s -> r) -> r) ->+ Free f a ->+ r foldFree' f g x = runFree x f g -- | A version of 'foldFree' that doesn't require @'Functor' f@, by folding -- over a 'Coyoneda' instead.-foldFreeC- :: (a -> r) -- ^ handle 'pure'- -> (Coyoneda f r -> r) -- ^ handle 'M.wrap'- -> Free f a- -> r+foldFreeC ::+ -- | handle 'pure'+ (a -> r) ->+ -- | handle 'M.wrap'+ (Coyoneda f r -> r) ->+ Free f a ->+ r foldFreeC f g = foldFree' f (\y n -> g (Coyoneda n y)) -- | Recursively fold down a 'Free' by handling the 'pure' case and the@@ -216,12 +242,14 @@ -- -- This requires @'Functor' f@; see 'foldFree'' and 'foldFreeC' for -- a version that doesn't require @'Functor' f@.-foldFree- :: Functor f- => (a -> r) -- ^ handle 'pure'- -> (f r -> r) -- ^ handle 'M.wrap'- -> Free f a- -> r+foldFree ::+ Functor f =>+ -- | handle 'pure'+ (a -> r) ->+ -- | handle 'M.wrap'+ (f r -> r) ->+ Free f a ->+ r foldFree f g = foldFreeC f (g . lowerCoyoneda) -- | The Free 'Bind'. Imbues any functor @f@ with a 'Bind' instance.@@ -235,75 +263,82 @@ -- Sometimes we want an @f :.: f@, or an @f :.: f :.: f@, or an @f :.: -- f :.: f :.: f@...just as long as we have at least one @f@. newtype Free1 f a = Free1- { runFree1 :: forall r. (forall s. f s -> (s -> a) -> r)- -> (forall s. f s -> (s -> r) -> r)- -> r- }+ { runFree1 ::+ forall r.+ (forall s. f s -> (s -> a) -> r) ->+ (forall s. f s -> (s -> r) -> r) ->+ r+ } instance Functor (Free1 f) where- fmap f x = Free1 $ \p b -> runFree1 x (\y c -> p y (f . c)) b+ fmap f x = Free1 $ \p b -> runFree1 x (\y c -> p y (f . c)) b -- | @since 0.4.1.2 instance Invariant (Free1 f) where- invmap f _ = fmap f+ invmap f _ = fmap f instance Apply (Free1 f) where- (<.>) = apDefault+ (<.>) = apDefault instance Bind (Free1 f) where- x >>- f = Free1 $ \p b ->- runFree1 x (\y c -> b y ((\q -> runFree1 q p b) . f . c)) b+ x >>- f = Free1 $ \p b ->+ runFree1 x (\y c -> b y ((\q -> runFree1 q p b) . f . c)) b instance Foldable f => Foldable (Free1 f) where- foldMap f = foldFree1C (foldMap f) fold+ foldMap f = foldFree1C (foldMap f) fold instance Traversable f => Traversable (Free1 f) where- traverse f = foldFree1 (fmap DoneF1 . traverse f)- (fmap MoreF1 . sequenceA )+ traverse f =+ foldFree1+ (fmap DoneF1 . traverse f)+ (fmap MoreF1 . sequenceA) instance Foldable1 f => Foldable1 (Free1 f) where- foldMap1 f = foldFree1C (foldMap1 f) fold1+ foldMap1 f = foldFree1C (foldMap1 f) fold1 instance Traversable1 f => Traversable1 (Free1 f) where- traverse1 f = foldFree1 (fmap DoneF1 . traverse1 f)- (fmap MoreF1 . sequence1 )+ traverse1 f =+ foldFree1+ (fmap DoneF1 . traverse1 f)+ (fmap MoreF1 . sequence1) instance (Functor f, Eq1 f) => Eq1 (Free1 f) where- liftEq eq x y = liftEq @(Free f) eq (toFree x) (toFree y)+ liftEq eq x y = liftEq @(Free f) eq (toFree x) (toFree y) instance (Functor f, Ord1 f) => Ord1 (Free1 f) where- liftCompare c x y = liftCompare @(Free f) c (toFree x) (toFree y)+ liftCompare c x y = liftCompare @(Free f) c (toFree x) (toFree y) instance (Functor f, Eq1 f, Eq a) => Eq (Free1 f a) where- (==) = eq1+ (==) = eq1 instance (Functor f, Ord1 f, Ord a) => Ord (Free1 f a) where- compare = compare1+ compare = compare1 instance (Functor f, Show1 f) => Show1 (Free1 f) where- liftShowsPrec sp sl d = \case- DoneF1 x -> showsUnaryWith (liftShowsPrec sp sl ) "DoneF1" d x- MoreF1 x -> showsUnaryWith (liftShowsPrec sp' sl') "MoreF1" d x- where- sp' = liftShowsPrec sp sl- sl' = liftShowList sp sl+ liftShowsPrec sp sl d = \case+ DoneF1 x -> showsUnaryWith (liftShowsPrec sp sl) "DoneF1" d x+ MoreF1 x -> showsUnaryWith (liftShowsPrec sp' sl') "MoreF1" d x+ where+ sp' = liftShowsPrec sp sl+ sl' = liftShowList sp sl -- | Show in terms of 'DoneF1' and 'MoreF1'. instance (Functor f, Show1 f, Show a) => Show (Free1 f a) where- showsPrec = liftShowsPrec showsPrec showList+ showsPrec = liftShowsPrec showsPrec showList instance (Functor f, Read1 f) => Read1 (Free1 f) where- liftReadsPrec rp rl = go- where- go = readsData $- readsUnaryWith (liftReadsPrec rp rl) "DoneF1" DoneF1- <> readsUnaryWith (liftReadsPrec go (liftReadList rp rl)) "MoreF1" MoreF1+ liftReadsPrec rp rl = go+ where+ go =+ readsData $+ readsUnaryWith (liftReadsPrec rp rl) "DoneF1" DoneF1+ <> readsUnaryWith (liftReadsPrec go (liftReadList rp rl)) "MoreF1" MoreF1 -- | Read in terms of 'DoneF1' and 'MoreF1'. instance (Functor f, Read1 f, Read a) => Read (Free1 f a) where- readPrec = readPrec1- readListPrec = readListPrecDefault- readList = readListDefault+ readPrec = readPrec1+ readListPrec = readListPrecDefault+ readList = readListDefault -- | Constructor matching on the case that a @'Free1' f@ consists of just -- a single un-nested @f@. Used as a part of the 'Show' and 'Read'@@ -321,13 +356,14 @@ pattern MoreF1 x <- (matchFree1 -> R1 (Comp x)) where MoreF1 x = liftFree1 x >>- id+ {-# COMPLETE DoneF1, MoreF1 #-} -- | Convert a @'Free1' f@ into any instance of @'M.MonadFree' f@.-reFree1- :: (M.MonadFree f m, Functor f)- => Free1 f a- -> m a+reFree1 ::+ (M.MonadFree f m, Functor f) =>+ Free1 f a ->+ m a reFree1 = foldFree1 (M.wrap . fmap pure) M.wrap -- | @'Free1' f@ is a special subset of @'Free' f@ that consists of at least one@@ -347,8 +383,8 @@ -- format. free1Comp :: Free1 f ~> Comp f (Free f) free1Comp = foldFree1' (\y c -> y :>>= (pure . c)) $ \y n ->- y :>>= \z -> case n z of- q :>>= m -> liftFree q >>= m+ y :>>= \z -> case n z of+ q :>>= m -> liftFree q >>= m -- | Inject an @f@ into a @'Free1' f@ liftFree1 :: f ~> Free1 f@@ -365,8 +401,10 @@ -- always have at least one @g@, so we do not need a full 'Monad' -- constraint. interpretFree1 :: Bind g => (f ~> g) -> Free1 f ~> g-interpretFree1 f = foldFree1' (\y c -> c <$> f y)- (\y n -> f y >>- n)+interpretFree1 f =+ foldFree1'+ (\y c -> c <$> f y)+ (\y n -> f y >>- n) -- | A @'Free1' f@ is either a single un-nested @f@, or a @f@ nested with -- another @'Free1' f@. This decides which is the case.@@ -374,27 +412,29 @@ matchFree1 = foldFree1 L1 (R1 . Comp . fmap shuffle) where shuffle :: f :+: Comp f (Free1 f) ~> Free1 f- shuffle (L1 y ) = liftFree1 y+ shuffle (L1 y) = liftFree1 y shuffle (R1 (y :>>= n)) = liftFree1 y >>- n -- | A version of 'foldFree1' that doesn't require @'Functor' f@, by taking -- a RankN folding function. This is essentially a flipped 'runFree'.-foldFree1'- :: (forall s. f s -> (s -> a) -> r)- -> (forall s. f s -> (s -> r) -> r)- -> Free1 f a- -> r+foldFree1' ::+ (forall s. f s -> (s -> a) -> r) ->+ (forall s. f s -> (s -> r) -> r) ->+ Free1 f a ->+ r foldFree1' f g x = runFree1 x f g -- | A version of 'foldFree1' that doesn't require @'Functor' f@, by -- folding over a 'Coyoneda' instead.-foldFree1C- :: (Coyoneda f a -> r)- -> (Coyoneda f r -> r)- -> Free1 f a- -> r-foldFree1C f g = foldFree1' (\y c -> f (Coyoneda c y))- (\y n -> g (Coyoneda n y))+foldFree1C ::+ (Coyoneda f a -> r) ->+ (Coyoneda f r -> r) ->+ Free1 f a ->+ r+foldFree1C f g =+ foldFree1'+ (\y c -> f (Coyoneda c y))+ (\y n -> g (Coyoneda n y)) -- | Recursively fold down a 'Free1' by handling the single @f@ case and -- the nested/wrapped case.@@ -403,14 +443,18 @@ -- -- This requires @'Functor' f@; see 'foldFree'' and 'foldFreeC' for -- a version that doesn't require @'Functor' f@.-foldFree1- :: Functor f- => (f a -> r) -- ^ handle @'DoneF1'@.- -> (f r -> r) -- ^ handle @'MoreF1'@.- -> Free1 f a- -> r-foldFree1 f g = foldFree1C (f . lowerCoyoneda)- (g . lowerCoyoneda)+foldFree1 ::+ Functor f =>+ -- | handle @'DoneF1'@.+ (f a -> r) ->+ -- | handle @'MoreF1'@.+ (f r -> r) ->+ Free1 f a ->+ r+foldFree1 f g =+ foldFree1C+ (f . lowerCoyoneda)+ (g . lowerCoyoneda) -- | Functor composition. @'Comp' f g a@ is equivalent to @f (g a)@, and -- the 'Comp' pattern synonym is a way of getting the @f (g a)@ in@@ -432,84 +476,88 @@ -- -- The "free monoid" over 'Comp' is 'Free', and the "free semigroup" over -- 'Comp' is 'Free1'.-data Comp f g a =- forall x. f x :>>= (x -> g a)+data Comp f g a+ = forall x. f x :>>= (x -> g a) instance Functor g => Functor (Comp f g) where- fmap f (x :>>= h) = x :>>= (fmap f . h)+ fmap f (x :>>= h) = x :>>= (fmap f . h) -- | @since 0.4.1.2 instance Invariant g => Invariant (Comp f g) where- invmap f g (x :>>= h) = x :>>= (invmap f g . h)+ invmap f g (x :>>= h) = x :>>= (invmap f g . h) -- | @since 0.3.6.0 instance (Apply f, Apply g) => Apply (Comp f g) where- (x :>>= f) <.> (y :>>= g) = ((,) <$> x <.> y)- :>>= (\(x', y') -> f x' <.> g y')- liftF2 h (x :>>= f) (y :>>= g)- = ((,) <$> x <.> y)- :>>= (\(x', y') -> liftF2 h (f x') (g y'))+ (x :>>= f) <.> (y :>>= g) =+ ((,) <$> x <.> y)+ :>>= (\(x', y') -> f x' <.> g y')+ liftF2 h (x :>>= f) (y :>>= g) =+ ((,) <$> x <.> y)+ :>>= (\(x', y') -> liftF2 h (f x') (g y')) instance (Applicative f, Applicative g) => Applicative (Comp f g) where- pure x = pure () :>>= (pure . const x)- (x :>>= f) <*> (y :>>= g) = ((,) <$> x <*> y)- :>>= (\(x', y') -> f x' <*> g y')- liftA2 h (x :>>= f) (y :>>= g)- = ((,) <$> x <*> y)- :>>= (\(x', y') -> liftA2 h (f x') (g y'))+ pure x = pure () :>>= (pure . const x)+ (x :>>= f) <*> (y :>>= g) =+ ((,) <$> x <*> y)+ :>>= (\(x', y') -> f x' <*> g y')+ liftA2 h (x :>>= f) (y :>>= g) =+ ((,) <$> x <*> y)+ :>>= (\(x', y') -> liftA2 h (f x') (g y')) instance (Foldable f, Foldable g) => Foldable (Comp f g) where- foldMap f (x :>>= h) = foldMap (foldMap f . h) x+ foldMap f (x :>>= h) = foldMap (foldMap f . h) x instance (Traversable f, Traversable g) => Traversable (Comp f g) where- traverse f (x :>>= h) = (:>>= id)- <$> traverse (traverse f . h) x+ traverse f (x :>>= h) =+ (:>>= id)+ <$> traverse (traverse f . h) x instance (Alternative f, Alternative g) => Alternative (Comp f g) where- empty = empty :>>= id- (x :>>= f) <|> (y :>>= g) = ((f <$> x) <|> (g <$> y)) :>>= id+ empty = empty :>>= id+ (x :>>= f) <|> (y :>>= g) = ((f <$> x) <|> (g <$> y)) :>>= id -- | @since 0.3.6.0 instance (Alt f, Alt g) => Alt (Comp f g) where- (x :>>= f) <!> (y :>>= g) = ((f <$> x) <!> (g <$> y)) :>>= id+ (x :>>= f) <!> (y :>>= g) = ((f <$> x) <!> (g <$> y)) :>>= id -- | @since 0.3.6.0 instance (Plus f, Plus g) => Plus (Comp f g) where- zero = zero :>>= id+ zero = zero :>>= id instance (Functor f, Show1 f, Show1 g) => Show1 (Comp f g) where- liftShowsPrec sp sl d (Comp x) =- showsUnaryWith (liftShowsPrec sp' sl') "Comp" d x- where- sp' = liftShowsPrec sp sl- sl' = liftShowList sp sl+ liftShowsPrec sp sl d (Comp x) =+ showsUnaryWith (liftShowsPrec sp' sl') "Comp" d x+ where+ sp' = liftShowsPrec sp sl+ sl' = liftShowList sp sl instance (Functor f, Show1 f, Show1 g, Show a) => Show (Comp f g a) where- showsPrec = liftShowsPrec showsPrec showList+ showsPrec = liftShowsPrec showsPrec showList instance (Functor f, Read1 f, Read1 g) => Read1 (Comp f g) where- liftReadPrec rp rl = readData $- readUnaryWith (liftReadPrec rp' rl') "Comp" Comp- where- rp' = liftReadPrec rp rl- rl' = liftReadListPrec rp rl+ liftReadPrec rp rl =+ readData $+ readUnaryWith (liftReadPrec rp' rl') "Comp" Comp+ where+ rp' = liftReadPrec rp rl+ rl' = liftReadListPrec rp rl instance (Functor f, Read1 f, Read1 g, Read a) => Read (Comp f g a) where- readPrec = readPrec1- readListPrec = readListPrecDefault- readList = readListDefault+ readPrec = readPrec1+ readListPrec = readListPrecDefault+ readList = readListDefault instance (Functor f, Eq1 f, Eq1 g) => Eq1 (Comp f g) where- liftEq eq (Comp x) (Comp y) = liftEq (liftEq eq) x y+ liftEq eq (Comp x) (Comp y) = liftEq (liftEq eq) x y instance (Functor f, Ord1 f, Ord1 g) => Ord1 (Comp f g) where- liftCompare c (Comp x) (Comp y) = liftCompare (liftCompare c) x y+ liftCompare c (Comp x) (Comp y) = liftCompare (liftCompare c) x y instance (Functor f, Eq1 f, Eq1 g, Eq a) => Eq (Comp f g a) where- (==) = eq1+ (==) = eq1 instance (Functor f, Ord1 f, Ord1 g, Ord a) => Ord (Comp f g a) where- compare = compare1+ compare = compare1 -- | "Smart constructor" for 'Comp' that doesn't require @'Functor' f@. comp :: f (g a) -> Comp f g a@@ -518,8 +566,8 @@ -- | Pattern match on and construct a @'Comp' f g a@ as if it were @f -- (g a)@. pattern Comp :: Functor f => f (g a) -> Comp f g a-pattern Comp { unComp } <- ((\case x :>>= f -> f <$> x)->unComp)+pattern Comp{unComp} <- (\case x :>>= f -> f <$> x -> unComp) where Comp x = comp x-{-# COMPLETE Comp #-} +{-# COMPLETE Comp #-}
src/Control/Natural/IsoF.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Control.Natural.IsoF--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -10,19 +10,21 @@ -- Types describing isomorphisms between two functors, and functions to -- manipulate them. module Control.Natural.IsoF (- type (~>)- , type (<~>)- , isoF- , coercedF- , viewF, reviewF, overF- , fromF- ) where+ type (~>),+ type (<~>),+ isoF,+ coercedF,+ viewF,+ reviewF,+ overF,+ fromF,+) where -import Control.Natural-import Data.Coerce-import Data.Kind-import Data.Profunctor-import Data.Tagged+import Control.Natural+import Data.Coerce+import Data.Kind+import Data.Profunctor+import Data.Tagged -- | The type of an isomorphism between two functors. @f '<~>' g@ means that -- @f@ and @g@ are isomorphic to each other.@@ -61,20 +63,22 @@ -- 'Data.HBifunctor.Tensor.splittingSF' :: 'Data.HBifunctor.Tensor.Monoidal' t => 'Data.HBifunctor.Associative.SF' t a '<~>' t f ('Data.HBifunctor.Tensor.MF' t f) -- 'Data.HBifunctor.Tensor.splitSF' :: Monoidal t => SF t a '~>' t f (MF t f) -- @-type f <~> g = forall p a. Profunctor p => p (g a) (g a) -> p (f a) (f a)+type f <~> g = forall p a. Profunctor p => p (g a) (g a) -> p (f a) (f a)+ infixr 0 <~> -- | Create an @f '<~>' g@ by providing both legs of the isomorphism (the -- @f a -> g a@ and the @g a -> f a@.-isoF- :: f ~> g- -> g ~> f- -> f <~> g+isoF ::+ f ~> g ->+ g ~> f ->+ f <~> g isoF f g a = dimap f g a -- | An isomorphism between two functors that are coercible/have the same -- internal representation. Useful for newtype wrappers.-coercedF :: forall f g. (forall x. Coercible (f x) (g x), forall x. Coercible (g x) (f x)) => f <~> g+coercedF ::+ forall f g. (forall x. Coercible (f x) (g x), forall x. Coercible (g x) (f x)) => f <~> g coercedF = isoF coerce coerce -- | Use a '<~>' by retrieving the "forward" function:@@ -106,8 +110,9 @@ -- 'viewF' ('fromF' i) == 'reviewF' i -- 'reviewF' ('fromF' i) == 'viewF' i -- @-fromF- :: forall (f :: Type -> Type) (g :: Type -> Type). ()- => f <~> g- -> g <~> f+fromF ::+ forall (f :: Type -> Type) (g :: Type -> Type).+ () =>+ f <~> g ->+ g <~> f fromF i = isoF (reviewF i) (viewF i)
src/Data/Functor/Apply/Free.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.Functor.Apply.Free--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -13,25 +13,26 @@ -- Ideally 'Ap1' would be in the /free/ package. However, it is defined -- here for now. module Data.Functor.Apply.Free (- Ap1(.., DayAp1, ap1Day)- , toAp, fromAp- , liftAp1- , retractAp1- , runAp1- ) where+ Ap1 (.., DayAp1, ap1Day),+ toAp,+ fromAp,+ liftAp1,+ retractAp1,+ runAp1,+) where -import Control.Applicative.Free-import Control.Natural-import Data.Function-import Data.Functor.Apply-import Data.Functor.Day-import Data.Functor.Identity-import Data.Functor.Invariant-import Data.HFunctor-import Data.HFunctor.HTraversable-import Data.HFunctor.Interpret-import Data.Kind-import GHC.Generics+import Control.Applicative.Free+import Control.Natural+import Data.Function+import Data.Functor.Apply+import Data.Functor.Day+import Data.Functor.Identity+import Data.Functor.Invariant+import Data.HFunctor+import Data.HFunctor.HTraversable+import Data.HFunctor.Interpret+import Data.Kind+import GHC.Generics -- | One or more @f@s convolved with itself. --@@ -57,7 +58,7 @@ -- The construction here is based on 'Ap', similar to now -- 'Data.List.NonEmpty.NonEmpty' is built on list. data Ap1 :: (Type -> Type) -> Type -> Type where- Ap1 :: f a -> Ap f (a -> b) -> Ap1 f b+ Ap1 :: f a -> Ap f (a -> b) -> Ap1 f b -- | An 'Ap1' is a "non-empty" 'Ap'; this function "forgets" the non-empty -- property and turns it back into a normal 'Ap'.@@ -68,25 +69,26 @@ -- return the 'Pure' value instead. fromAp :: Ap f ~> (Identity :+: Ap1 f) fromAp = \case- Pure x -> L1 $ Identity x- Ap x xs -> R1 $ Ap1 x xs+ Pure x -> L1 $ Identity x+ Ap x xs -> R1 $ Ap1 x xs -- | @since 0.3.0.0 instance Invariant (Ap1 f) where- invmap f _ = fmap f+ invmap f _ = fmap f -- | An @'Ap1' f@ is just a @'Day' f ('Ap' f)@. This bidirectional pattern -- synonym lets you treat it as such. pattern DayAp1 :: Day f (Ap f) a -> Ap1 f a-pattern DayAp1 { ap1Day } <- ((\case Ap1 x y -> Day x y (&)) -> ap1Day)+pattern DayAp1{ap1Day} <- (\case Ap1 x y -> Day x y (&) -> ap1Day) where DayAp1 (Day x y f) = Ap1 x (flip f <$> y)+ {-# COMPLETE DayAp1 #-} deriving instance Functor (Ap1 f) instance Apply (Ap1 f) where- Ap1 x xs <.> ys = Ap1 x (flip <$> xs <*> toAp ys)+ Ap1 x xs <.> ys = Ap1 x (flip <$> xs <*> toAp ys) -- | Embed an @f@ into 'Ap1'. liftAp1 :: f ~> Ap1 f@@ -101,60 +103,60 @@ retractAp1 (Ap1 x xs) = retractAp1_ x xs -- | Interpret an @'Ap' f@ into some 'Apply' context @g@.-runAp1- :: Apply g- => (f ~> g)- -> Ap1 f ~> g+runAp1 ::+ Apply g =>+ (f ~> g) ->+ Ap1 f ~> g runAp1 f (Ap1 x xs) = runAp1_ f x xs instance HFunctor Ap1 where- hmap f (Ap1 x xs) = Ap1 (f x) (hmap f xs)+ hmap f (Ap1 x xs) = Ap1 (f x) (hmap f xs) instance Inject Ap1 where- inject = liftAp1+ inject = liftAp1 instance HBind Ap1 where- hbind = runAp1+ hbind = runAp1 instance HTraversable Ap1 where- htraverse f (Ap1 x xs) = Ap1 <$> f x <*> htraverse f xs+ htraverse f (Ap1 x xs) = Ap1 <$> f x <*> htraverse f xs instance HTraversable1 Ap1 where- htraverse1 f (Ap1 x xs) = traverseAp1_ f x xs+ htraverse1 f (Ap1 x xs) = traverseAp1_ f x xs -traverseAp1_- :: forall f g h a b. Apply h- => (forall x. f x -> h (g x))- -> f a- -> Ap f (a -> b)- -> h (Ap1 g b)+traverseAp1_ ::+ forall f g h a b.+ Apply h =>+ (forall x. f x -> h (g x)) ->+ f a ->+ Ap f (a -> b) ->+ h (Ap1 g b) traverseAp1_ f = go where go :: f x -> Ap f (x -> y) -> h (Ap1 g y) go x = \case- Pure y -> (`Ap1` Pure y) <$> f x+ Pure y -> (`Ap1` Pure y) <$> f x Ap y ys -> Ap1 <$> f x <.> (toAp <$> go y ys) - instance Apply f => Interpret Ap1 f where- retract = retractAp1- interpret = runAp1+ retract = retractAp1+ interpret = runAp1 retractAp1_ :: Apply f => f a -> Ap f (a -> b) -> f b retractAp1_ x = \case- Pure y -> y <$> x- Ap y ys -> (&) <$> x <.> retractAp1_ y ys+ Pure y -> y <$> x+ Ap y ys -> (&) <$> x <.> retractAp1_ y ys -runAp1_- :: forall f g a b. Apply g- => (f ~> g)- -> f a- -> Ap f (a -> b)- -> g b+runAp1_ ::+ forall f g a b.+ Apply g =>+ (f ~> g) ->+ f a ->+ Ap f (a -> b) ->+ g b runAp1_ f = go where go :: f x -> Ap f (x -> y) -> g y go x = \case- Pure y -> y <$> f x+ Pure y -> y <$> f x Ap y ys -> (&) <$> f x <.> go y ys-
src/Data/Functor/Combinator.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.Functor.Combinator--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -30,128 +30,163 @@ -- combinator. module Data.Functor.Combinator ( -- * Classes+ -- | A lot of type signatures are stated in terms of '~>'. '~>' -- represents a "natural transformation" between two functors: a value of -- type @f '~>' g@ is a value of type 'f a -> g a@ that works for /any/ -- @a@.- type (~>)- , type (<~>)+ type (~>),+ type (<~>),+ -- ** Single Functors+ -- | Classes that deal with single-functor combinators, that enhance -- a single functor.- , HFunctor(..)- , Inject(..)- , Interpret(..)- , forI- , iget, icollect, icollect1- , iapply, ifanout, ifanout1- , getI, collectI- , injectMap, injectContramap- , AltConst(..)+ HFunctor (..),+ Inject (..),+ Interpret (..),+ forI,+ iget,+ icollect,+ icollect1,+ iapply,+ ifanout,+ ifanout1,+ getI,+ collectI,+ injectMap,+ injectContramap,+ AltConst (..),+ -- ** 'HTraversable'- , HTraversable(..), hsequence, hfoldMap, htoList- , HTraversable1(..), hsequence1, hfoldMap1, htoNonEmpty+ HTraversable (..),+ hsequence,+ hfoldMap,+ htoList,+ HTraversable1 (..),+ hsequence1,+ hfoldMap1,+ htoNonEmpty,+ -- ** Multi-Functors+ -- | Classes that deal with two-functor combinators, that "mix" two -- functors together in some way.- , HBifunctor(..)+ HBifunctor (..),+ -- *** Associative- , Associative(..)- , SemigroupIn(..)- , biget, biapply+ Associative (..),+ SemigroupIn (..),+ biget,+ biapply, -- , biget, bicollect, bicollect1- , (!*!)- , (!+!)- , (!$!)+ (!*!),+ (!+!),+ (!$!),+ -- *** Tensor- , Tensor(..)- , MonoidIn(..)- , nilLB, consLB- , inL, inR- , outL, outR+ Tensor (..),+ MonoidIn (..),+ nilLB,+ consLB,+ inL,+ inR,+ outL,+ outR,+ -- * Combinators+ -- | Functor combinators -- ** Single- , Coyoneda(..)- , ListF(..)- , NonEmptyF(..)- , MaybeF(..)- , MapF(..)- , NEMapF(..)- , Ap- , Ap1(..)- , Alt- , Free- , Free1- , Lift- , Step(..)- , Steps(..)- , ProxyF(..)- , ConstF(..)- , EnvT(..)- , ReaderT(..)- , Flagged(..)- , IdentityT(..)- , Void2- , Final(..)- , FreeOf(..)- , ComposeT(..)+ Coyoneda (..),+ ListF (..),+ NonEmptyF (..),+ MaybeF (..),+ MapF (..),+ NEMapF (..),+ Ap,+ Ap1 (..),+ Alt,+ Free,+ Free1,+ Lift,+ Step (..),+ Steps (..),+ ProxyF (..),+ ConstF (..),+ EnvT (..),+ ReaderT (..),+ Flagged (..),+ IdentityT (..),+ Void2,+ Final (..),+ FreeOf (..),+ ComposeT (..),+ -- ** Multi- , Day(..)- , (:*:)(..), prodOutL, prodOutR- , (:+:)(..), V1- , These1(..)- , Night(..), Not(..), refuted- , Comp(Comp, unComp)- , LeftF(..)- , RightF(..)+ Day (..),+ (:*:) (..),+ prodOutL,+ prodOutR,+ (:+:) (..),+ V1,+ These1 (..),+ Night (..),+ Not (..),+ refuted,+ Comp (Comp, unComp),+ LeftF (..),+ RightF (..),+ -- ** Combinator Combinators- , HLift(..)- , HFree(..)+ HLift (..),+ HFree (..),+ -- * Util+ -- ** Natural Transformations- , generalize- , absorb- -- ** Divisible- , dsum- , dsum1- , concludeN- , decideN- ) where+ generalize,+ absorb, -import Control.Alternative.Free-import Control.Applicative.Free-import Control.Applicative.Lift-import Control.Applicative.ListF-import Control.Applicative.Step-import Control.Comonad.Trans.Env-import Control.Monad.Freer.Church-import Control.Monad.Trans.Compose-import Control.Monad.Trans.Identity-import Control.Monad.Trans.Reader-import Control.Natural-import Control.Natural.IsoF-import Data.Functor.Apply.Free-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Coyoneda-import Data.Functor.Day-import Data.Functor.Invariant.Night-import Data.Functor.These-import Data.HBifunctor-import Data.HBifunctor.Associative-import Data.HBifunctor.Tensor-import Data.HFunctor-import Data.HFunctor.Final-import Data.HFunctor.HTraversable-import Data.HFunctor.Internal-import Data.HFunctor.Interpret-import GHC.Generics-import qualified Data.SOP as SOP+ -- ** Divisible+ dsum,+ dsum1,+ concludeN,+ decideN,+) where +import Control.Alternative.Free+import Control.Applicative.Free+import Control.Applicative.Lift+import Control.Applicative.ListF+import Control.Applicative.Step+import Control.Comonad.Trans.Env+import Control.Monad.Freer.Church+import Control.Monad.Trans.Compose+import Control.Monad.Trans.Identity+import Control.Monad.Trans.Reader+import Control.Natural+import Control.Natural.IsoF+import Data.Functor.Apply.Free+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Coyoneda+import Data.Functor.Day+import Data.Functor.Invariant.Night+import Data.Functor.These+import Data.HBifunctor+import Data.HBifunctor.Associative+import Data.HBifunctor.Tensor+import Data.HFunctor+import Data.HFunctor.Final+import Data.HFunctor.HTraversable+import Data.HFunctor.Internal+import Data.HFunctor.Interpret+import qualified Data.SOP as SOP+import GHC.Generics -- | Convenient helper function to build up a 'Divisible' by splitting -- input across many different @f a@s. Most useful when used alongside@@ -166,11 +201,11 @@ -- @ -- -- @since 0.3.3.0-dsum- :: (Foldable t, Divisible f)- => t (f a)- -> f a-dsum = foldr (divide (\x -> (x,x))) conquer+dsum ::+ (Foldable t, Divisible f) =>+ t (f a) ->+ f a+dsum = foldr (divide (\x -> (x, x))) conquer -- | Convenient helper function to build up a 'Conclude' by providing -- each component of it. This makes it much easier to build up longer@@ -204,14 +239,15 @@ -- otherwise you'd need to manually peel off eithers one-by-one. -- -- @since 0.3.0.0-concludeN- :: Conclude f- => SOP.NP f as- -> f (SOP.NS SOP.I as)+concludeN ::+ Conclude f =>+ SOP.NP f as ->+ f (SOP.NS SOP.I as) concludeN = \case- SOP.Nil -> conclude (\case {})- x SOP.:* xs -> decide- (\case SOP.Z y -> Left (SOP.unI y); SOP.S ys -> Right ys)+ SOP.Nil -> conclude (\case {})+ x SOP.:* xs ->+ decide+ (\case SOP.Z y -> Left (SOP.unI y); SOP.S ys -> Right ys) x (concludeN xs) @@ -219,14 +255,15 @@ -- and so only requires a 'Decide' constraint. -- -- @since 0.3.0.0-decideN- :: Decide f- => SOP.NP f (a ': as)- -> f (SOP.NS SOP.I (a ': as))+decideN ::+ Decide f =>+ SOP.NP f (a ': as) ->+ f (SOP.NS SOP.I (a ': as)) decideN = \case- x SOP.:* xs -> case xs of- SOP.Nil -> contramap (SOP.unI . SOP.unZ) x- _ SOP.:* _ -> decide+ x SOP.:* xs -> case xs of+ SOP.Nil -> contramap (SOP.unI . SOP.unZ) x+ _ SOP.:* _ ->+ decide (\case SOP.Z z -> Left (SOP.unI z); SOP.S zs -> Right zs) x (decideN xs)
src/Data/Functor/Combinator/Unsafe.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.Functor.Combinator.Unsafe--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -20,32 +20,32 @@ -- coherence. Because of this, you should always use these with /specific/ -- @f@s, and never in a polymorphic way over @f@. module Data.Functor.Combinator.Unsafe (- unsafePlus- , unsafeApply- , unsafeBind- , unsafePointed- , unsafeConclude- , unsafeDivise- , unsafeInvariantCo- , unsafeInvariantContra- , unsafeInplyCo- , unsafeInplyContra- , unsafeInplicativeCo- , unsafeInplicativeContra- ) where+ unsafePlus,+ unsafeApply,+ unsafeBind,+ unsafePointed,+ unsafeConclude,+ unsafeDivise,+ unsafeInvariantCo,+ unsafeInvariantContra,+ unsafeInplyCo,+ unsafeInplyContra,+ unsafeInplicativeCo,+ unsafeInplicativeContra,+) where -import Control.Applicative-import Data.Constraint-import Data.Constraint.Unsafe-import Data.Functor.Bind-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Invariant-import Data.Functor.Invariant.Inplicative-import Data.Functor.Plus-import Data.Pointed+import Control.Applicative+import Data.Constraint+import Data.Constraint.Unsafe+import Data.Functor.Bind+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Invariant+import Data.Functor.Invariant.Inplicative+import Data.Functor.Plus+import Data.Pointed -- | For any @'Alternative' f@, produce a value that would require @'Plus' -- f@.@@ -58,7 +58,7 @@ -- \@MyFunctor@. unsafePlus :: forall f proxy r. Alternative f => proxy f -> (Plus f => r) -> r unsafePlus _ x = case unsafeCoerceConstraint @(Plus (WrappedApplicative f)) @(Plus f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Applicative' f@, produce a value that would require @'Apply' -- f@.@@ -71,7 +71,7 @@ -- \@MyFunctor@. unsafeApply :: forall f proxy r. Applicative f => proxy f -> (Apply f => r) -> r unsafeApply _ x = case unsafeCoerceConstraint @(Apply (WrappedApplicative f)) @(Apply f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Monad' f@, produce a value that would require @'Bind' -- f@.@@ -84,12 +84,12 @@ -- \@MyFunctor@. unsafeBind :: forall f proxy r. Monad f => proxy f -> (Bind f => r) -> r unsafeBind _ x = case unsafeCoerceConstraint @(Bind (WrappedMonad f)) @(Bind f) of- Sub Dict -> x+ Sub Dict -> x newtype PointMe f a = PointMe (f a) instance Applicative f => Pointed (PointMe f) where- point = PointMe . pure+ point = PointMe . pure -- | For any @'Applicative' f@, produce a value that would require -- @'Pointed' f@.@@ -102,7 +102,7 @@ -- \@MyFunctor@. unsafePointed :: forall f proxy r. Applicative f => proxy f -> (Pointed f => r) -> r unsafePointed _ x = case unsafeCoerceConstraint @(Pointed (PointMe f)) @(Pointed f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Decidable' f@, produce a value that would require @'Conclude' -- f@.@@ -117,7 +117,7 @@ -- @since 0.3.0.0 unsafeConclude :: forall f proxy r. Decidable f => proxy f -> (Conclude f => r) -> r unsafeConclude _ x = case unsafeCoerceConstraint @(Conclude (WrappedDivisible f)) @(Conclude f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Divisible' f@, produce a value that would require @'Divise' -- f@.@@ -132,7 +132,7 @@ -- @since 0.3.0.0 unsafeDivise :: forall f proxy r. Divisible f => proxy f -> (Divise f => r) -> r unsafeDivise _ x = case unsafeCoerceConstraint @(Divise (WrappedDivisible f)) @(Divise f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Functor' f@, produce a value that would require @'Invariant' -- f@.@@ -147,7 +147,7 @@ -- @since 0.4.1.0 unsafeInvariantCo :: forall f proxy r. Functor f => proxy f -> (Invariant f => r) -> r unsafeInvariantCo _ x = case unsafeCoerceConstraint @(Invariant (WrappedFunctor f)) @(Invariant f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Contravariant' f@, produce a value that would require @'Invariant' -- f@.@@ -162,7 +162,7 @@ -- @since 0.4.1.0 unsafeInvariantContra :: forall f proxy r. Contravariant f => proxy f -> (Invariant f => r) -> r unsafeInvariantContra _ x = case unsafeCoerceConstraint @(Invariant (WrappedContravariant f)) @(Invariant f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Apply' f@, produce a value that would require @'Inply' -- f@.@@ -177,7 +177,7 @@ -- @since 0.4.1.0 unsafeInplyCo :: forall f proxy r. Apply f => proxy f -> (Inply f => r) -> r unsafeInplyCo _ x = case unsafeCoerceConstraint @(Inply (WrappedFunctor f)) @(Inply f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Divise' f@, produce a value that would require @'Inply' -- f@.@@ -192,7 +192,7 @@ -- @since 0.4.1.0 unsafeInplyContra :: forall f proxy r. Divise f => proxy f -> (Inply f => r) -> r unsafeInplyContra _ x = case unsafeCoerceConstraint @(Inply (WrappedContravariant f)) @(Inply f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Applicative' f@, produce a value that would require -- @'Inplicative' f@.@@ -205,9 +205,10 @@ -- \@MyFunctor@. -- -- @since 0.4.1.0-unsafeInplicativeCo :: forall f proxy r. (Applicative f, Invariant f) => proxy f -> (Inplicative f => r) -> r+unsafeInplicativeCo ::+ forall f proxy r. (Applicative f, Invariant f) => proxy f -> (Inplicative f => r) -> r unsafeInplicativeCo _ x = case unsafeCoerceConstraint @(Inply (WrappedApplicativeOnly f)) @(Inplicative f) of- Sub Dict -> x+ Sub Dict -> x -- | For any @'Divisibl3' f@, produce a value that would require -- @'Inplicative' f@.@@ -220,7 +221,7 @@ -- \@MyFunctor@. -- -- @since 0.4.1.0-unsafeInplicativeContra :: forall f proxy r. (Divisible f, Invariant f) => proxy f -> (Inplicative f => r) -> r+unsafeInplicativeContra ::+ forall f proxy r. (Divisible f, Invariant f) => proxy f -> (Inplicative f => r) -> r unsafeInplicativeContra _ x = case unsafeCoerceConstraint @(Inply (WrappedDivisibleOnly f)) @(Inplicative f) of- Sub Dict -> x-+ Sub Dict -> x
src/Data/Functor/Contravariant/Conclude.hs view
@@ -1,10 +1,10 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE TypeOperators #-} {-# OPTIONS_GHC -Wno-deprecations #-} -- | -- Module : Data.Functor.Contravariant.Conclude--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -18,9 +18,9 @@ -- -- @since 0.3.0.0 module Data.Functor.Contravariant.Conclude (- Conclude(..)- , concluded- ) where+ Conclude (..),+ concluded,+) where import Control.Applicative.Backwards import Control.Monad.Trans.Identity@@ -97,8 +97,8 @@ -- 'Decide', it adds a way to construct an "identity" @conclude@ where -- @decide f x (conclude q) == x@, and @decide g (conclude r) y == y@. class Decide f => Conclude f where- -- | The consumer that cannot ever receive /any/ input.- conclude :: (a -> Void) -> f a+ -- | The consumer that cannot ever receive /any/ input.+ conclude :: (a -> Void) -> f a -- | A potentially more meaningful form of 'conclude', the consumer that cannot -- ever receive /any/ input. That is because it expects only input of type@@ -111,7 +111,7 @@ concluded = conclude id instance Decidable f => Conclude (WrappedDivisible f) where- conclude f = WrapDivisible (lose f)+ conclude f = WrapDivisible (lose f) instance Conclude Comparison where conclude = lose instance Conclude Equivalence where conclude = lose@@ -194,4 +194,3 @@ lazyFst :: (a, b) -> a lazyFst ~(a, _) = a-
src/Data/Functor/Contravariant/Decide.hs view
@@ -1,10 +1,10 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE TypeOperators #-} {-# OPTIONS_GHC -Wno-deprecations #-} -- | -- Module : Data.Functor.Contravariant.Decide--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -18,14 +18,20 @@ -- -- @since 0.3.0.0 module Data.Functor.Contravariant.Decide (- Decide(..)- , decided- ) where+ Decide (..),+ decided,+) where import Control.Applicative.Backwards import Control.Monad.Trans.Identity import Control.Monad.Trans.Maybe+import qualified Control.Monad.Trans.RWS.Lazy as Lazy+import qualified Control.Monad.Trans.RWS.Strict as Strict import Control.Monad.Trans.Reader+import qualified Control.Monad.Trans.State.Lazy as Lazy+import qualified Control.Monad.Trans.State.Strict as Strict+import qualified Control.Monad.Trans.Writer.Lazy as Lazy+import qualified Control.Monad.Trans.Writer.Strict as Strict import Data.Functor.Apply import Data.Functor.Compose import Data.Functor.Contravariant@@ -33,12 +39,6 @@ import Data.Functor.Contravariant.Divisible import Data.Functor.Product import Data.Functor.Reverse-import qualified Control.Monad.Trans.RWS.Lazy as Lazy-import qualified Control.Monad.Trans.RWS.Strict as Strict-import qualified Control.Monad.Trans.State.Lazy as Lazy-import qualified Control.Monad.Trans.State.Strict as Strict-import qualified Control.Monad.Trans.Writer.Lazy as Lazy-import qualified Control.Monad.Trans.Writer.Strict as Strict #if MIN_VERSION_base(4,8,0) import Data.Monoid (Alt(..))@@ -81,9 +81,9 @@ -- That is, it is possible to define a function @(f `EitherDay` f) a -> -- f a@ in a way that is associative. class Contravariant f => Decide f where- -- | Takes the "decision" method and the two potential consumers, and- -- returns the wrapped/combined consumer.- decide :: (a -> Either b c) -> f b -> f c -> f a+ -- | Takes the "decision" method and the two potential consumers, and+ -- returns the wrapped/combined consumer.+ decide :: (a -> Either b c) -> f b -> f c -> f a -- | For @'decided' x y@, the resulting @f ('Either' b c)@ will direct -- 'Left's to be consumed by @x@, and 'Right's to be consumed by y.@@ -91,7 +91,7 @@ decided = decide id instance Decidable f => Decide (WrappedDivisible f) where- decide f (WrapDivisible x) (WrapDivisible y) = WrapDivisible (choose f x y)+ decide f (WrapDivisible x) (WrapDivisible y) = WrapDivisible (choose f x y) instance Decide Comparison where decide = choose instance Decide Equivalence where decide = choose@@ -135,17 +135,27 @@ instance Decide m => Decide (Lazy.RWST r w s m) where decide abc (Lazy.RWST rsmb) (Lazy.RWST rsmc) = Lazy.RWST $ \r s ->- decide (\ ~(a, s', w) -> either (Left . betuple3 s' w)- (Right . betuple3 s' w)- (abc a))- (rsmb r s) (rsmc r s)+ decide+ ( \ ~(a, s', w) ->+ either+ (Left . betuple3 s' w)+ (Right . betuple3 s' w)+ (abc a)+ )+ (rsmb r s)+ (rsmc r s) instance Decide m => Decide (Strict.RWST r w s m) where decide abc (Strict.RWST rsmb) (Strict.RWST rsmc) = Strict.RWST $ \r s ->- decide (\(a, s', w) -> either (Left . betuple3 s' w)- (Right . betuple3 s' w)- (abc a))- (rsmb r s) (rsmc r s)+ decide+ ( \(a, s', w) ->+ either+ (Left . betuple3 s' w)+ (Right . betuple3 s' w)+ (abc a)+ )+ (rsmb r s)+ (rsmc r s) #if !MIN_VERSION_transformers(0,6,0) instance Divise m => Decide (ListT m) where@@ -153,29 +163,43 @@ #endif instance Divise m => Decide (MaybeT m) where- decide f (MaybeT l) (MaybeT r) = MaybeT $- divise ( maybe (Nothing, Nothing)- (either (\b -> (Just b, Nothing))- (\c -> (Nothing, Just c)) . f)- ) l r+ decide f (MaybeT l) (MaybeT r) =+ MaybeT $+ divise+ ( maybe+ (Nothing, Nothing)+ ( either+ (\b -> (Just b, Nothing))+ (\c -> (Nothing, Just c))+ . f+ )+ )+ l+ r instance Decide m => Decide (Lazy.StateT s m) where decide f (Lazy.StateT l) (Lazy.StateT r) = Lazy.StateT $ \s ->- decide (\ ~(a, s') -> either (Left . betuple s') (Right . betuple s') (f a))- (l s) (r s)+ decide+ (\ ~(a, s') -> either (Left . betuple s') (Right . betuple s') (f a))+ (l s)+ (r s) instance Decide m => Decide (Strict.StateT s m) where decide f (Strict.StateT l) (Strict.StateT r) = Strict.StateT $ \s ->- decide (\(a, s') -> either (Left . betuple s') (Right . betuple s') (f a))- (l s) (r s)+ decide+ (\(a, s') -> either (Left . betuple s') (Right . betuple s') (f a))+ (l s)+ (r s) instance Decide m => Decide (Lazy.WriterT w m) where- decide f (Lazy.WriterT l) (Lazy.WriterT r) = Lazy.WriterT $- decide (\ ~(a, s') -> either (Left . betuple s') (Right . betuple s') (f a)) l r+ decide f (Lazy.WriterT l) (Lazy.WriterT r) =+ Lazy.WriterT $+ decide (\ ~(a, s') -> either (Left . betuple s') (Right . betuple s') (f a)) l r instance Decide m => Decide (Strict.WriterT w m) where- decide f (Strict.WriterT l) (Strict.WriterT r) = Strict.WriterT $- decide (\(a, s') -> either (Left . betuple s') (Right . betuple s') (f a)) l r+ decide f (Strict.WriterT l) (Strict.WriterT r) =+ Strict.WriterT $+ decide (\(a, s') -> either (Left . betuple s') (Right . betuple s') (f a)) l r -- | Unlike 'Decidable', requires only 'Apply' on @f@. instance (Apply f, Decide g) => Decide (Compose f g) where
src/Data/Functor/Contravariant/Divise.hs view
@@ -1,10 +1,10 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE TypeOperators #-} {-# OPTIONS_GHC -Wno-deprecations #-} -- | -- Module : Data.Functor.Contravariant.Divise--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -17,35 +17,35 @@ -- -- @since 0.3.0.0 module Data.Functor.Contravariant.Divise (- Divise(..)- , (<:>)- , dsum1- , WrappedDivisible(..)- ) where+ Divise (..),+ (<:>),+ dsum1,+ WrappedDivisible (..),+) where -import Control.Applicative-import Control.Applicative.Backwards-import Control.Arrow-import Control.Monad.Trans.Except-import Control.Monad.Trans.Identity-import Control.Monad.Trans.Maybe-import Control.Monad.Trans.Reader-import Data.Deriving-import Data.Functor.Apply-import Data.Functor.Compose-import Data.Functor.Constant-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Divisible-import Data.Functor.Invariant-import Data.Functor.Product-import Data.Functor.Reverse-import qualified Control.Monad.Trans.RWS.Lazy as Lazy-import qualified Control.Monad.Trans.RWS.Strict as Strict-import qualified Control.Monad.Trans.State.Lazy as Lazy-import qualified Control.Monad.Trans.State.Strict as Strict-import qualified Control.Monad.Trans.Writer.Lazy as Lazy-import qualified Control.Monad.Trans.Writer.Strict as Strict-import qualified Data.Semigroup.Foldable as F1+import Control.Applicative+import Control.Applicative.Backwards+import Control.Arrow+import Control.Monad.Trans.Except+import Control.Monad.Trans.Identity+import Control.Monad.Trans.Maybe+import qualified Control.Monad.Trans.RWS.Lazy as Lazy+import qualified Control.Monad.Trans.RWS.Strict as Strict+import Control.Monad.Trans.Reader+import qualified Control.Monad.Trans.State.Lazy as Lazy+import qualified Control.Monad.Trans.State.Strict as Strict+import qualified Control.Monad.Trans.Writer.Lazy as Lazy+import qualified Control.Monad.Trans.Writer.Strict as Strict+import Data.Deriving+import Data.Functor.Apply+import Data.Functor.Compose+import Data.Functor.Constant+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Divisible+import Data.Functor.Invariant+import Data.Functor.Product+import Data.Functor.Reverse+import qualified Data.Semigroup.Foldable as F1 #if MIN_VERSION_base(4,8,0) import Data.Monoid (Alt(..))@@ -98,20 +98,22 @@ -- convolution. That is, it is possible to define a function @(f `Day` f) -- a -> f a@ in a way that is associative. class Contravariant f => Divise f where- -- | Takes a "splitting" method and the two sub-consumers, and- -- returns the wrapped/combined consumer.- divise :: (a -> (b, c)) -> f b -> f c -> f a- divise f x y = contramap f (divised x y)- -- | Combine a consumer of @a@ with a consumer of @b@ to get a consumer- -- of @(a, b)@.- divised :: f a -> f b -> f (a, b)- divised = divise id- {-# MINIMAL divise | divised #-}+ -- | Takes a "splitting" method and the two sub-consumers, and+ -- returns the wrapped/combined consumer.+ divise :: (a -> (b, c)) -> f b -> f c -> f a+ divise f x y = contramap f (divised x y) + -- | Combine a consumer of @a@ with a consumer of @b@ to get a consumer+ -- of @(a, b)@.+ divised :: f a -> f b -> f (a, b)+ divised = divise id++ {-# MINIMAL divise | divised #-}+ -- | The Contravariant version of '<|>': split the same input over two -- different consumers. (<:>) :: Divise f => f a -> f a -> f a-x <:> y = divise (\r -> (r,r)) x y+x <:> y = divise (\r -> (r, r)) x y -- | Convenient helper function to build up a 'Divise' by splitting -- input across many different @f a@s. Most useful when used alongside@@ -129,7 +131,7 @@ dsum1 = foldr1 (<:>) . F1.toNonEmpty -- | Wrap a 'Divisible' to be used as a member of 'Divise'-newtype WrappedDivisible f a = WrapDivisible { unwrapDivisible :: f a }+newtype WrappedDivisible f a = WrapDivisible {unwrapDivisible :: f a} deriving (Generic, Eq, Show, Ord, Read, Functor, Foldable, Traversable) deriving newtype (Divisible, Contravariant) @@ -223,15 +225,21 @@ instance Divise m => Divise (Lazy.RWST r w s m) where divise abc (Lazy.RWST rsmb) (Lazy.RWST rsmc) = Lazy.RWST $ \r s ->- divise (\ ~(a, s', w) -> case abc a of- ~(b, c) -> ((b, s', w), (c, s', w)))- (rsmb r s) (rsmc r s)+ divise+ ( \ ~(a, s', w) -> case abc a of+ ~(b, c) -> ((b, s', w), (c, s', w))+ )+ (rsmb r s)+ (rsmc r s) instance Divise m => Divise (Strict.RWST r w s m) where divise abc (Strict.RWST rsmb) (Strict.RWST rsmc) = Strict.RWST $ \r s ->- divise (\(a, s', w) -> case abc a of- (b, c) -> ((b, s', w), (c, s', w)))- (rsmb r s) (rsmc r s)+ divise+ ( \(a, s', w) -> case abc a of+ (b, c) -> ((b, s', w), (c, s', w))+ )+ (rsmb r s)+ (rsmc r s) instance Divise m => Divise (Lazy.StateT s m) where divise f (Lazy.StateT l) (Lazy.StateT r) = Lazy.StateT $ \s ->@@ -242,12 +250,14 @@ divise (strictFanout f) (l s) (r s) instance Divise m => Divise (Lazy.WriterT w m) where- divise f (Lazy.WriterT l) (Lazy.WriterT r) = Lazy.WriterT $- divise (lazyFanout f) l r+ divise f (Lazy.WriterT l) (Lazy.WriterT r) =+ Lazy.WriterT $+ divise (lazyFanout f) l r instance Divise m => Divise (Strict.WriterT w m) where- divise f (Strict.WriterT l) (Strict.WriterT r) = Strict.WriterT $- divise (strictFanout f) l r+ divise f (Strict.WriterT l) (Strict.WriterT r) =+ Strict.WriterT $+ divise (strictFanout f) l r -- | Unlike 'Divisible', requires only 'Apply' on @f@. instance (Apply f, Divise g) => Divise (Compose f g) where
src/Data/Functor/Contravariant/Divisible/Free.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Data.Functor.Contravariant.Divisible.Free--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -14,42 +14,54 @@ -- -- @since 0.3.0.0 module Data.Functor.Contravariant.Divisible.Free (- Div(.., Conquer, Divide)- , hoistDiv, liftDiv, runDiv- , divListF, listFDiv- , Div1(.., Div1_)- , hoistDiv1, liftDiv1, toDiv, runDiv1- , div1NonEmptyF, nonEmptyFDiv1- , Dec(..)- , hoistDec, liftDec, runDec- , Dec1(..)- , hoistDec1, liftDec1, toDec, runDec1- ) where+ Div (.., Conquer, Divide),+ hoistDiv,+ liftDiv,+ runDiv,+ divListF,+ listFDiv,+ Div1 (.., Div1_),+ hoistDiv1,+ liftDiv1,+ toDiv,+ runDiv1,+ div1NonEmptyF,+ nonEmptyFDiv1,+ Dec (..),+ hoistDec,+ liftDec,+ runDec,+ Dec1 (..),+ hoistDec1,+ liftDec1,+ toDec,+ runDec1,+) where -import Control.Applicative.ListF-import Control.Natural-import Data.Bifunctor-import Data.Bifunctor.Assoc-import Data.Foldable-import Data.Functor.Apply-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Coyoneda-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Invariant-import Data.Functor.Invariant.Inplicative-import Data.Functor.Invariant.Internative-import Data.HFunctor-import Data.HFunctor.HTraversable-import Data.HFunctor.Interpret-import Data.Kind-import Data.List.NonEmpty (NonEmpty(..))-import Data.Semigroup.Traversable-import Data.Void-import qualified Control.Monad.Trans.Compose as CT-import qualified Data.Functor.Contravariant.Day as CD+import Control.Applicative.ListF+import qualified Control.Monad.Trans.Compose as CT+import Control.Natural+import Data.Bifunctor+import Data.Bifunctor.Assoc+import Data.Foldable+import Data.Functor.Apply+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import Data.Functor.Contravariant.Coyoneda+import qualified Data.Functor.Contravariant.Day as CD+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Invariant+import Data.Functor.Invariant.Inplicative+import Data.Functor.Invariant.Internative+import Data.HFunctor+import Data.HFunctor.HTraversable+import Data.HFunctor.Interpret+import Data.Kind+import Data.List.NonEmpty (NonEmpty (..))+import Data.Semigroup.Traversable+import Data.Void -- | The free 'Divisible'. Used to sequence multiple contravariant -- consumers, splitting out the input across all consumers.@@ -63,15 +75,15 @@ -- The wrapping in 'Coyoneda' is also to provide a usable -- 'Data.HBifunctor.Associative.Associative' instance for the contravariant -- 'CD.Day'.-newtype Div f a = Div { unDiv :: [Coyoneda f a] }+newtype Div f a = Div {unDiv :: [Coyoneda f a]} deriving (Contravariant, Divise, Divisible) via (ListF (Coyoneda f)) deriving (HFunctor, Inject) via (CT.ComposeT ListF Coyoneda) instance HTraversable Div where- htraverse f (Div xs) = Div <$> traverse (htraverse f) xs+ htraverse f (Div xs) = Div <$> traverse (htraverse f) xs instance Invariant (Div f) where- invmap _ = contramap+ invmap _ = contramap deriving via WrappedDivisible (Div f) instance Inply (Div f) deriving via WrappedDivisible (Div f) instance Inplicative (Div f)@@ -94,6 +106,7 @@ pattern Divide f x xs <- (divDay_ -> Just (CD.Day x xs f)) where Divide f x (Div xs) = Div $ Coyoneda (fst . f) x : (map . contramap) (snd . f) xs+ {-# COMPLETE Conquer, Divide #-} divDay_ :: Div f a -> Maybe (CD.Day f (Div f) a)@@ -122,10 +135,10 @@ runDiv :: forall f g. Divisible g => (f ~> g) -> Div f ~> g runDiv f = foldr go conquer . unDiv where- go (Coyoneda g x) = divide (\y -> (y,y)) (contramap g (f x))+ go (Coyoneda g x) = divide (\y -> (y, y)) (contramap g (f x)) instance Divisible f => Interpret Div f where- interpret = runDiv+ interpret = runDiv -- | The free 'Divise': a non-empty version of 'Div'. --@@ -138,23 +151,23 @@ -- The wrapping in 'Coyoneda' is also to provide a usable -- 'Data.HBifunctor.Associative.Associative' instance for the contravariant -- 'CD.Day'.-newtype Div1 f a = Div1 { unDiv1 :: NonEmpty (Coyoneda f a) }+newtype Div1 f a = Div1 {unDiv1 :: NonEmpty (Coyoneda f a)} deriving (Contravariant, Divise) via (NonEmptyF (Coyoneda f)) deriving (HFunctor, Inject) via (CT.ComposeT NonEmptyF Coyoneda) instance HTraversable Div1 where- htraverse f (Div1 xs) = Div1 <$> traverse (htraverse f) xs+ htraverse f (Div1 xs) = Div1 <$> traverse (htraverse f) xs instance HTraversable1 Div1 where- htraverse1 f (Div1 xs) = Div1 <$> traverse1 (htraverse1 f) xs+ htraverse1 f (Div1 xs) = Div1 <$> traverse1 (htraverse1 f) xs instance Invariant (Div1 f) where- invmap _ = contramap+ invmap _ = contramap deriving via WrappedDivisible (Div1 f) instance Inply (Div1 f) instance Divise f => Interpret Div1 f where- interpret = runDiv1+ interpret = runDiv1 -- | Pattern matching on a 'Div1', exposing the raw @f@ instead of -- having it wrapped in a 'Coyoneda'. This is the analogue of@@ -166,9 +179,10 @@ -- -- @since 0.3.3.0 pattern Div1_ :: (a -> (b, c)) -> f b -> Div f c -> Div1 f a-pattern Div1_ f x xs <- (div1_->CD.Day x xs f)+pattern Div1_ f x xs <- (div1_ -> CD.Day x xs f) where Div1_ f x (Div xs) = Div1 $ Coyoneda (fst . f) x :| (map . contramap) (snd . f) xs+ {-# COMPLETE Div1_ #-} div1_ :: Div1 f ~> CD.Day f (Div f)@@ -189,7 +203,7 @@ -- | Interpret a 'Div1' into a context @g@, provided @g@ is 'Divise'. runDiv1 :: Divise g => (f ~> g) -> Div1 f ~> g-runDiv1 f = foldr1 (divise (\y->(y,y))) . fmap go . unDiv1+runDiv1 f = foldr1 (divise (\y -> (y, y))) . fmap go . unDiv1 where go (Coyoneda g x) = contramap g (f x) @@ -206,39 +220,40 @@ -- | The free 'Decide'. Used to aggregate multiple possible consumers, -- directing the input into an appropriate consumer. data Dec :: (Type -> Type) -> Type -> Type where- Lose :: (a -> Void) -> Dec f a- Choose :: (a -> Either b c) -> f b -> Dec f c -> Dec f a+ Lose :: (a -> Void) -> Dec f a+ Choose :: (a -> Either b c) -> f b -> Dec f c -> Dec f a instance Contravariant (Dec f) where- contramap f = \case- Lose g -> Lose (g . f)- Choose g x xs -> Choose (g . f) x xs+ contramap f = \case+ Lose g -> Lose (g . f)+ Choose g x xs -> Choose (g . f) x xs instance Invariant (Dec f) where- invmap _ = contramap+ invmap _ = contramap deriving via WrappedDivisible (Dec f) instance Inalt (Dec f) deriving via WrappedDivisible (Dec f) instance Inplus (Dec f) instance Decide (Dec f) where- decide f = \case- Lose g -> contramap (either (absurd . g) id . f)- Choose g x xs -> Choose (assoc . first g . f) x- . decide id xs+ decide f = \case+ Lose g -> contramap (either (absurd . g) id . f)+ Choose g x xs ->+ Choose (assoc . first g . f) x+ . decide id xs instance Conclude (Dec f) where- conclude = Lose+ conclude = Lose instance HFunctor Dec where- hmap = hoistDec+ hmap = hoistDec instance Inject Dec where- inject = liftDec+ inject = liftDec instance Conclude f => Interpret Dec f where- interpret = runDec+ interpret = runDec instance HTraversable Dec where- htraverse :: forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> Dec f a -> h (Dec g a)- htraverse f = go- where- go :: Dec f b -> h (Dec g b)- go = \case- Lose v -> pure (Lose v)- Choose g x xs -> Choose g <$> f x <*> go xs+ htraverse :: forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> Dec f a -> h (Dec g a)+ htraverse f = go+ where+ go :: Dec f b -> h (Dec g b)+ go = \case+ Lose v -> pure (Lose v)+ Choose g x xs -> Choose g <$> f x <*> go xs -- | Map over the underlying context in a 'Dec'. hoistDec :: forall f g. (f ~> g) -> Dec f ~> Dec g@@ -262,10 +277,9 @@ Lose g -> conclude g Choose g x xs -> decide g (f x) (go xs) - -- | The free 'Decide': a non-empty version of 'Dec'. data Dec1 :: (Type -> Type) -> Type -> Type where- Dec1 :: (a -> Either b c) -> f b -> Dec f c -> Dec1 f a+ Dec1 :: (a -> Either b c) -> f b -> Dec f c -> Dec1 f a -- | A 'Dec1' is a "non-empty" 'Dec'; this function "forgets" the non-empty -- property and turns it back into a normal 'Dec'.@@ -273,26 +287,27 @@ toDec (Dec1 f x xs) = Choose f x xs instance Contravariant (Dec1 f) where- contramap f (Dec1 g x xs) = Dec1 (g . f) x xs+ contramap f (Dec1 g x xs) = Dec1 (g . f) x xs instance Invariant (Dec1 f) where- invmap _ = contramap+ invmap _ = contramap deriving via WrappedDivisible (Dec1 f) instance Inalt (Dec1 f) instance Decide (Dec1 f) where- decide f (Dec1 g x xs) = Dec1 (assoc . first g . f) x- . decide id xs- . toDec+ decide f (Dec1 g x xs) =+ Dec1 (assoc . first g . f) x+ . decide id xs+ . toDec instance HFunctor Dec1 where- hmap = hoistDec1+ hmap = hoistDec1 instance Inject Dec1 where- inject = liftDec1+ inject = liftDec1 instance Decide f => Interpret Dec1 f where- interpret = runDec1+ interpret = runDec1 instance HTraversable Dec1 where- htraverse f (Dec1 g x xs) = Dec1 g <$> f x <*> htraverse f xs+ htraverse f (Dec1 g x xs) = Dec1 g <$> f x <*> htraverse f xs instance HTraversable1 Dec1 where- htraverse1 f (Dec1 g x xs) = traverseDec1_ f g x xs+ htraverse1 f (Dec1 g x xs) = traverseDec1_ f g x xs -- | Map over the undering context in a 'Dec1'. hoistDec1 :: forall f g. (f ~> g) -> Dec1 f ~> Dec1 g@@ -306,30 +321,32 @@ runDec1 :: Decide g => (f ~> g) -> Dec1 f ~> g runDec1 f (Dec1 g x xs) = runDec1_ f g x xs -runDec1_- :: forall f g a b c. Decide g- => (f ~> g)- -> (a -> Either b c)- -> f b- -> Dec f c- -> g a+runDec1_ ::+ forall f g a b c.+ Decide g =>+ (f ~> g) ->+ (a -> Either b c) ->+ f b ->+ Dec f c ->+ g a runDec1_ f = go where go :: (x -> Either y z) -> f y -> Dec f z -> g x go g x = \case- Lose h -> contramap (either id (absurd . h) . g) (f x)+ Lose h -> contramap (either id (absurd . h) . g) (f x) Choose h y ys -> decide g (f x) (go h y ys) -traverseDec1_- :: forall f g h a b c. Apply h- => (forall x. f x -> h (g x))- -> (a -> Either b c)- -> f b- -> Dec f c- -> h (Dec1 g a)+traverseDec1_ ::+ forall f g h a b c.+ Apply h =>+ (forall x. f x -> h (g x)) ->+ (a -> Either b c) ->+ f b ->+ Dec f c ->+ h (Dec1 g a) traverseDec1_ f = go where go :: (x -> Either y z) -> f y -> Dec f z -> h (Dec1 g x) go g x = \case- Lose h -> (\x' -> Dec1 g x' (Lose h)) <$> f x+ Lose h -> (\x' -> Dec1 g x' (Lose h)) <$> f x Choose h y ys -> Dec1 g <$> f x <.> (toDec <$> go h y ys)
src/Data/Functor/Contravariant/Night.hs view
@@ -1,7 +1,6 @@- -- | -- Module : Data.Functor.Contravariant.Night--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -13,26 +12,32 @@ -- -- @since 0.3.0.0 module Data.Functor.Contravariant.Night (- Night(..)- , night- , runNight, necide- , assoc, unassoc- , swapped- , trans1, trans2- , intro1, intro2- , elim1, elim2- , Not(..), refuted- ) where+ Night (..),+ night,+ runNight,+ necide,+ assoc,+ unassoc,+ swapped,+ trans1,+ trans2,+ intro1,+ intro2,+ elim1,+ elim2,+ Not (..),+ refuted,+) where -import Control.Natural-import Data.Bifunctor-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Decide-import Data.Functor.Invariant-import Data.Kind-import Data.Void-import qualified Data.Bifunctor.Assoc as B-import qualified Data.Bifunctor.Swap as B+import Control.Natural+import Data.Bifunctor+import qualified Data.Bifunctor.Assoc as B+import qualified Data.Bifunctor.Swap as B+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Decide+import Data.Functor.Invariant+import Data.Kind+import Data.Void -- | A pairing of contravariant functors to create a new contravariant -- functor that represents the "choice" between the two.@@ -52,43 +57,44 @@ -- about in Haskell (which uses @(,)@). Therefore, it is an alternative to -- the typical 'Data.Functor.Day' convolution --- hence, the name 'Night'. data Night :: (Type -> Type) -> (Type -> Type) -> (Type -> Type) where- Night :: f b- -> g c- -> (a -> Either b c)- -> Night f g a+ Night ::+ f b ->+ g c ->+ (a -> Either b c) ->+ Night f g a instance Contravariant (Night f g) where- contramap f (Night x y g) = Night x y (g . f)+ contramap f (Night x y g) = Night x y (g . f) instance Invariant (Night f g) where- invmap _ f (Night x y g) = Night x y (g . f)+ invmap _ f (Night x y g) = Night x y (g . f) -- | Inject into a 'Night'. -- -- @'night' x y@ is a consumer of @'Either' a b@; 'Left' will be passed -- to @x@, and 'Right' will be passed to @y@.-night- :: f a- -> g b- -> Night f g (Either a b)+night ::+ f a ->+ g b ->+ Night f g (Either a b) night x y = Night x y id -- | Interpret out of a 'Night' into any instance of 'Decide' by providing -- two interpreting functions.-runNight- :: Decide h- => (f ~> h)- -> (g ~> h)- -> Night f g ~> h+runNight ::+ Decide h =>+ (f ~> h) ->+ (g ~> h) ->+ Night f g ~> h runNight f g (Night x y z) = decide z (f x) (g y) -- | Squash the two items in a 'Night' using their natural 'Decide' -- instances. -- -- @since 0.4.0.0-necide- :: Decide f- => Night f f ~> f+necide ::+ Decide f =>+ Night f f ~> f necide (Night x y z) = decide z x y -- | 'Night' is associative.@@ -112,7 +118,7 @@ trans2 f (Night x y z) = Night x (f y) z -- | A value of type @'Not' a@ is "proof" that @a@ is uninhabited.-newtype Not a = Not { refute :: a -> Void }+newtype Not a = Not {refute :: a -> Void} -- | A useful shortcut for a common usage: 'Void' is always not so. --@@ -121,13 +127,14 @@ refuted = Not id instance Contravariant Not where- contramap f (Not g) = Not (g . f)+ contramap f (Not g) = Not (g . f)+ -- | @since 0.3.1.0 instance Invariant Not where- invmap _ = contramap+ invmap _ = contramap instance Semigroup (Not a) where- Not f <> Not g = Not (f <> g)+ Not f <> Not g = Not (f <> g) -- | The left identity of 'Night' is 'Not'; this is one side of that -- isomorphism.
src/Data/Functor/Invariant/Inplicative.hs view
@@ -1,5 +1,5 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE DerivingVia #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE DerivingVia #-} {-# OPTIONS_GHC -fno-warn-deprecations #-} -- |@@ -17,77 +17,80 @@ -- @since 0.4.0.0 module Data.Functor.Invariant.Inplicative ( -- * Typeclass- Inply(..)- , Inplicative(..)+ Inply (..),+ Inplicative (..),+ -- * Deriving- , WrappedApplicativeOnly(..)- , WrappedDivisibleOnly(..)+ WrappedApplicativeOnly (..),+ WrappedDivisibleOnly (..),+ -- * Invariant 'Day'- , runDay- , dather- , runDayApply- , runDayDivise+ runDay,+ dather,+ runDayApply,+ runDayDivise,+ -- * Assembling Helpers- , gatheredN- , gatheredNMap- , gatheredN1- , gatheredN1Map- , gatheredNRec- , gatheredNMapRec- , gatheredN1Rec- , gatheredN1MapRec- , gatherN- , gatherN1- ) where+ gatheredN,+ gatheredNMap,+ gatheredN1,+ gatheredN1Map,+ gatheredNRec,+ gatheredNMapRec,+ gatheredN1Rec,+ gatheredN1MapRec,+ gatherN,+ gatherN1,+) where -import Control.Applicative-import Control.Applicative.Backwards (Backwards(..))-import Control.Applicative.Lift (Lift(Pure, Other))-import Control.Arrow (Arrow)-import Control.Monad.Trans.Cont (ContT)-import Control.Monad.Trans.Except (ExceptT(..))-import Control.Monad.Trans.Identity (IdentityT(..))-import Control.Monad.Trans.Maybe (MaybeT(..))-import Control.Monad.Trans.RWS (RWST(..))-import Control.Monad.Trans.Reader (ReaderT(..))-import Control.Monad.Trans.State (StateT)-import Control.Monad.Trans.Writer (WriterT(..))-import Control.Natural-import Data.Complex (Complex)-import Data.Deriving-import Data.Functor.Apply-import Data.Functor.Bind.Class (Bind)-import Data.Functor.Constant (Constant)-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Identity-import Data.Functor.Invariant-import Data.Functor.Invariant.Day-import Data.Functor.Product (Product(..))-import Data.Functor.Reverse (Reverse(..))-import Data.Hashable (Hashable)-import Data.Kind-import Data.List.NonEmpty (NonEmpty)-import Data.SOP hiding (hmap)-import Data.Sequence (Seq)-import Data.StateVar (SettableStateVar)-import Data.Tagged (Tagged)-import Data.Tree (Tree)-import GHC.Generics (Generic)-import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST(..))-import qualified Control.Monad.Trans.State.Strict as Strict (StateT)-import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT(..))-import qualified Data.HashMap.Lazy as HM-import qualified Data.IntMap as IM-import qualified Data.Map as M-import qualified Data.Monoid as Monoid-import qualified Data.Semigroup as Semigroup-import qualified Data.Sequence.NonEmpty as NESeq-import qualified Data.Vinyl as V-import qualified Data.Vinyl.Curry as V-import qualified Data.Vinyl.Functor as V-import qualified GHC.Generics as Generics+import Control.Applicative+import Control.Applicative.Backwards (Backwards (..))+import Control.Applicative.Lift (Lift (Other, Pure))+import Control.Arrow (Arrow)+import Control.Monad.Trans.Cont (ContT)+import Control.Monad.Trans.Except (ExceptT (..))+import Control.Monad.Trans.Identity (IdentityT (..))+import Control.Monad.Trans.Maybe (MaybeT (..))+import Control.Monad.Trans.RWS (RWST (..))+import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST (..))+import Control.Monad.Trans.Reader (ReaderT (..))+import Control.Monad.Trans.State (StateT)+import qualified Control.Monad.Trans.State.Strict as Strict (StateT)+import Control.Monad.Trans.Writer (WriterT (..))+import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT (..))+import Control.Natural+import Data.Complex (Complex)+import Data.Deriving+import Data.Functor.Apply+import Data.Functor.Bind.Class (Bind)+import Data.Functor.Constant (Constant)+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Identity+import Data.Functor.Invariant+import Data.Functor.Invariant.Day+import Data.Functor.Product (Product (..))+import Data.Functor.Reverse (Reverse (..))+import qualified Data.HashMap.Lazy as HM+import Data.Hashable (Hashable)+import qualified Data.IntMap as IM+import Data.Kind+import Data.List.NonEmpty (NonEmpty)+import qualified Data.Map as M+import qualified Data.Monoid as Monoid+import Data.SOP hiding (hmap)+import qualified Data.Semigroup as Semigroup+import Data.Sequence (Seq)+import qualified Data.Sequence.NonEmpty as NESeq+import Data.StateVar (SettableStateVar)+import Data.Tagged (Tagged)+import Data.Tree (Tree)+import qualified Data.Vinyl as V+import qualified Data.Vinyl.Curry as V+import qualified Data.Vinyl.Functor as V+import GHC.Generics (Generic)+import qualified GHC.Generics as Generics #if !MIN_VERSION_transformers(0,6,0) import Control.Monad.Trans.Error@@ -112,42 +115,44 @@ -- -- @since 0.4.0.0 class Invariant f => Inply f where- -- | Like '<.>', '<*>', 'divise', or 'divide', but requires both- -- a splitting and a recombining function. '<.>' and '<*>' require- -- only a combining function, and 'divise' and 'divide' require only- -- a splitting function.- --- -- It is used to merge @f b@ (producer and consumer of @b@) and @f c@- -- (producer and consumer of @c@) into a @f a@. You can think of it- -- as, for the @f a@, it "splits" the a into @b@ and @c@ with the @a ->- -- (b, c)@, feeds it to the original @f b@ and @f c@, and then- -- re-combines the output back into a @a@ with the @b -> c -> a@.- --- -- An important property is that it will always use @both@ of the- -- ccomponents given in order to fulfil its job. If you gather an @f- -- a@ and an @f b@ into an @f c@, in order to consume/produdce the @c@,- -- it will always use both the @f a@ or the @f b@ -- exactly one of- -- them.- --- -- @since 0.4.0.0- gather- :: (b -> c -> a)- -> (a -> (b, c))- -> f b- -> f c- -> f a- gather f g x y = invmap (uncurry f) g (gathered x y)- -- | A simplified version of 'gather' that combines into a tuple. You- -- can then use 'invmap' to reshape it into the proper shape.- --- -- @since 0.4.0.0- gathered- :: f a- -> f b- -> f (a, b)- gathered = gather (,) id- {-# MINIMAL gather | gathered #-}+ -- | Like '<.>', '<*>', 'divise', or 'divide', but requires both+ -- a splitting and a recombining function. '<.>' and '<*>' require+ -- only a combining function, and 'divise' and 'divide' require only+ -- a splitting function.+ --+ -- It is used to merge @f b@ (producer and consumer of @b@) and @f c@+ -- (producer and consumer of @c@) into a @f a@. You can think of it+ -- as, for the @f a@, it "splits" the a into @b@ and @c@ with the @a ->+ -- (b, c)@, feeds it to the original @f b@ and @f c@, and then+ -- re-combines the output back into a @a@ with the @b -> c -> a@.+ --+ -- An important property is that it will always use @both@ of the+ -- ccomponents given in order to fulfil its job. If you gather an @f+ -- a@ and an @f b@ into an @f c@, in order to consume/produdce the @c@,+ -- it will always use both the @f a@ or the @f b@ -- exactly one of+ -- them.+ --+ -- @since 0.4.0.0+ gather ::+ (b -> c -> a) ->+ (a -> (b, c)) ->+ f b ->+ f c ->+ f a+ gather f g x y = invmap (uncurry f) g (gathered x y) + -- | A simplified version of 'gather' that combines into a tuple. You+ -- can then use 'invmap' to reshape it into the proper shape.+ --+ -- @since 0.4.0.0+ gathered ::+ f a ->+ f b ->+ f (a, b)+ gathered = gather (,) id++ {-# MINIMAL gather | gathered #-}+ -- | The invariant counterpart of 'Applicative' and 'Divisible'. -- -- The main important action is described in 'Inply', but this adds 'knot',@@ -160,7 +165,7 @@ -- -- @since 0.4.0.0 class Inply f => Inplicative f where- knot :: a -> f a+ knot :: a -> f a -- | Interpret out of a contravariant 'Day' into any instance of 'Inply' by -- providing two interpreting functions.@@ -169,11 +174,11 @@ -- a different package. -- -- @since 0.4.0.0-runDay- :: Inply h- => (f ~> h)- -> (g ~> h)- -> Day f g ~> h+runDay ::+ Inply h =>+ (f ~> h) ->+ (g ~> h) ->+ Day f g ~> h runDay f g (Day x y a b) = gather a b (f x) (g y) -- | Squash the two items in a 'Day' using their natural 'Inply'@@ -183,38 +188,40 @@ -- a different package. -- -- @since 0.4.0.0-dather- :: Inply f- => Day f f ~> f+dather ::+ Inply f =>+ Day f f ~> f dather (Day x y a b) = gather a b x y -- | Ignores the contravariant part of 'gather' instance Apply f => Inply (WrappedFunctor f) where- gather f _ (WrapFunctor x) (WrapFunctor y) = WrapFunctor (liftF2 f x y)- gathered (WrapFunctor x) (WrapFunctor y) = WrapFunctor (liftF2 (,) x y)+ gather f _ (WrapFunctor x) (WrapFunctor y) = WrapFunctor (liftF2 f x y)+ gathered (WrapFunctor x) (WrapFunctor y) = WrapFunctor (liftF2 (,) x y)+ -- | @'knot' = 'pure'@ instance (Applicative f, Apply f) => Inplicative (WrappedFunctor f) where- knot = pure+ knot = pure -- | Ignores the covariant part of 'gather' instance Divise f => Inply (WrappedContravariant f) where- gather _ g (WrapContravariant x) (WrapContravariant y) = WrapContravariant (divise g x y)- gathered (WrapContravariant x) (WrapContravariant y) = WrapContravariant (divised x y)+ gather _ g (WrapContravariant x) (WrapContravariant y) = WrapContravariant (divise g x y)+ gathered (WrapContravariant x) (WrapContravariant y) = WrapContravariant (divised x y)+ -- | @'knot' _ = 'conquer'@ instance (Divisible f, Divise f) => Inplicative (WrappedContravariant f) where- knot _ = conquer+ knot _ = conquer -- | Ignores the covariant part of 'gather' instance Divise f => Inply (WrappedDivisible f) where- gather _ g (WrapDivisible x) (WrapDivisible y) = WrapDivisible (divise g x y)- gathered (WrapDivisible x) (WrapDivisible y) = WrapDivisible (divised x y)+ gather _ g (WrapDivisible x) (WrapDivisible y) = WrapDivisible (divise g x y)+ gathered (WrapDivisible x) (WrapDivisible y) = WrapDivisible (divised x y)+ -- | @'knot' _ = 'conquer'@ instance (Divisible f, Divise f) => Inplicative (WrappedDivisible f) where- knot _ = conquer+ knot _ = conquer -- | Wrap an 'Applicative' that is not necessarily an 'Apply'.-newtype WrappedApplicativeOnly f a =- WrapApplicativeOnly { unwrapApplicativeOnly :: f a }+newtype WrappedApplicativeOnly f a = WrapApplicativeOnly {unwrapApplicativeOnly :: f a} deriving (Generic, Eq, Show, Ord, Read, Functor, Foldable, Traversable) deriving newtype (Applicative, Monad) @@ -224,20 +231,21 @@ deriveOrd1 ''WrappedApplicativeOnly instance Invariant f => Invariant (WrappedApplicativeOnly f) where- invmap f g (WrapApplicativeOnly x) = WrapApplicativeOnly (invmap f g x)+ invmap f g (WrapApplicativeOnly x) = WrapApplicativeOnly (invmap f g x) instance (Applicative f, Invariant f) => Apply (WrappedApplicativeOnly f) where- x <.> y = x <*> y+ x <.> y = x <*> y+ -- | Ignores the contravariant part of 'gather' instance (Applicative f, Invariant f) => Inply (WrappedApplicativeOnly f) where- gather f _ (WrapApplicativeOnly x) (WrapApplicativeOnly y) = WrapApplicativeOnly (liftA2 f x y)- gathered (WrapApplicativeOnly x) (WrapApplicativeOnly y) = WrapApplicativeOnly (liftA2 (,) x y)+ gather f _ (WrapApplicativeOnly x) (WrapApplicativeOnly y) = WrapApplicativeOnly (liftA2 f x y)+ gathered (WrapApplicativeOnly x) (WrapApplicativeOnly y) = WrapApplicativeOnly (liftA2 (,) x y)+ -- | @'knot' = 'pure'@ instance (Applicative f, Invariant f) => Inplicative (WrappedApplicativeOnly f) where- knot = pure+ knot = pure -- | Wrap an 'Divisible' that is not necessarily a 'Divise'.-newtype WrappedDivisibleOnly f a =- WrapDivisibleOnly { unwrapDivisibleOnly :: f a }+newtype WrappedDivisibleOnly f a = WrapDivisibleOnly {unwrapDivisibleOnly :: f a} deriving (Generic, Eq, Show, Ord, Read, Functor, Foldable, Traversable) deriving newtype (Divisible, Contravariant) @@ -247,63 +255,78 @@ deriveOrd1 ''WrappedDivisibleOnly instance Invariant f => Invariant (WrappedDivisibleOnly f) where- invmap f g (WrapDivisibleOnly x) = WrapDivisibleOnly (invmap f g x)+ invmap f g (WrapDivisibleOnly x) = WrapDivisibleOnly (invmap f g x) instance (Divisible f, Invariant f) => Divise (WrappedDivisibleOnly f) where- divise g (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (divide g x y)+ divise g (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (divide g x y)+ -- | Ignores the covariant part of 'gather' instance (Divisible f, Invariant f) => Inply (WrappedDivisibleOnly f) where- gather _ g (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (divide g x y)- gathered (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (divided x y)+ gather _ g (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (divide g x y)+ gathered (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (divided x y)+ -- | @'knot' _ = 'conquer'@ instance (Divisible f, Invariant f) => Inplicative (WrappedDivisibleOnly f) where- knot _ = conquer+ knot _ = conquer funzip :: Functor f => f (a, b) -> (f a, f b) funzip x = (fmap fst x, fmap snd x) -- | @since 0.4.1.0 instance Inply f => Inply (MaybeT f) where- gather f g (MaybeT x) (MaybeT y) = MaybeT $+ gather f g (MaybeT x) (MaybeT y) =+ MaybeT $ gather (liftA2 f) (funzip . fmap g) x y+ -- | @since 0.4.1.0 instance Inplicative f => Inplicative (MaybeT f) where- knot x = MaybeT (knot (Just x))+ knot x = MaybeT (knot (Just x)) -- | @since 0.4.1.0 instance (Inply f, Semigroup w) => Inply (WriterT w f) where- gather f g (WriterT x) (WriterT y) = WriterT $- gather (\case (a, q) -> \case (b, r) -> (f a b, q <> r))- (\case (a, s) -> case g a of (b, c) -> ((b, s), (c, s)))- x y+ gather f g (WriterT x) (WriterT y) =+ WriterT $+ gather+ (\case (a, q) -> \case (b, r) -> (f a b, q <> r))+ (\case (a, s) -> case g a of (b, c) -> ((b, s), (c, s)))+ x+ y+ -- | @since 0.4.1.0 instance (Inplicative f, Monoid w) => Inplicative (WriterT w f) where- knot x = WriterT (knot (x, mempty))+ knot x = WriterT (knot (x, mempty)) -- | @since 0.4.1.0 instance (Inply f, Semigroup w) => Inply (Strict.WriterT w f) where- gather f g (Strict.WriterT x) (Strict.WriterT y) = Strict.WriterT $- gather (\(~(a, q)) (~(b, r)) -> (f a b, q <> r))- (\(~(a, s)) -> let ~(b, c) = g a in ((b, s), (c, s)))- x y+ gather f g (Strict.WriterT x) (Strict.WriterT y) =+ Strict.WriterT $+ gather+ (\(~(a, q)) (~(b, r)) -> (f a b, q <> r))+ (\(~(a, s)) -> let ~(b, c) = g a in ((b, s), (c, s)))+ x+ y+ -- | @since 0.4.1.0 instance (Inplicative f, Monoid w) => Inplicative (Strict.WriterT w f) where- knot x = Strict.WriterT (knot (x, mempty))+ knot x = Strict.WriterT (knot (x, mempty)) -- | @since 0.4.1.0 instance Inply f => Inply (ReaderT r f) where- gather f g (ReaderT x) (ReaderT y) = ReaderT $ \r ->- gather f g (x r) (y r)+ gather f g (ReaderT x) (ReaderT y) = ReaderT $ \r ->+ gather f g (x r) (y r)+ -- | @since 0.4.1.0 instance Inplicative f => Inplicative (ReaderT r f) where- knot x = ReaderT (\_ -> knot x)+ knot x = ReaderT (\_ -> knot x) -- | @since 0.4.1.0 instance Inply f => Inply (ExceptT e f) where- gather f g (ExceptT x) (ExceptT y) = ExceptT $+ gather f g (ExceptT x) (ExceptT y) =+ ExceptT $ gather (liftA2 f) (funzip . fmap g) x y+ -- | @since 0.4.1.0 instance Inplicative f => Inplicative (ExceptT e f) where- knot x = ExceptT (knot (Right x))+ knot x = ExceptT (knot (Right x)) #if !MIN_VERSION_transformers(0,6,0) -- | @since 0.4.1.0@@ -324,148 +347,229 @@ #endif -- | @since 0.4.1.0-deriving via WrappedFunctor (RWST r w s m) instance (Bind m, Invariant m, Semigroup w) => Inply (RWST r w s m)+deriving via+ WrappedFunctor (RWST r w s m)+ instance+ (Bind m, Invariant m, Semigroup w) => Inply (RWST r w s m)+ -- | @since 0.4.1.0-deriving via WrappedFunctor (RWST r w s m) instance (Monad m, Bind m, Invariant m, Monoid w) => Inplicative (RWST r w s m)+deriving via+ WrappedFunctor (RWST r w s m)+ instance+ (Monad m, Bind m, Invariant m, Monoid w) => Inplicative (RWST r w s m)+ -- | @since 0.4.1.0-deriving via WrappedFunctor (Strict.RWST r w s m) instance (Bind m, Invariant m, Semigroup w) => Inply (Strict.RWST r w s m)+deriving via+ WrappedFunctor (Strict.RWST r w s m)+ instance+ (Bind m, Invariant m, Semigroup w) => Inply (Strict.RWST r w s m)+ -- | @since 0.4.1.0-deriving via WrappedFunctor (Strict.RWST r w s m) instance (Monad m, Bind m, Invariant m, Monoid w) => Inplicative (Strict.RWST r w s m)+deriving via+ WrappedFunctor (Strict.RWST r w s m)+ instance+ (Monad m, Bind m, Invariant m, Monoid w) => Inplicative (Strict.RWST r w s m)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (StateT s m) instance (Bind m, Invariant m) => Inply (StateT s m)+ -- | @since 0.4.1.0-deriving via WrappedFunctor (StateT s m) instance (Monad m, Bind m, Invariant m) => Inplicative (StateT s m)+deriving via+ WrappedFunctor (StateT s m)+ instance+ (Monad m, Bind m, Invariant m) => Inplicative (StateT s m)+ -- | @since 0.4.1.0-deriving via WrappedFunctor (Strict.StateT s m) instance (Bind m, Invariant m) => Inply (Strict.StateT s m)+deriving via+ WrappedFunctor (Strict.StateT s m)+ instance+ (Bind m, Invariant m) => Inply (Strict.StateT s m)+ -- | @since 0.4.1.0-deriving via WrappedFunctor (Strict.StateT s m) instance (Monad m, Bind m, Invariant m) => Inplicative (Strict.StateT s m)+deriving via+ WrappedFunctor (Strict.StateT s m)+ instance+ (Monad m, Bind m, Invariant m) => Inplicative (Strict.StateT s m) -- | @since 0.4.1.0 instance Inply f => Inply (Generics.M1 i t f :: Type -> Type) where- gather f g (Generics.M1 x) (Generics.M1 y) = Generics.M1 (gather f g x y)+ gather f g (Generics.M1 x) (Generics.M1 y) = Generics.M1 (gather f g x y)+ -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Generics.M1 i t f :: Type -> Type) where- knot = Generics.M1 . knot+ knot = Generics.M1 . knot+ -- | @since 0.4.1.0 instance (Inply f, Inply g) => Inply (f Generics.:*: g) where- gather f g (x1 Generics.:*: y1) (x2 Generics.:*: y2) =- gather f g x1 x2 Generics.:*: gather f g y1 y2+ gather f g (x1 Generics.:*: y1) (x2 Generics.:*: y2) =+ gather f g x1 x2 Generics.:*: gather f g y1 y2+ -- | @since 0.4.1.0 instance (Inplicative f, Inplicative g) => Inplicative (f Generics.:*: g) where- knot x = knot x Generics.:*: knot x+ knot x = knot x Generics.:*: knot x+ -- | @since 0.4.1.0 instance (Inply f, Inply g) => Inply (Product f g) where- gather f g (Pair x1 y1) (Pair x2 y2) =- gather f g x1 x2 `Pair` gather f g y1 y2+ gather f g (Pair x1 y1) (Pair x2 y2) =+ gather f g x1 x2 `Pair` gather f g y1 y2+ -- | @since 0.4.1.0 instance (Inplicative f, Inplicative g) => Inplicative (Product f g) where- knot x = knot x `Pair` knot x+ knot x = knot x `Pair` knot x+ -- | @since 0.4.1.0 instance Inply f => Inply (Generics.Rec1 f :: Type -> Type) where- gather f g (Generics.Rec1 x) (Generics.Rec1 y) = Generics.Rec1 (gather f g x y)+ gather f g (Generics.Rec1 x) (Generics.Rec1 y) = Generics.Rec1 (gather f g x y)+ -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Generics.Rec1 f :: Type -> Type) where- knot = Generics.Rec1 . knot+ knot = Generics.Rec1 . knot+ -- | @since 0.4.1.0 instance Inply f => Inply (Monoid.Alt f) where- gather f g (Monoid.Alt x) (Monoid.Alt y) = Monoid.Alt (gather f g x y)+ gather f g (Monoid.Alt x) (Monoid.Alt y) = Monoid.Alt (gather f g x y)+ -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Monoid.Alt f) where- knot = Monoid.Alt . knot+ knot = Monoid.Alt . knot+ -- | @since 0.4.1.0 instance Inply f => Inply (IdentityT f :: Type -> Type) where- gather f g (IdentityT x) (IdentityT y) = IdentityT (gather f g x y)+ gather f g (IdentityT x) (IdentityT y) = IdentityT (gather f g x y)+ -- | @since 0.4.1.0 instance Inplicative f => Inplicative (IdentityT f :: Type -> Type) where- knot = IdentityT . knot+ knot = IdentityT . knot+ -- | @since 0.4.1.0 instance Inply f => Inply (Reverse f :: Type -> Type) where- gather f g (Reverse x) (Reverse y) = Reverse (gather f g x y)+ gather f g (Reverse x) (Reverse y) = Reverse (gather f g x y)+ -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Reverse f :: Type -> Type) where- knot = Reverse . knot+ knot = Reverse . knot+ -- | @since 0.4.1.0 instance Inply f => Inply (Backwards f :: Type -> Type) where- gather f g (Backwards x) (Backwards y) = Backwards (gather f g x y)+ gather f g (Backwards x) (Backwards y) = Backwards (gather f g x y)+ -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Backwards f :: Type -> Type) where- knot = Backwards . knot+ knot = Backwards . knot+ -- | @since 0.4.1.0 instance Inply f => Inply (Lift f) where- gather f g = \case- Pure x -> \case- Pure y -> Pure (f x y)- Other y -> Other (invmap (f x) (snd . g) y)- Other x -> \case- Pure y -> Other (invmap (`f` y) (fst . g) x)- Other y -> Other (gather f g x y)+ gather f g = \case+ Pure x -> \case+ Pure y -> Pure (f x y)+ Other y -> Other (invmap (f x) (snd . g) y)+ Other x -> \case+ Pure y -> Other (invmap (`f` y) (fst . g) x)+ Other y -> Other (gather f g x y)+ -- | @since 0.4.1.0 instance Inply f => Inplicative (Lift f) where- knot = Pure+ knot = Pure -- | @since 0.4.1.0 deriving via WrappedApplicativeOnly (Tagged a) instance Inply (Tagged a)+ -- | @since 0.4.1.0 deriving via WrappedApplicativeOnly (Tagged a) instance Inplicative (Tagged a) -- | @since 0.4.1.0 deriving via WrappedFunctor Identity instance Inply Identity+ -- | @since 0.4.1.0 deriving via WrappedFunctor Identity instance Inplicative Identity+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Proxy :: Type -> Type) instance Inply Proxy+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Proxy :: Type -> Type) instance Inplicative Proxy+ -- | @since 0.4.1.0 deriving via WrappedFunctor [] instance Inply []+ -- | @since 0.4.1.0 deriving via WrappedFunctor [] instance Inplicative []+ -- | @since 0.4.1.0 deriving via WrappedFunctor ((->) r) instance Inply ((->) r)+ -- | @since 0.4.1.0 deriving via WrappedFunctor ((->) r) instance Inplicative ((->) r)+ -- | @since 0.4.1.0 deriving via WrappedFunctor Maybe instance Inply Maybe+ -- | @since 0.4.1.0 deriving via WrappedFunctor Maybe instance Inplicative Maybe+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Either e) instance Inply (Either e)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Either e) instance Inplicative (Either e)+ -- | @since 0.4.1.0 deriving via WrappedFunctor IO instance Inply IO+ -- | @since 0.4.1.0 deriving via WrappedFunctor IO instance Inplicative IO+ -- | @since 0.4.1.0 deriving via WrappedFunctor Generics.Par1 instance Inply Generics.Par1+ -- | @since 0.4.1.0 deriving via WrappedFunctor Generics.Par1 instance Inplicative Generics.Par1+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.U1 :: Type -> Type) instance Inply Generics.U1+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.U1 :: Type -> Type) instance Inplicative Generics.U1+ -- | @since 0.4.1.0-deriving via WrappedFunctor (Generics.K1 i c :: Type -> Type) instance Semigroup c => Inply (Generics.K1 i c)+deriving via+ WrappedFunctor (Generics.K1 i c :: Type -> Type)+ instance+ Semigroup c => Inply (Generics.K1 i c)+ -- | @since 0.4.1.0-deriving via WrappedFunctor (Generics.K1 i c :: Type -> Type) instance Monoid c => Inplicative (Generics.K1 i c)+deriving via+ WrappedFunctor (Generics.K1 i c :: Type -> Type)+ instance+ Monoid c => Inplicative (Generics.K1 i c)+ -- | @since 0.4.1.0 deriving via WrappedFunctor Complex instance Inply Complex+ -- | @since 0.4.1.0 deriving via WrappedFunctor Complex instance Inplicative Complex+ -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Min instance Inply Semigroup.Min+ -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Min instance Inplicative Semigroup.Min+ -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Max instance Inply Semigroup.Max+ -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Max instance Inplicative Semigroup.Max+ -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.First instance Inply Semigroup.First+ -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.First instance Inplicative Semigroup.First+ -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Last instance Inply Semigroup.Last+ -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Last instance Inplicative Semigroup.Last @@ -478,50 +582,73 @@ -- | @since 0.4.1.0 deriving via WrappedFunctor ZipList instance Inply ZipList+ -- | @since 0.4.1.0 deriving via WrappedFunctor ZipList instance Inplicative ZipList+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.First instance Inply Monoid.First+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.First instance Inplicative Monoid.First+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Last instance Inply Monoid.Last+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Last instance Inplicative Monoid.Last+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Dual instance Inply Monoid.Dual+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Dual instance Inplicative Monoid.Dual+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Sum instance Inply Monoid.Sum+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Sum instance Inplicative Monoid.Sum+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Product instance Inply Monoid.Product+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Product instance Inplicative Monoid.Product+ -- | @since 0.4.1.0 deriving via WrappedFunctor NonEmpty instance Inply NonEmpty+ -- | @since 0.4.1.0 deriving via WrappedFunctor NonEmpty instance Inplicative NonEmpty+ -- | @since 0.4.1.0 deriving via WrappedFunctor Tree instance Inply Tree+ -- | @since 0.4.1.0 deriving via WrappedFunctor Tree instance Inplicative Tree+ -- | @since 0.4.1.0 deriving via WrappedFunctor Seq instance Inply Seq+ -- | @since 0.4.1.0 deriving via WrappedFunctor Seq instance Inplicative Seq+ -- | @since 0.4.1.0 deriving via WrappedFunctor NESeq.NESeq instance Inply NESeq.NESeq+ -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedArrow a b) instance Arrow a => Inply (WrappedArrow a b)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedArrow a b) instance Arrow a => Inplicative (WrappedArrow a b)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.V1 :: Type -> Type) instance Inply Generics.V1+ -- | @since 0.4.1.0 deriving via WrappedFunctor IM.IntMap instance Inply IM.IntMap+ -- | @since 0.4.1.0 deriving via WrappedFunctor (M.Map k) instance Ord k => Inply (M.Map k) @@ -537,49 +664,67 @@ -- | @since 0.4.1.0 deriving via WrappedFunctor (Const w :: Type -> Type) instance Semigroup w => Inply (Const w)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Const w :: Type -> Type) instance Monoid w => Inplicative (Const w)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Constant w :: Type -> Type) instance Semigroup w => Inply (Constant w)+ -- | @since 0.4.1.0-deriving via WrappedFunctor (Constant w :: Type -> Type) instance Monoid w => Inplicative (Constant w)+deriving via+ WrappedFunctor (Constant w :: Type -> Type)+ instance+ Monoid w => Inplicative (Constant w)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (ContT r (m :: Type -> Type)) instance Inply (ContT r m)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (ContT r (m :: Type -> Type)) instance Inplicative (ContT r m)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedMonad m) instance Monad m => Inply (WrappedMonad m)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedMonad m) instance Monad m => Inplicative (WrappedMonad m)+ -- | @since 0.4.1.0 deriving via WrappedFunctor ((,) w :: Type -> Type) instance Semigroup w => Inply ((,) w)+ -- | @since 0.4.1.0 deriving via WrappedFunctor ((,) w :: Type -> Type) instance Monoid w => Inplicative ((,) w) -- | @since 0.4.1.0 deriving via WrappedDivisible SettableStateVar instance Inply SettableStateVar+ -- | @since 0.4.1.0 deriving via WrappedDivisible SettableStateVar instance Inplicative SettableStateVar+ -- | @since 0.4.1.0 deriving via WrappedDivisible Predicate instance Inply Predicate+ -- | @since 0.4.1.0 deriving via WrappedDivisible Predicate instance Inplicative Predicate+ -- | @since 0.4.1.0 deriving via WrappedDivisible Comparison instance Inply Comparison+ -- | @since 0.4.1.0 deriving via WrappedDivisible Comparison instance Inplicative Comparison+ -- | @since 0.4.1.0 deriving via WrappedDivisible Equivalence instance Inply Equivalence+ -- | @since 0.4.1.0 deriving via WrappedDivisible Equivalence instance Inplicative Equivalence+ -- | @since 0.4.1.0 deriving via WrappedDivisible (Op r) instance Semigroup r => Inply (Op r)+ -- | @since 0.4.1.0 deriving via WrappedDivisible (Op r) instance Monoid r => Inplicative (Op r) --- -- | Convenient wrapper to build up an 'Inplicative' instance by providing -- each component of it. This makes it much easier to build up longer -- chains because you would only need to write the splitting/joining@@ -614,13 +759,14 @@ -- otherwise you'd need to manually peel off tuples one-by-one. -- -- @since 0.4.1.0-gatheredN- :: Inplicative f- => NP f as- -> f (NP I as)+gatheredN ::+ Inplicative f =>+ NP f as ->+ f (NP I as) gatheredN = \case- Nil -> knot Nil- x :* xs -> gather+ Nil -> knot Nil+ x :* xs ->+ gather (\y ys -> I y :* ys) (\case I y :* ys -> (y, ys)) x@@ -654,25 +800,26 @@ -- See notes on 'gatheredNMap' for more details and caveats. -- -- @since 0.4.1.0-gatheredNMap- :: Inplicative f- => (NP I as -> b)- -> (b -> NP I as)- -> NP f as- -> f b+gatheredNMap ::+ Inplicative f =>+ (NP I as -> b) ->+ (b -> NP I as) ->+ NP f as ->+ f b gatheredNMap f g = invmap f g . gatheredN -- | A version of 'gatheredN' for non-empty 'NP', but only -- requiring an 'Inply' instance. -- -- @since 0.4.1.0-gatheredN1- :: Inply f- => NP f (a ': as)- -> f (NP I (a ': as))+gatheredN1 ::+ Inply f =>+ NP f (a ': as) ->+ f (NP I (a ': as)) gatheredN1 (x :* xs) = case xs of- Nil -> invmap ((:* Nil) . I) (\case I y :* _ -> y) x- _ :* _ -> gather+ Nil -> invmap ((:* Nil) . I) (\case I y :* _ -> y) x+ _ :* _ ->+ gather (\y ys -> I y :* ys) (\case I y :* ys -> (y, ys)) x@@ -682,12 +829,12 @@ -- requiring an 'Inply' instance. -- -- @since 0.4.1.0-gatheredN1Map- :: Inplicative f- => (NP I (a ': as) -> b)- -> (b -> NP I (a ': as))- -> NP f (a ': as)- -> f b+gatheredN1Map ::+ Inplicative f =>+ (NP I (a ': as) -> b) ->+ (b -> NP I (a ': as)) ->+ NP f (a ': as) ->+ f b gatheredN1Map f g = invmap f g . gatheredN1 -- | A version of 'gatheredN' using 'V.XRec' from /vinyl/ instead of@@ -695,13 +842,14 @@ -- require manual unwrapping/wrapping of tuple components. -- -- @since 0.4.1.0-gatheredNRec- :: Inplicative f- => V.Rec f as- -> f (V.XRec V.Identity as)+gatheredNRec ::+ Inplicative f =>+ V.Rec f as ->+ f (V.XRec V.Identity as) gatheredNRec = \case- V.RNil -> knot V.RNil- x V.:& xs -> gather+ V.RNil -> knot V.RNil+ x V.:& xs ->+ gather (V.::&) (\case y V.::& ys -> (y, ys)) x@@ -712,12 +860,12 @@ -- require manual unwrapping/wrapping of tuple components. -- -- @since 0.4.1.0-gatheredNMapRec- :: Inplicative f- => (V.XRec V.Identity as -> b)- -> (b -> V.XRec V.Identity as)- -> V.Rec f as- -> f b+gatheredNMapRec ::+ Inplicative f =>+ (V.XRec V.Identity as -> b) ->+ (b -> V.XRec V.Identity as) ->+ V.Rec f as ->+ f b gatheredNMapRec f g = invmap f g . gatheredNRec -- | Convenient wrapper to 'gather' over multiple arguments using tine@@ -763,27 +911,30 @@ -- @ -- -- @since 0.4.1.0-gatherN- :: forall f as b. (Inplicative f, V.IsoXRec V.Identity as, V.RecordCurry as)- => V.Curried as b- -> (b -> V.XRec V.Identity as)- -> V.CurriedF f as (f b)-gatherN f g = V.rcurry @as @f $+gatherN ::+ forall f as b.+ (Inplicative f, V.IsoXRec V.Identity as, V.RecordCurry as) =>+ V.Curried as b ->+ (b -> V.XRec V.Identity as) ->+ V.CurriedF f as (f b)+gatherN f g =+ V.rcurry @as @f $ invmap (V.runcurry' f . V.fromXRec) g- . gatheredNRec+ . gatheredNRec -- | A version of 'gatheredN1' using 'V.XRec' from /vinyl/ instead of -- 'NP' from /sop-core/. This can be more convenient because it doesn't -- require manual unwrapping/wrapping of components. -- -- @since 0.4.1.0-gatheredN1Rec- :: Inply f- => V.Rec f (a ': as)- -> f (V.XRec V.Identity (a ': as))+gatheredN1Rec ::+ Inply f =>+ V.Rec f (a ': as) ->+ f (V.XRec V.Identity (a ': as)) gatheredN1Rec (x V.:& xs) = case xs of- V.RNil -> invmap (V.::& V.RNil) (\case z V.::& _ -> z) x- _ V.:& _ -> gather+ V.RNil -> invmap (V.::& V.RNil) (\case z V.::& _ -> z) x+ _ V.:& _ ->+ gather (V.::&) (\case y V.::& ys -> (y, ys)) x@@ -794,26 +945,28 @@ -- require manual unwrapping/wrapping of tuple components. -- -- @since 0.4.1.0-gatheredN1MapRec- :: Inplicative f- => (V.XRec V.Identity (a ': as) -> b)- -> (b -> V.XRec V.Identity (a ': as))- -> V.Rec f (a ': as)- -> f b+gatheredN1MapRec ::+ Inplicative f =>+ (V.XRec V.Identity (a ': as) -> b) ->+ (b -> V.XRec V.Identity (a ': as)) ->+ V.Rec f (a ': as) ->+ f b gatheredN1MapRec f g = invmap f g . gatheredN1Rec -- | 'gatherN' but with at least one argument, so can be used with any -- 'Inply'. -- -- @since 0.4.1.0-gatherN1- :: forall f a as b. (Inply f, V.IsoXRec V.Identity as, V.RecordCurry as)- => V.Curried (a ': as) b- -> (b -> V.XRec V.Identity (a ': as))- -> V.CurriedF f (a ': as) (f b)-gatherN1 f g = V.rcurry @(a ': as) @f $+gatherN1 ::+ forall f a as b.+ (Inply f, V.IsoXRec V.Identity as, V.RecordCurry as) =>+ V.Curried (a ': as) b ->+ (b -> V.XRec V.Identity (a ': as)) ->+ V.CurriedF f (a ': as) (f b)+gatherN1 f g =+ V.rcurry @(a ': as) @f $ invmap (V.runcurry' f . V.fromXRec) g- . gatheredN1Rec+ . gatheredN1Rec -- | Interpret out of a contravariant 'Day' into any instance of 'Apply' by -- providing two interpreting functions.@@ -823,11 +976,12 @@ -- instance of 'Inply'. However, this can be handy if you are using an -- instance of 'Apply' that has no 'Inply' instance. Consider also -- 'unsafeInplyCo' if you are using a specific, concrete type for @h@.-runDayApply- :: forall f g h. Apply h- => f ~> h- -> g ~> h- -> Day f g ~> h+runDayApply ::+ forall f g h.+ Apply h =>+ f ~> h ->+ g ~> h ->+ Day f g ~> h runDayApply f g (Day x y j _) = liftF2 j (f x) (g y) -- | Interpret out of a contravariant 'Day' into any instance of 'Divise'@@ -838,10 +992,10 @@ -- instance of 'Inply'. However, this can be handy if you are using an -- instance of 'Divise' that has no 'Inply' instance. Consider also -- 'unsafeInplyContra' if you are using a specific, concrete type for @h@.-runDayDivise- :: forall f g h. Divise h- => f ~> h- -> g ~> h- -> Day f g ~> h+runDayDivise ::+ forall f g h.+ Divise h =>+ f ~> h ->+ g ~> h ->+ Day f g ~> h runDayDivise f g (Day x y _ h) = divise h (f x) (g y)-
src/Data/Functor/Invariant/Inplicative/Free.hs view
@@ -1,8 +1,9 @@+{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- | -- Module : Data.Functor.Invariant.Inplicative.Free--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -17,47 +18,50 @@ -- @since 0.4.0.0 module Data.Functor.Invariant.Inplicative.Free ( -- * Chain- DivAp(.., Gather, Knot)- , runCoDivAp- , runContraDivAp- , divApAp- , divApDiv- , foldDivAp- , assembleDivAp- , assembleDivApRec+ DivAp (.., Gather, Knot),+ runCoDivAp,+ runContraDivAp,+ divApAp,+ divApDiv,+ foldDivAp,+ assembleDivAp,+ assembleDivApRec,+ -- * Nonempty Chain- , DivAp1(.., DivAp1)- , runCoDivAp1- , runContraDivAp1- , divApAp1- , divApDiv1- , foldDivAp1- , assembleDivAp1- , assembleDivAp1Rec- ) where+ DivAp1 (.., DivAp1),+ runCoDivAp1,+ runContraDivAp1,+ divApAp1,+ divApDiv1,+ foldDivAp1,+ assembleDivAp1,+ assembleDivAp1Rec,+) where -import Control.Applicative-import Control.Applicative.Free (Ap(..))-import Control.Applicative.ListF (MaybeF(..))-import Control.Natural-import Data.Coerce-import Data.Functor.Apply-import Data.Functor.Apply.Free (Ap1(..))-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Contravariant.Divisible.Free (Div(..), Div1)-import Data.Functor.Identity-import Data.Functor.Invariant-import Data.Functor.Invariant.Day-import Data.Functor.Invariant.Inplicative-import Data.HBifunctor.Tensor hiding (elim1, elim2, intro1, intro2)-import Data.HFunctor-import Data.HFunctor.Chain-import Data.HFunctor.Chain.Internal-import Data.HFunctor.Interpret-import Data.SOP hiding (hmap)-import qualified Data.Vinyl as V-import qualified Data.Vinyl.Functor as V+#if !MIN_VERSION_base(4,17,0)+import Control.Applicative (liftA2)+#endif+import Control.Applicative.Free (Ap (..))+import Control.Applicative.ListF (MaybeF (..))+import Control.Natural+import Data.Coerce+import Data.Functor.Apply+import Data.Functor.Apply.Free (Ap1 (..))+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Contravariant.Divisible.Free (Div (..), Div1)+import Data.Functor.Identity+import Data.Functor.Invariant+import Data.Functor.Invariant.Day+import Data.Functor.Invariant.Inplicative+import Data.HBifunctor.Tensor hiding (elim1, elim2, intro1, intro2)+import Data.HFunctor+import Data.HFunctor.Chain+import Data.HFunctor.Chain.Internal+import Data.HFunctor.Interpret+import Data.SOP hiding (hmap)+import qualified Data.Vinyl as V+import qualified Data.Vinyl.Functor as V -- | In the covariant direction, we can interpret into any 'Apply'. --@@ -66,10 +70,11 @@ -- of 'Inply'. However, this can be handy if you are using an instance of -- 'Apply' that has no 'Inply' instance. Consider also 'unsafeInplyCo' if -- you are using a specific, concrete type for @g@.-runCoDivAp1- :: forall f g. Apply g- => f ~> g- -> DivAp1 f ~> g+runCoDivAp1 ::+ forall f g.+ Apply g =>+ f ~> g ->+ DivAp1 f ~> g runCoDivAp1 f = foldDivAp1 f (runDayApply f id) -- | In the contravariant direction, we can interpret into any 'Divise'.@@ -79,10 +84,11 @@ -- of 'Inply'. However, this can be handy if you are using an instance of -- 'Divise' that has no 'Inply' instance. Consider also -- 'unsafeInplyContra' if you are using a specific, concrete type for @g@.-runContraDivAp1- :: forall f g. Divise g- => f ~> g- -> DivAp1 f ~> g+runContraDivAp1 ::+ forall f g.+ Divise g =>+ f ~> g ->+ DivAp1 f ~> g runContraDivAp1 f = foldDivAp1 f (runDayDivise f id) -- | In the covariant direction, we can interpret into any 'Applicative'.@@ -93,10 +99,11 @@ -- an instance of 'Applicative' that has no 'Inplicative' instance. -- Consider also 'unsafeInplicativeCo' if you are using a specific, -- concrete type for @g@.-runCoDivAp- :: forall f g. Applicative g- => f ~> g- -> DivAp f ~> g+runCoDivAp ::+ forall f g.+ Applicative g =>+ f ~> g ->+ DivAp f ~> g runCoDivAp f = foldDivAp pure (\case Day x y h _ -> liftA2 h (f x) y) -- | In the covariant direction, we can interpret into any 'Divisible'.@@ -107,10 +114,11 @@ -- an instance of 'Divisible' that has no 'Inplicative' instance. Consider -- also 'unsafeInplicativeContra' if you are using a specific, concrete -- type for @g@.-runContraDivAp- :: forall f g. Divisible g- => f ~> g- -> DivAp f ~> g+runContraDivAp ::+ forall f g.+ Divisible g =>+ f ~> g ->+ DivAp f ~> g runContraDivAp f = foldDivAp (const conquer) (\case Day x y _ g -> divide g (f x) y) -- | General-purpose folder of 'DivAp'. Provide a way to handle the@@ -118,26 +126,22 @@ -- ('liftA2'/'divide'/'Gather'). -- -- @since 0.3.5.0-foldDivAp- :: (forall x. x -> g x)- -> (Day f g ~> g)- -> DivAp f ~> g+foldDivAp ::+ (forall x. x -> g x) ->+ (Day f g ~> g) ->+ DivAp f ~> g foldDivAp f g = foldChain (f . runIdentity) g . unDivAp -- | General-purpose folder of 'DivAp1'. Provide a way to handle the -- individual leaves and a way to handle a cons ('liftF2/'divise'/'Gather'). -- -- @since 0.3.5.0-foldDivAp1- :: (f ~> g)- -> (Day f g ~> g)- -> DivAp1 f ~> g+foldDivAp1 ::+ (f ~> g) ->+ (Day f g ~> g) ->+ DivAp1 f ~> g foldDivAp1 f g = foldChain1 f g . unDivAp1 ---- -- | Extract the 'Ap' part out of a 'DivAp', shedding the -- contravariant bits. --@@ -173,27 +177,28 @@ -- Note that the order of the first two arguments has swapped as of -- v0.4.0.0 pattern Gather :: (b -> c -> a) -> (a -> (b, c)) -> f b -> DivAp f c -> DivAp f a-pattern Gather f g x xs <- (unGather_->MaybeF (Just (Day x xs f g)))+pattern Gather f g x xs <- (unGather_ -> MaybeF (Just (Day x xs f g))) where Gather f g x xs = DivAp $ More $ Day x (unDivAp xs) f g unGather_ :: DivAp f ~> MaybeF (Day f (DivAp f)) unGather_ = \case DivAp (More (Day x xs g f)) -> MaybeF . Just $ Day x (DivAp xs) g f- DivAp (Done _ ) -> MaybeF Nothing+ DivAp (Done _) -> MaybeF Nothing -- | Match on an "empty" 'DivAp'; contains no @f@s, but only the -- terminal value. Analogous to 'Control.Applicative.Free.Pure'. pattern Knot :: a -> DivAp f a pattern Knot x = DivAp (Done (Identity x))+ {-# COMPLETE Gather, Knot #-} instance Inply (DivAp f) where- gather = coerce (gather @(Chain Day Identity _))+ gather = coerce (gather @(Chain Day Identity _)) -- | The free 'Inplicative' instance Inplicative (DivAp f) where- knot = coerce (knot @(Chain Day Identity _))+ knot = coerce (knot @(Chain Day Identity _)) -- | Match on a 'DivAp1' to get the head and the rest of the items. -- Analogous to the 'Data.Functor.Apply.Free.Ap1' constructor.@@ -201,14 +206,15 @@ -- Note that the order of the first two arguments has swapped as of -- v0.4.0.0 pattern DivAp1 :: Invariant f => (b -> c -> a) -> (a -> (b, c)) -> f b -> DivAp f c -> DivAp1 f a-pattern DivAp1 f g x xs <- (coerce splitChain1->Day x xs f g)+pattern DivAp1 f g x xs <- (coerce splitChain1 -> Day x xs f g) where DivAp1 f g x xs = unsplitNE $ Day x xs f g+ {-# COMPLETE DivAp1 #-} -- | The free 'Inplicative' instance Invariant f => Inply (DivAp1 f) where- gather = coerce (gather @(Chain1 Day _))+ gather = coerce (gather @(Chain1 Day _)) -- | Convenient wrapper to build up a 'DivAp' by providing each -- component of it. This makes it much easier to build up longer chains@@ -244,16 +250,19 @@ -- -- If each component is itself a @'DivAp' f@ (instead of @f@), you can use -- 'concatInplicative'.-assembleDivAp- :: NP f as- -> DivAp f (NP I as)+assembleDivAp ::+ NP f as ->+ DivAp f (NP I as) assembleDivAp = \case- Nil -> DivAp $ Done $ Identity Nil- x :* xs -> DivAp $ More $ Day- x- (unDivAp (assembleDivAp xs))- (\y ys -> I y :* ys)- (\case I y :* ys -> (y, ys))+ Nil -> DivAp $ Done $ Identity Nil+ x :* xs ->+ DivAp $+ More $+ Day+ x+ (unDivAp (assembleDivAp xs))+ (\y ys -> I y :* ys)+ (\case I y :* ys -> (y, ys)) -- | A version of 'assembleDivAp' but for 'DivAp1' instead. Can be -- useful if you intend on interpreting it into something with only@@ -261,17 +270,19 @@ -- -- If each component is itself a @'DivAp1' f@ (instead of @f@), you can use -- 'concatInply'.-assembleDivAp1- :: Invariant f- => NP f (a ': as)- -> DivAp1 f (NP I (a ': as))+assembleDivAp1 ::+ Invariant f =>+ NP f (a ': as) ->+ DivAp1 f (NP I (a ': as)) assembleDivAp1 (x :* xs) = DivAp1_ $ case xs of- Nil -> Done1 $ invmap ((:* Nil) . I) (unI . hd) x- _ :* _ -> More1 $ Day- x- (unDivAp1 (assembleDivAp1 xs))- (\y ys -> I y :* ys)- (\case I y :* ys -> (y, ys))+ Nil -> Done1 $ invmap ((:* Nil) . I) (unI . hd) x+ _ :* _ ->+ More1 $+ Day+ x+ (unDivAp1 (assembleDivAp1 xs))+ (\y ys -> I y :* ys)+ (\case I y :* ys -> (y, ys)) -- | A version of 'assembleDivAp' using 'V.XRec' from /vinyl/ instead of -- 'NP' from /sop-core/. This can be more convenient because it doesn't@@ -290,16 +301,19 @@ -- -- If each component is itself a @'DivAp' f@ (instead of @f@), you can use -- 'concatDivApRec'.-assembleDivApRec- :: V.Rec f as- -> DivAp f (V.XRec V.Identity as)+assembleDivApRec ::+ V.Rec f as ->+ DivAp f (V.XRec V.Identity as) assembleDivApRec = \case- V.RNil -> DivAp $ Done $ Identity V.RNil- x V.:& xs -> DivAp $ More $ Day- x- (unDivAp (assembleDivApRec xs))- (V.::&)- unconsRec+ V.RNil -> DivAp $ Done $ Identity V.RNil+ x V.:& xs ->+ DivAp $+ More $+ Day+ x+ (unDivAp (assembleDivApRec xs))+ (V.::&)+ unconsRec -- | A version of 'assembleDivAp1' using 'V.XRec' from /vinyl/ instead of -- 'NP' from /sop-core/. This can be more convenient because it doesn't@@ -307,25 +321,28 @@ -- -- If each component is itself a @'DivAp1' f@ (instead of @f@), you can use -- 'concatDivAp1Rec'.-assembleDivAp1Rec- :: Invariant f- => V.Rec f (a ': as)- -> DivAp1 f (V.XRec V.Identity (a ': as))+assembleDivAp1Rec ::+ Invariant f =>+ V.Rec f (a ': as) ->+ DivAp1 f (V.XRec V.Identity (a ': as)) assembleDivAp1Rec (x V.:& xs) = case xs of- V.RNil -> DivAp1_ $ Done1 $ invmap (V.::& V.RNil) (\case z V.::& _ -> z) x- _ V.:& _ -> DivAp1_ $ More1 $ Day- x- (unDivAp1 (assembleDivAp1Rec xs))- (V.::&)- unconsRec+ V.RNil -> DivAp1_ $ Done1 $ invmap (V.::& V.RNil) (\case z V.::& _ -> z) x+ _ V.:& _ ->+ DivAp1_ $+ More1 $+ Day+ x+ (unDivAp1 (assembleDivAp1Rec xs))+ (V.::&)+ unconsRec unconsRec :: V.XRec V.Identity (a ': as) -> (a, V.XRec V.Identity as) unconsRec (y V.::& ys) = (y, ys) -- | A free 'Inply' instance Inply f => Interpret DivAp1 f where- interpret f (DivAp1_ x) = foldChain1 f (runDay f id) x+ interpret f (DivAp1_ x) = foldChain1 f (runDay f id) x -- | A free 'Inplicative' instance Inplicative f => Interpret DivAp f where- interpret f (DivAp x) = foldChain (knot . runIdentity) (runDay f id) x+ interpret f (DivAp x) = foldChain (knot . runIdentity) (runDay f id) x
src/Data/Functor/Invariant/Internative.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE CPP #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE DerivingVia #-} -- |@@ -17,48 +17,49 @@ -- @since 0.4.0.0 module Data.Functor.Invariant.Internative ( -- * Typeclass- Inalt(..)- , Inplus(..)- , Internative+ Inalt (..),+ Inplus (..),+ Internative,+ -- * Assembling Helpers- , swervedN- , swervedNMap- , swervedN1- , swervedN1Map- ) where+ swervedN,+ swervedNMap,+ swervedN1,+ swervedN1Map,+) where -import Control.Applicative-import Control.Applicative.Backwards (Backwards(..))-import Control.Arrow (ArrowPlus)-import Control.Monad-import Control.Monad.Trans.Identity (IdentityT(..))-import Data.Functor.Alt-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Invariant-import Data.Functor.Invariant.Inplicative-import Data.Functor.Plus-import Data.Functor.Product (Product(..))-import Data.Functor.Reverse (Reverse(..))-import Data.Hashable (Hashable)-import Data.Kind-import Data.List.NonEmpty (NonEmpty)-import Data.SOP hiding (hmap)-import Data.Sequence (Seq)-import Data.StateVar (SettableStateVar)-import Data.Void-import qualified Data.HashMap.Lazy as HM-import qualified Data.IntMap as IM-import qualified Data.IntMap.NonEmpty as NEIM-import qualified Data.Map as M-import qualified Data.Map.NonEmpty as NEM-import qualified Data.Monoid as Monoid-import qualified Data.Semigroup as Semigroup-import qualified Data.Sequence.NonEmpty as NESeq-import qualified GHC.Generics as Generics+import Control.Applicative+import Control.Applicative.Backwards (Backwards (..))+import Control.Arrow (ArrowPlus)+import Control.Monad+import Control.Monad.Trans.Identity (IdentityT (..))+import Data.Functor.Alt+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Invariant+import Data.Functor.Invariant.Inplicative+import Data.Functor.Plus+import Data.Functor.Product (Product (..))+import Data.Functor.Reverse (Reverse (..))+import qualified Data.HashMap.Lazy as HM+import Data.Hashable (Hashable)+import qualified Data.IntMap as IM+import qualified Data.IntMap.NonEmpty as NEIM+import Data.Kind+import Data.List.NonEmpty (NonEmpty)+import qualified Data.Map as M+import qualified Data.Map.NonEmpty as NEM+import qualified Data.Monoid as Monoid+import Data.SOP hiding (hmap)+import qualified Data.Semigroup as Semigroup+import Data.Sequence (Seq)+import qualified Data.Sequence.NonEmpty as NESeq+import Data.StateVar (SettableStateVar)+import Data.Void+import qualified GHC.Generics as Generics -- | The invariant counterpart of 'Alt' and 'Decide'. --@@ -81,43 +82,45 @@ -- -- @since 0.4.0.0 class Invariant f => Inalt f where- -- | Like '<!>', 'decide', or 'choose', but requires both- -- an injecting and a choosing function.- --- -- It is used to merge @f b@ (producer and consumer of @b@) and @f c@- -- (producer and consumer of @c@) into a @f a@ in an either-or manner.- -- You can think of it as, for the @f a@, it "chooses" if the @a@ is- -- actually a @b@ or a @c@ with the @a -> 'Either' b c@, feeds it to- -- either the original @f b@ or the original @f c@, and then re-injects- -- the output back into a @a@ with the @b -> a@ or the @c -> a@.- --- -- An important property is that it will only ever use exactly @one@ of- -- the options given in order to fulfil its job. If you swerve an @f- -- a@ and an @f b@ into an @f c@, in order to consume/produdce the @c@,- -- it will only use either the @f a@ or the @f b@ -- exactly one of- -- them.- --- -- @since 0.4.0.0- swerve- :: (b -> a)- -> (c -> a)- -> (a -> Either b c)- -> f b- -> f c- -> f a- swerve f g h x y = invmap (either f g) h (swerved x y)- -- | A simplified version of 'swerive' that splits to and from an- -- 'Either'. You can then use 'invmap' to reshape it into the proper- -- shape.- --- -- @since 0.4.0.0- swerved- :: f a- -> f b- -> f (Either a b)- swerved = swerve Left Right id- {-# MINIMAL swerve | swerved #-}+ -- | Like '<!>', 'decide', or 'choose', but requires both+ -- an injecting and a choosing function.+ --+ -- It is used to merge @f b@ (producer and consumer of @b@) and @f c@+ -- (producer and consumer of @c@) into a @f a@ in an either-or manner.+ -- You can think of it as, for the @f a@, it "chooses" if the @a@ is+ -- actually a @b@ or a @c@ with the @a -> 'Either' b c@, feeds it to+ -- either the original @f b@ or the original @f c@, and then re-injects+ -- the output back into a @a@ with the @b -> a@ or the @c -> a@.+ --+ -- An important property is that it will only ever use exactly @one@ of+ -- the options given in order to fulfil its job. If you swerve an @f+ -- a@ and an @f b@ into an @f c@, in order to consume/produdce the @c@,+ -- it will only use either the @f a@ or the @f b@ -- exactly one of+ -- them.+ --+ -- @since 0.4.0.0+ swerve ::+ (b -> a) ->+ (c -> a) ->+ (a -> Either b c) ->+ f b ->+ f c ->+ f a+ swerve f g h x y = invmap (either f g) h (swerved x y) + -- | A simplified version of 'swerive' that splits to and from an+ -- 'Either'. You can then use 'invmap' to reshape it into the proper+ -- shape.+ --+ -- @since 0.4.0.0+ swerved ::+ f a ->+ f b ->+ f (Either a b)+ swerved = swerve Left Right id++ {-# MINIMAL swerve | swerved #-}+ -- | The invariant counterpart of 'Alt' and 'Conclude'. -- -- The main important action is described in 'Inalt', but this adds 'reject',@@ -131,7 +134,7 @@ -- @since 0.4.0.0 class Inalt f => Inplus f where- reject :: (a -> Void) -> f a+ reject :: (a -> Void) -> f a -- | The invariant counterpart to 'Alternative' and 'Decidable': represents -- a combination of both 'Applicative' and 'Alt', or 'Divisible' and@@ -142,138 +145,176 @@ -- | Ignores the contravariant part of 'swerve' instance Alt f => Inalt (WrappedFunctor f) where- swerved (WrapFunctor x) (WrapFunctor y) = WrapFunctor $- (Left <$> x) <!> (Right <$> y)+ swerved (WrapFunctor x) (WrapFunctor y) =+ WrapFunctor $+ (Left <$> x) <!> (Right <$> y)+ -- | @'reject' _ = 'zero'@ instance Plus f => Inplus (WrappedFunctor f) where- reject _ = WrapFunctor zero+ reject _ = WrapFunctor zero+ instance (Alternative f, Plus f, Apply f) => Internative (WrappedFunctor f) -- | Ignores the covariant part of 'gather' instance Decide f => Inalt (WrappedContravariant f) where- swerve _ _ h (WrapContravariant x) (WrapContravariant y) = WrapContravariant (decide h x y)+ swerve _ _ h (WrapContravariant x) (WrapContravariant y) = WrapContravariant (decide h x y)+ -- | @'reject' = 'conclude'@ instance Conclude f => Inplus (WrappedContravariant f) where- reject f = WrapContravariant (conclude f)+ reject f = WrapContravariant (conclude f)+ instance (Conclude f, Divisible f, Divise f) => Internative (WrappedContravariant f) -- | Ignores the covariant part of 'gather' instance Decide f => Inalt (WrappedDivisible f) where- swerve _ _ h (WrapDivisible x) (WrapDivisible y) = WrapDivisible (decide h x y)+ swerve _ _ h (WrapDivisible x) (WrapDivisible y) = WrapDivisible (decide h x y)+ -- | @'reject' = 'conclude'@ instance Conclude f => Inplus (WrappedDivisible f) where- reject f = WrapDivisible (conclude f)+ reject f = WrapDivisible (conclude f)+ instance (Conclude f, Divisible f, Divise f) => Internative (WrappedDivisible f) -- | Ignores the covariant part of 'gather' instance (Decidable f, Invariant f) => Inalt (WrappedDivisibleOnly f) where- swerve _ _ h (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (choose h x y)+ swerve _ _ h (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (choose h x y)+ -- | @'reject' = 'lose'@ instance (Decidable f, Invariant f) => Inplus (WrappedDivisibleOnly f) where- reject f = WrapDivisibleOnly (lose f)+ reject f = WrapDivisibleOnly (lose f)+ instance (Decidable f, Invariant f) => Internative (WrappedDivisibleOnly f) -- | @since 0.4.1.0 deriving via WrappedFunctor (Proxy :: Type -> Type) instance Inalt Proxy+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Proxy :: Type -> Type) instance Inplus Proxy+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Proxy :: Type -> Type) instance Internative Proxy+ -- | @since 0.4.1.0 deriving via WrappedFunctor [] instance Inalt []+ -- | @since 0.4.1.0 deriving via WrappedFunctor [] instance Inplus []+ -- | @since 0.4.1.0 deriving via WrappedFunctor [] instance Internative []+ -- | @since 0.4.1.0 deriving via WrappedFunctor Maybe instance Inalt Maybe+ -- | @since 0.4.1.0 deriving via WrappedFunctor Maybe instance Inplus Maybe+ -- | @since 0.4.1.0 deriving via WrappedFunctor Maybe instance Internative Maybe+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Either e) instance Inalt (Either e)+ -- | @since 0.4.1.0 deriving via WrappedFunctor IO instance Inalt IO+ -- | @since 0.4.1.0 deriving via WrappedFunctor IO instance Inplus IO+ -- | @since 0.4.1.0 deriving via WrappedFunctor IO instance Internative IO -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.U1 :: Type -> Type) instance Inalt Generics.U1+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.U1 :: Type -> Type) instance Inplus Generics.U1+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.U1 :: Type -> Type) instance Internative Generics.U1 -- | @since 0.4.1.0 instance Inalt f => Inalt (Generics.M1 i t f) where- swerve f g h (Generics.M1 x) (Generics.M1 y) = Generics.M1 (swerve f g h x y)+ swerve f g h (Generics.M1 x) (Generics.M1 y) = Generics.M1 (swerve f g h x y)+ -- | @since 0.4.1.0 instance Inplus f => Inplus (Generics.M1 i t f) where- reject = Generics.M1 . reject+ reject = Generics.M1 . reject+ -- | @since 0.4.1.0 instance Internative f => Internative (Generics.M1 i t f) -- | @since 0.4.1.0 instance (Inalt f, Inalt g) => Inalt (f Generics.:*: g) where- swerve f g h (x1 Generics.:*: y1) (x2 Generics.:*: y2) =- swerve f g h x1 x2 Generics.:*: swerve f g h y1 y2+ swerve f g h (x1 Generics.:*: y1) (x2 Generics.:*: y2) =+ swerve f g h x1 x2 Generics.:*: swerve f g h y1 y2+ -- | @since 0.4.1.0 instance (Inplus f, Inplus g) => Inplus (f Generics.:*: g) where- reject f = reject f Generics.:*: reject f+ reject f = reject f Generics.:*: reject f+ -- | @since 0.4.1.0 instance (Internative f, Internative g) => Internative (f Generics.:*: g) -- | @since 0.4.1.0 instance (Inalt f, Inalt g) => Inalt (Product f g) where- swerve f g h (Pair x1 y1) (Pair x2 y2) =- swerve f g h x1 x2 `Pair` swerve f g h y1 y2+ swerve f g h (Pair x1 y1) (Pair x2 y2) =+ swerve f g h x1 x2 `Pair` swerve f g h y1 y2+ -- | @since 0.4.1.0 instance (Inplus f, Inplus g) => Inplus (Product f g) where- reject f = reject f `Pair` reject f+ reject f = reject f `Pair` reject f+ -- | @since 0.4.1.0 instance (Internative f, Internative g) => Internative (Product f g) -- | @since 0.4.1.0 instance Inalt f => Inalt (Generics.Rec1 f) where- swerve f g h (Generics.Rec1 x) (Generics.Rec1 y) = Generics.Rec1 (swerve f g h x y)+ swerve f g h (Generics.Rec1 x) (Generics.Rec1 y) = Generics.Rec1 (swerve f g h x y)+ -- | @since 0.4.1.0 instance Inplus f => Inplus (Generics.Rec1 f) where- reject = Generics.Rec1 . reject+ reject = Generics.Rec1 . reject+ -- | @since 0.4.1.0 instance Internative f => Internative (Generics.Rec1 f) -- | @since 0.4.1.0 instance Inalt f => Inalt (IdentityT f) where- swerve f g h (IdentityT x) (IdentityT y) = IdentityT (swerve f g h x y)+ swerve f g h (IdentityT x) (IdentityT y) = IdentityT (swerve f g h x y)+ -- | @since 0.4.1.0 instance Inplus f => Inplus (IdentityT f) where- reject = IdentityT . reject+ reject = IdentityT . reject+ -- | @since 0.4.1.0-instance Internative f => Internative (IdentityT f) where+instance Internative f => Internative (IdentityT f) -- | @since 0.4.1.0 instance Inalt f => Inalt (Reverse f) where- swerve f g h (Reverse x) (Reverse y) = Reverse (swerve f g h x y)+ swerve f g h (Reverse x) (Reverse y) = Reverse (swerve f g h x y)+ -- | @since 0.4.1.0 instance Inplus f => Inplus (Reverse f) where- reject = Reverse . reject+ reject = Reverse . reject+ -- | @since 0.4.1.0-instance Internative f => Internative (Reverse f) where+instance Internative f => Internative (Reverse f) -- | @since 0.4.1.0 instance Inalt f => Inalt (Backwards f) where- swerve f g h (Backwards x) (Backwards y) = Backwards (swerve f g h x y)+ swerve f g h (Backwards x) (Backwards y) = Backwards (swerve f g h x y)+ -- | @since 0.4.1.0 instance Inplus f => Inplus (Backwards f) where- reject = Backwards . reject+ reject = Backwards . reject+ -- | @since 0.4.1.0-instance Internative f => Internative (Backwards f) where+instance Internative f => Internative (Backwards f) -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.First instance Inalt Semigroup.First+ -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Last instance Inalt Semigroup.Last @@ -288,40 +329,61 @@ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.First instance Inalt Monoid.First+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.First instance Inplus Monoid.First+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.First instance Internative Monoid.First+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Last instance Inalt Monoid.Last+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Last instance Inplus Monoid.Last+ -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Last instance Internative Monoid.Last+ -- | @since 0.4.1.0 deriving via WrappedFunctor NonEmpty instance Inalt NonEmpty+ -- | @since 0.4.1.0 deriving via WrappedFunctor Seq instance Inalt Seq+ -- | @since 0.4.1.0 deriving via WrappedFunctor Seq instance Inplus Seq+ -- | @since 0.4.1.0 deriving via WrappedFunctor Seq instance Internative Seq+ -- | @since 0.4.1.0 deriving via WrappedFunctor NESeq.NESeq instance Inalt NESeq.NESeq+ -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedArrow a b) instance ArrowPlus a => Inalt (WrappedArrow a b)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedArrow a b) instance ArrowPlus a => Inplus (WrappedArrow a b)+ -- | @since 0.4.1.0-deriving via WrappedFunctor (WrappedArrow a b) instance ArrowPlus a => Internative (WrappedArrow a b)+deriving via+ WrappedFunctor (WrappedArrow a b)+ instance+ ArrowPlus a => Internative (WrappedArrow a b)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.V1 :: Type -> Type) instance Inalt Generics.V1+ -- | @since 0.4.1.0 deriving via WrappedFunctor IM.IntMap instance Inalt IM.IntMap+ -- | @since 0.4.1.0 deriving via WrappedFunctor NEIM.NEIntMap instance Inalt NEIM.NEIntMap+ -- | @since 0.4.1.0 deriving via WrappedFunctor (M.Map k) instance Ord k => Inalt (M.Map k)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (NEM.NEMap k) instance Ord k => Inalt (NEM.NEMap k) @@ -336,44 +398,58 @@ -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedMonad m) instance MonadPlus m => Inalt (WrappedMonad m)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedMonad m) instance MonadPlus m => Inplus (WrappedMonad m)+ -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedMonad m) instance MonadPlus m => Internative (WrappedMonad m) -- | @since 0.4.1.0 deriving via WrappedDivisible SettableStateVar instance Inalt SettableStateVar+ -- | @since 0.4.1.0 deriving via WrappedDivisible SettableStateVar instance Inplus SettableStateVar+ -- | @since 0.4.1.0 deriving via WrappedDivisible SettableStateVar instance Internative SettableStateVar+ -- | @since 0.4.1.0 deriving via WrappedDivisible Predicate instance Inalt Predicate+ -- | @since 0.4.1.0 deriving via WrappedDivisible Predicate instance Inplus Predicate+ -- | @since 0.4.1.0 deriving via WrappedDivisible Predicate instance Internative Predicate+ -- | @since 0.4.1.0 deriving via WrappedDivisible Comparison instance Inalt Comparison+ -- | @since 0.4.1.0 deriving via WrappedDivisible Comparison instance Inplus Comparison+ -- | @since 0.4.1.0 deriving via WrappedDivisible Comparison instance Internative Comparison+ -- | @since 0.4.1.0 deriving via WrappedDivisible Equivalence instance Inalt Equivalence+ -- | @since 0.4.1.0 deriving via WrappedDivisible Equivalence instance Inplus Equivalence+ -- | @since 0.4.1.0 deriving via WrappedDivisible Equivalence instance Internative Equivalence+ -- | @since 0.4.1.0 deriving via WrappedDivisible (Op r) instance Inalt (Op r)+ -- | @since 0.4.1.0 deriving via WrappedDivisible (Op r) instance Inplus (Op r)+ -- | @since 0.4.1.0 deriving via WrappedDivisible (Op r) instance Monoid r => Internative (Op r) -- -- | Convenient wrapper to build up an 'Inplus' instance on by providing -- each branch of it. This makes it much easier to build up longer chains -- because you would only need to write the splitting/joining functions in@@ -408,13 +484,14 @@ -- otherwise you'd need to manually peel off eithers one-by-one. -- -- @since 0.4.1.0-swervedN- :: Inplus f- => NP f as- -> f (NS I as)+swervedN ::+ Inplus f =>+ NP f as ->+ f (NS I as) swervedN = \case- Nil -> reject $ \case {}- x :* xs -> swerve+ Nil -> reject $ \case {}+ x :* xs ->+ swerve (Z . I) S (\case Z (I y) -> Left y; S ys -> Right ys)@@ -457,25 +534,26 @@ -- See notes on 'swervedNMap' for more details and caveats. -- -- @since 0.4.1.0-swervedNMap- :: Inplus f- => (NS I as -> b)- -> (b -> NS I as)- -> NP f as- -> f b+swervedNMap ::+ Inplus f =>+ (NS I as -> b) ->+ (b -> NS I as) ->+ NP f as ->+ f b swervedNMap f g = invmap f g . swervedN -- | A version of 'swervedN' for non-empty 'NP', but only -- requiring an 'Inalt' instance. -- -- @since 0.4.1.0-swervedN1- :: Inalt f- => NP f (a ': as)- -> f (NS I (a ': as))+swervedN1 ::+ Inalt f =>+ NP f (a ': as) ->+ f (NS I (a ': as)) swervedN1 (x :* xs) = case xs of- Nil -> invmap (Z . I) (\case Z (I y) -> y; S ys -> case ys of {}) x- _ :* _ -> swerve+ Nil -> invmap (Z . I) (\case Z (I y) -> y; S ys -> case ys of {}) x+ _ :* _ ->+ swerve (Z . I) S (\case Z (I y) -> Left y; S ys -> Right ys)@@ -486,11 +564,10 @@ -- requiring an 'Inalt' instance. -- -- @since 0.4.1.0-swervedN1Map- :: Inalt f- => (NS I (a ': as) -> b)- -> (b -> NS I (a ': as))- -> NP f (a ': as)- -> f b+swervedN1Map ::+ Inalt f =>+ (NS I (a ': as) -> b) ->+ (b -> NS I (a ': as)) ->+ NP f (a ': as) ->+ f b swervedN1Map f g = invmap f g . swervedN1-
src/Data/Functor/Invariant/Internative/Free.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Data.Functor.Invariant.Internative.Free--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -17,46 +17,46 @@ -- @since 0.4.0.0 module Data.Functor.Invariant.Internative.Free ( -- * Chain- DecAlt(.., Swerve, Reject)- , runCoDecAlt- , runContraDecAlt- , decAltListF- , decAltListF_- , decAltDec- , foldDecAlt- , assembleDecAlt- -- * Nonempty Chain- , DecAlt1(.., DecAlt1)- , runCoDecAlt1- , runContraDecAlt1- , decAltNonEmptyF- , decAltNonEmptyF_- , decAltDec1- , foldDecAlt1- , assembleDecAlt1- ) where+ DecAlt (.., Swerve, Reject),+ runCoDecAlt,+ runContraDecAlt,+ decAltListF,+ decAltListF_,+ decAltDec,+ foldDecAlt,+ assembleDecAlt, -import Control.Applicative.ListF-import Control.Natural-import Data.Coerce-import Data.Functor.Alt-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divisible.Free-import Data.Functor.Invariant-import Data.Functor.Invariant.Internative-import Data.Functor.Invariant.Night-import Data.Functor.Plus-import Data.HBifunctor.Tensor hiding (elim1, elim2, intro1, intro2)-import Data.HFunctor-import Data.HFunctor.Chain-import Data.HFunctor.Chain.Internal-import Data.SOP hiding (hmap)-import Data.Void-import qualified Control.Monad.Trans.Compose as CT-import qualified Data.Functor.Coyoneda as CY-import qualified Data.List.NonEmpty as NE+ -- * Nonempty Chain+ DecAlt1 (.., DecAlt1),+ runCoDecAlt1,+ runContraDecAlt1,+ decAltNonEmptyF,+ decAltNonEmptyF_,+ decAltDec1,+ foldDecAlt1,+ assembleDecAlt1,+) where +import Control.Applicative.ListF+import qualified Control.Monad.Trans.Compose as CT+import Control.Natural+import Data.Coerce+import Data.Functor.Alt+import Data.Functor.Contravariant.Conclude+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divisible.Free+import qualified Data.Functor.Coyoneda as CY+import Data.Functor.Invariant+import Data.Functor.Invariant.Internative+import Data.Functor.Invariant.Night+import Data.Functor.Plus+import Data.HBifunctor.Tensor hiding (elim1, elim2, intro1, intro2)+import Data.HFunctor+import Data.HFunctor.Chain+import Data.HFunctor.Chain.Internal+import qualified Data.List.NonEmpty as NE+import Data.SOP hiding (hmap)+import Data.Void -- | In the covariant direction, we can interpret into any 'Alt'. --@@ -65,10 +65,11 @@ -- of 'Inalt'. However, this can be handy if you are using an instance of -- 'Alt' that has no 'Inalt' instance. Consider also 'unsafeInaltCo' if -- you are using a specific, concrete type for @g@.-runCoDecAlt1- :: forall f g. Alt g- => f ~> g- -> DecAlt1 f ~> g+runCoDecAlt1 ::+ forall f g.+ Alt g =>+ f ~> g ->+ DecAlt1 f ~> g runCoDecAlt1 f = foldDecAlt1 f (runNightAlt f id) -- | In the contravariant direction, we can interpret into any 'Decide'.@@ -78,10 +79,11 @@ -- of 'Inalt'. However, this can be handy if you are using an instance of -- 'Decide' that has no 'Inalt' instance. Consider also -- 'unsafeInaltContra' if you are using a specific, concrete type for @g@.-runContraDecAlt1- :: forall f g. Decide g- => f ~> g- -> DecAlt1 f ~> g+runContraDecAlt1 ::+ forall f g.+ Decide g =>+ f ~> g ->+ DecAlt1 f ~> g runContraDecAlt1 f = foldDecAlt1 f (runNightDecide f id) -- | Extract the 'Dec' part out of a 'DecAlt', shedding the@@ -101,10 +103,11 @@ -- of 'Inplus'. However, this can be handy if you are using an instance of -- 'Plus' that has no 'Inplus' instance. Consider also 'unsafeInplusCo' if -- you are using a specific, concrete type for @g@.-runCoDecAlt- :: forall f g. Plus g- => f ~> g- -> DecAlt f ~> g+runCoDecAlt ::+ forall f g.+ Plus g =>+ f ~> g ->+ DecAlt f ~> g runCoDecAlt f = foldDecAlt (const zero) (runNightAlt f id) -- | In the contravariant direction, we can interpret into any 'Decide'.@@ -114,10 +117,11 @@ -- instance of 'Inplus'. However, this can be handy if you are using an -- instance of 'Conclude' that has no 'Inplus' instance. Consider also -- 'unsafeInplusContra' if you are using a specific, concrete type for @g@.-runContraDecAlt- :: forall f g. Conclude g- => f ~> g- -> DecAlt f ~> g+runContraDecAlt ::+ forall f g.+ Conclude g =>+ f ~> g ->+ DecAlt f ~> g runContraDecAlt f = foldDecAlt conclude (runNightDecide f id) -- | Extract the 'ListF' part out of a 'DecAlt', shedding the@@ -137,7 +141,8 @@ -- @since 0.3.2.0 decAltListF_ :: DecAlt f ~> CT.ComposeT ListF CY.Coyoneda f decAltListF_ = foldDecAlt (const (CT.ComposeT (ListF []))) $ \case- Night x (CT.ComposeT (ListF xs)) f g _ -> CT.ComposeT . ListF $+ Night x (CT.ComposeT (ListF xs)) f g _ ->+ CT.ComposeT . ListF $ CY.Coyoneda f x : (map . fmap) g xs -- | Extract the 'NonEmptyF' part out of a 'DecAlt1', shedding the@@ -157,7 +162,8 @@ -- @since 0.3.2.0 decAltNonEmptyF_ :: DecAlt1 f ~> CT.ComposeT NonEmptyF CY.Coyoneda f decAltNonEmptyF_ = foldDecAlt1 inject $ \case- Night x (CT.ComposeT (NonEmptyF xs)) f g _ -> CT.ComposeT . NonEmptyF $+ Night x (CT.ComposeT (NonEmptyF xs)) f g _ ->+ CT.ComposeT . NonEmptyF $ CY.Coyoneda f x NE.<| (fmap . fmap) g xs -- | General-purpose folder of 'DecAlt'. Provide a way to handle the@@ -165,20 +171,20 @@ -- ('<!>'/'decide'/'swerve'). -- -- @since 0.3.5.0-foldDecAlt- :: (forall x. (x -> Void) -> g x)- -> (Night f g ~> g)- -> DecAlt f ~> g+foldDecAlt ::+ (forall x. (x -> Void) -> g x) ->+ (Night f g ~> g) ->+ DecAlt f ~> g foldDecAlt f g = foldChain (f . refute) g . unDecAlt -- | General-purpose folder of 'DecAlt1'. Provide a way to handle the -- individual leaves and a way to handle a cons ('<!>'/'decide'/'swerve'). -- -- @since 0.3.5.0-foldDecAlt1- :: (f ~> g)- -> (Night f g ~> g)- -> DecAlt1 f ~> g+foldDecAlt1 ::+ (f ~> g) ->+ (Night f g ~> g) ->+ DecAlt1 f ~> g foldDecAlt1 f g = foldChain1 f g . unDecAlt1 -- | Match on a non-empty 'DecAlt'; contains the splitting function,@@ -186,40 +192,42 @@ -- Analogous to the 'Data.Functor.Contravariant.Divisible.Free.Choose' -- constructor. pattern Swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> f b -> DecAlt f c -> DecAlt f a-pattern Swerve f g h x xs <- (unSwerve_->MaybeF (Just (Night x xs f g h)))+pattern Swerve f g h x xs <- (unSwerve_ -> MaybeF (Just (Night x xs f g h))) where Swerve f g h x xs = DecAlt $ More $ Night x (unDecAlt xs) f g h unSwerve_ :: DecAlt f ~> MaybeF (Night f (DecAlt f)) unSwerve_ = \case DecAlt (More (Night x xs g f h)) -> MaybeF . Just $ Night x (DecAlt xs) g f h- DecAlt (Done _ ) -> MaybeF Nothing-+ DecAlt (Done _) -> MaybeF Nothing -- | Match on an "empty" 'DecAlt'; contains no @f@s, but only the -- terminal value. Analogous to the -- 'Data.Functor.Contravariant.Divisible.Free.Lose' constructor. pattern Reject :: (a -> Void) -> DecAlt f a pattern Reject x = DecAlt (Done (Not x))+ {-# COMPLETE Swerve, Reject #-} instance Inalt (DecAlt f) where- swerve = coerce (swerve @(Chain Night Not _))+ swerve = coerce (swerve @(Chain Night Not _)) instance Inplus (DecAlt f) where- reject = coerce (reject @(Chain Night Not _))+ reject = coerce (reject @(Chain Night Not _)) -- | Match on a 'DecAlt1' to get the head and the rest of the items. -- Analogous to the 'Data.Functor.Contravariant.Divisible.Free.Dec1' -- constructor.-pattern DecAlt1 :: Invariant f => (b -> a) -> (c -> a) -> (a -> Either b c) -> f b -> DecAlt f c -> DecAlt1 f a-pattern DecAlt1 f g h x xs <- (coerce splitChain1->Night x xs f g h)+pattern DecAlt1 ::+ Invariant f => (b -> a) -> (c -> a) -> (a -> Either b c) -> f b -> DecAlt f c -> DecAlt1 f a+pattern DecAlt1 f g h x xs <- (coerce splitChain1 -> Night x xs f g h) where DecAlt1 f g h x xs = unsplitNE $ Night x xs f g h+ {-# COMPLETE DecAlt1 #-} instance Invariant f => Inalt (DecAlt1 f) where- swerve = coerce (swerve @(Chain1 Night _))+ swerve = coerce (swerve @(Chain1 Night _)) -- | Convenient wrapper to build up a 'DecAlt' on by providing each -- branch of it. This makes it much easier to build up longer chains@@ -255,17 +263,20 @@ -- -- If each component is itself a @'DecAlt' f@ (instead of @f@), you can use -- 'concatInplus'.-assembleDecAlt- :: NP f as- -> DecAlt f (NS I as)+assembleDecAlt ::+ NP f as ->+ DecAlt f (NS I as) assembleDecAlt = \case- Nil -> DecAlt $ Done $ Not (\case {})- x :* xs -> DecAlt $ More $ Night- x- (unDecAlt $ assembleDecAlt xs)- (Z . I)- S- (\case Z (I y) -> Left y; S ys -> Right ys)+ Nil -> DecAlt $ Done $ Not (\case {})+ x :* xs ->+ DecAlt $+ More $+ Night+ x+ (unDecAlt $ assembleDecAlt xs)+ (Z . I)+ S+ (\case Z (I y) -> Left y; S ys -> Right ys) -- | A version of 'assembleDecAlt' but for 'DecAlt1' instead. Can -- be useful if you intend on interpreting it into something with only@@ -275,15 +286,17 @@ -- -- If each component is itself a @'DecAlt1' f@ (instead of @f@), you can -- use 'concatInalt'.-assembleDecAlt1- :: Invariant f- => NP f (a ': as)- -> DecAlt1 f (NS I (a ': as))+assembleDecAlt1 ::+ Invariant f =>+ NP f (a ': as) ->+ DecAlt1 f (NS I (a ': as)) assembleDecAlt1 (x :* xs) = DecAlt1_ $ case xs of- Nil -> Done1 $ invmap (Z . I) (unI . unZ) x- _ :* _ -> More1 $ Night- x- (unDecAlt1 $ assembleDecAlt1 xs)- (Z . I)- S- (\case Z (I y) -> Left y; S ys -> Right ys)+ Nil -> Done1 $ invmap (Z . I) (unI . unZ) x+ _ :* _ ->+ More1 $+ Night+ x+ (unDecAlt1 $ assembleDecAlt1 xs)+ (Z . I)+ S+ (\case Z (I y) -> Left y; S ys -> Right ys)
src/Data/Functor/Invariant/Night.hs view
@@ -1,7 +1,6 @@- -- | -- Module : Data.Functor.Invariant.Night--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -12,37 +11,42 @@ -- -- @since 0.3.0.0 module Data.Functor.Invariant.Night (- Night(..)- , Not(..), refuted- , night- , runNight- , nerve- , runNightAlt- , runNightDecide- , toCoNight- , toCoNight_- , toContraNight- , assoc, unassoc- , intro1, intro2- , elim1, elim2- , swapped- , trans1, trans2- ) where+ Night (..),+ Not (..),+ refuted,+ night,+ runNight,+ nerve,+ runNightAlt,+ runNightDecide,+ toCoNight,+ toCoNight_,+ toContraNight,+ assoc,+ unassoc,+ intro1,+ intro2,+ elim1,+ elim2,+ swapped,+ trans1,+ trans2,+) where -import Control.Natural-import Data.Bifunctor-import Data.Functor.Alt-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Night (Not(..), refuted)-import Data.Functor.Invariant-import Data.Functor.Invariant.Internative-import Data.Kind-import Data.Void-import GHC.Generics-import qualified Data.Bifunctor.Assoc as B-import qualified Data.Bifunctor.Swap as B-import qualified Data.Functor.Contravariant.Night as CN-import qualified Data.Functor.Coyoneda as CY+import Control.Natural+import Data.Bifunctor+import qualified Data.Bifunctor.Assoc as B+import qualified Data.Bifunctor.Swap as B+import Data.Functor.Alt+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Night (Not (..), refuted)+import qualified Data.Functor.Contravariant.Night as CN+import qualified Data.Functor.Coyoneda as CY+import Data.Functor.Invariant+import Data.Functor.Invariant.Internative+import Data.Kind+import Data.Void+import GHC.Generics -- | A pairing of invariant functors to create a new invariant functor that -- represents the "choice" between the two.@@ -64,15 +68,16 @@ -- about in Haskell (which uses @(,)@). Therefore, it is an alternative to -- the typical 'Data.Functor.Day' convolution --- hence, the name 'Night'. data Night :: (Type -> Type) -> (Type -> Type) -> (Type -> Type) where- Night :: f b- -> g c- -> (b -> a)- -> (c -> a)- -> (a -> Either b c)- -> Night f g a+ Night ::+ f b ->+ g c ->+ (b -> a) ->+ (c -> a) ->+ (a -> Either b c) ->+ Night f g a instance Invariant (Night f g) where- invmap f g (Night x y h j k) = Night x y (f . h) (f . j) (k . g)+ invmap f g (Night x y h j k) = Night x y (f . h) (f . j) (k . g) -- | Pair two invariant actions together into a 'Night'; assigns the first -- one to 'Left' inputs and outputs and the second one to 'Right' inputs@@ -83,21 +88,23 @@ -- | Interpret the covariant part of a 'Night' into a target context @h@, -- as long as the context is an instance of 'Alt'. The 'Alt' is used to -- combine results back together, chosen by '<!>'.-runNightAlt- :: forall f g h. Alt h- => f ~> h- -> g ~> h- -> Night f g ~> h+runNightAlt ::+ forall f g h.+ Alt h =>+ f ~> h ->+ g ~> h ->+ Night f g ~> h runNightAlt f g (Night x y h j _) = fmap h (f x) <!> fmap j (g y) -- | Interpret the contravariant part of a 'Night' into a target context -- @h@, as long as the context is an instance of 'Decide'. The 'Decide' is -- used to pick which part to feed the input to.-runNightDecide- :: forall f g h. Decide h- => f ~> h- -> g ~> h- -> Night f g ~> h+runNightDecide ::+ forall f g h.+ Decide h =>+ f ~> h ->+ g ~> h ->+ Night f g ~> h runNightDecide f g (Night x y _ _ k) = decide k (f x) (g y) -- | Convert an invariant 'Night' into the covariant version, dropping the@@ -120,7 +127,6 @@ toCoNight_ :: Night f g ~> CY.Coyoneda f :*: CY.Coyoneda g toCoNight_ (Night x y f g _) = CY.Coyoneda f x :*: CY.Coyoneda g y - -- | Convert an invariant 'Night' into the contravariant version, dropping -- the covariant part. toContraNight :: Night f g ~> CN.Night f g@@ -130,40 +136,45 @@ -- two interpreting functions. -- -- @since 0.4.0.0-runNight- :: Inalt h- => (f ~> h)- -> (g ~> h)- -> Night f g ~> h+runNight ::+ Inalt h =>+ (f ~> h) ->+ (g ~> h) ->+ Night f g ~> h runNight f g (Night x y a b c) = swerve a b c (f x) (g y) -- | Squash the two items in a 'Night' using their natural 'Inalt' -- instances. -- -- @since 0.4.0.0-nerve- :: Inalt f- => Night f f ~> f+nerve ::+ Inalt f =>+ Night f f ~> f nerve (Night x y a b c) = swerve a b c x y -- | 'Night' is associative. assoc :: Night f (Night g h) ~> Night (Night f g) h assoc (Night x (Night y z f g h) j k l) =- Night (Night x y Left Right id) z- (either j (k . f))- (k . g)- (B.unassoc . second h . l)+ Night+ (Night x y Left Right id)+ z+ (either j (k . f))+ (k . g)+ (B.unassoc . second h . l) -- | 'Night' is associative. unassoc :: Night (Night f g) h ~> Night f (Night g h) unassoc (Night (Night x y f g h) z j k l) =- Night x (Night y z Left Right id)- (j . f)- (either (j . g) k)- (B.assoc . first h . l)- -- (k . g)- -- (either (k . h) l)+ Night+ x+ (Night y z Left Right id)+ (j . f)+ (either (j . g) k)+ (B.assoc . first h . l) +-- (k . g)+-- (either (k . h) l)+ -- | The left identity of 'Night' is 'Not'; this is one side of that -- isomorphism. intro1 :: g ~> Night Not g@@ -195,4 +206,3 @@ -- | Hoist a function over the right side of a 'Night'. trans2 :: g ~> h -> Night f g ~> Night f h trans2 f (Night x y g h j) = Night x (f y) g h j-
src/Data/HBifunctor.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Data.HBifunctor--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -12,46 +12,48 @@ -- This module provides an abstraction for "two-argument functor -- combinators", 'HBifunctor', as well as some useful combinators. module Data.HBifunctor (- HBifunctor(..)- , WrappedHBifunctor(..)- , overHBifunctor+ HBifunctor (..),+ WrappedHBifunctor (..),+ overHBifunctor,+ -- * Simple Instances- , LeftF(..)- , RightF(..)- ) where+ LeftF (..),+ RightF (..),+) where -import Control.Natural.IsoF-import Data.Biapplicative-import Data.Bifunctor.TH-import Data.Coerce-import Data.Data-import Data.Deriving-import Data.HFunctor-import Data.HFunctor.HTraversable-import Data.HFunctor.Internal-import Data.HFunctor.Interpret-import GHC.Generics+import Control.Natural.IsoF+import Data.Biapplicative+import Data.Bifunctor.TH+import Data.Coerce+import Data.Data+import Data.Deriving+import Data.HFunctor+import Data.HFunctor.HTraversable+import Data.HFunctor.Internal+import Data.HFunctor.Interpret+import GHC.Generics -- | Lift two isomorphisms on each side of a bifunctor to become an -- isomorphism between the two bifunctor applications. -- -- Basically, if @f@ and @f'@ are isomorphic, and @g@ and @g'@ are -- isomorphic, then @t f g@ is isomorphic to @t f' g'@.-overHBifunctor- :: HBifunctor t- => (f <~> f')- -> (g <~> g')- -> t f g <~> t f' g'+overHBifunctor ::+ HBifunctor t =>+ (f <~> f') ->+ (g <~> g') ->+ t f g <~> t f' g' overHBifunctor f g =- isoF (hbimap (viewF f) (viewF g))- (hbimap (reviewF f) (reviewF g))+ isoF+ (hbimap (viewF f) (viewF g))+ (hbimap (reviewF f) (reviewF g)) -- | An 'HBifunctor' that ignores its second input. Like -- a 'GHC.Generics.:+:' with no 'GHC.Generics.R1'/right branch. -- -- This is 'Data.Bifunctors.Joker.Joker' from "Data.Bifunctors.Joker", but -- given a more sensible name for its purpose.-newtype LeftF f g a = LeftF { runLeftF :: f a }+newtype LeftF f g a = LeftF {runLeftF :: f a} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''LeftF@@ -63,24 +65,24 @@ deriveBitraversable ''LeftF instance Applicative f => Biapplicative (LeftF f) where- bipure _ y = LeftF (pure y)- LeftF x <<*>> LeftF y = LeftF (x <*> y)+ bipure _ y = LeftF (pure y)+ LeftF x <<*>> LeftF y = LeftF (x <*> y) instance HBifunctor LeftF where- hbimap f _ (LeftF x) = LeftF (f x)+ hbimap f _ (LeftF x) = LeftF (f x) instance HFunctor (LeftF f) where- hmap _ = coerce+ hmap _ = coerce instance HTraversable (LeftF f) where- htraverse _ = pure . coerce+ htraverse _ = pure . coerce -- | An 'HBifunctor' that ignores its first input. Like -- a 'GHC.Generics.:+:' with no 'GHC.Generics.L1'/left branch. -- -- In its polykinded form (on @f@), it is essentially a higher-order -- version of 'Data.Tagged.Tagged'.-newtype RightF f g a = RightF { runRightF :: g a }+newtype RightF f g a = RightF {runRightF :: g a} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''RightF@@ -89,20 +91,20 @@ deriveOrd1 ''RightF instance HBifunctor RightF where- hbimap _ g (RightF x) = RightF (g x)+ hbimap _ g (RightF x) = RightF (g x) instance HFunctor (RightF g) where- hmap f (RightF x) = RightF (f x)+ hmap f (RightF x) = RightF (f x) instance Inject (RightF g) where- inject = RightF+ inject = RightF instance HTraversable (RightF g) where- htraverse f (RightF x) = RightF <$> f x+ htraverse f (RightF x) = RightF <$> f x instance HBind (RightF g) where- hbind f (RightF x) = f x+ hbind f (RightF x) = f x instance Interpret (RightF g) f where- retract (RightF x) = x- interpret f (RightF x) = f x+ retract (RightF x) = x+ interpret f (RightF x) = f x
src/Data/HBifunctor/Associative.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Data.HBifunctor.Associative--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -34,71 +34,73 @@ -- and moving in and out of them. module Data.HBifunctor.Associative ( -- * 'Associative'- Associative(..)- , assoc- , disassoc+ Associative (..),+ assoc,+ disassoc,+ -- * 'SemigroupIn'- , SemigroupIn(..)- , matchingNE- , retractNE- , interpretNE+ SemigroupIn (..),+ matchingNE,+ retractNE,+ interpretNE,+ -- ** Utility- , biget- , biapply- , (!*!)- , (!$!)- , (!+!)- , WrapHBF(..)- , WrapNE(..)- ) where+ biget,+ biapply,+ (!*!),+ (!$!),+ (!+!),+ WrapHBF (..),+ WrapNE (..),+) where -import Control.Applicative.ListF-import Control.Applicative.Step-import Control.Monad.Freer.Church-import Control.Monad.Trans.Compose-import Control.Monad.Trans.Identity-import Control.Natural-import Control.Natural.IsoF-import Data.Bifunctor-import Data.Bifunctor.Joker-import Data.Coerce-import Data.Constraint.Trivial-import Data.Data-import Data.Foldable-import Data.Functor.Apply.Free-import Data.Functor.Bind-import Data.Functor.Classes-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible.Free-import Data.Functor.Contravariant.Night (Night(..))-import Data.Functor.Day (Day(..))-import Data.Functor.Identity-import Data.Functor.Invariant-import Data.Functor.Invariant.Inplicative-import Data.Functor.Invariant.Internative-import Data.Functor.Plus-import Data.Functor.Product-import Data.Functor.Sum-import Data.Functor.These-import Data.HBifunctor-import Data.HFunctor-import Data.HFunctor.Chain.Internal-import Data.HFunctor.Internal-import Data.HFunctor.Interpret-import Data.Kind-import Data.List.NonEmpty (NonEmpty(..))-import Data.Void-import GHC.Generics-import qualified Data.Bifunctor.Assoc as B-import qualified Data.Functor.Contravariant.Coyoneda as CCY-import qualified Data.Functor.Contravariant.Day as CD-import qualified Data.Functor.Contravariant.Night as N-import qualified Data.Functor.Day as D-import qualified Data.Functor.Invariant.Day as ID-import qualified Data.Functor.Invariant.Night as IN-import qualified Data.Map.NonEmpty as NEM+import Control.Applicative.ListF+import Control.Applicative.Step+import Control.Monad.Freer.Church+import Control.Monad.Trans.Compose+import Control.Monad.Trans.Identity+import Control.Natural+import Control.Natural.IsoF+import Data.Bifunctor+import qualified Data.Bifunctor.Assoc as B+import Data.Bifunctor.Joker+import Data.Coerce+import Data.Constraint.Trivial+import Data.Data+import Data.Foldable+import Data.Functor.Apply.Free+import Data.Functor.Bind+import Data.Functor.Classes+import Data.Functor.Contravariant+import qualified Data.Functor.Contravariant.Coyoneda as CCY+import qualified Data.Functor.Contravariant.Day as CD+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible.Free+import Data.Functor.Contravariant.Night (Night (..))+import qualified Data.Functor.Contravariant.Night as N+import Data.Functor.Day (Day (..))+import qualified Data.Functor.Day as D+import Data.Functor.Identity+import Data.Functor.Invariant+import qualified Data.Functor.Invariant.Day as ID+import Data.Functor.Invariant.Inplicative+import Data.Functor.Invariant.Internative+import qualified Data.Functor.Invariant.Night as IN+import Data.Functor.Plus+import Data.Functor.Product+import Data.Functor.Sum+import Data.Functor.These+import Data.HBifunctor+import Data.HFunctor+import Data.HFunctor.Chain.Internal+import Data.HFunctor.Internal+import Data.HFunctor.Interpret+import Data.Kind+import Data.List.NonEmpty (NonEmpty (..))+import qualified Data.Map.NonEmpty as NEM+import Data.Void+import GHC.Generics -- | An 'HBifunctor' where it doesn't matter which binds first is -- 'Associative'. Knowing this gives us a lot of power to rearrange the@@ -119,85 +121,86 @@ -- Different instances of @t@ each enrich the endofunctor category in -- different ways, giving a different semigroupoidal category. class (HBifunctor t, Inject (NonEmptyBy t)) => Associative t where- -- | The "semigroup functor combinator" generated by @t@.- --- -- A value of type @NonEmptyBy t f a@ is /equivalent/ to one of:- --- -- * @f a@- -- * @t f f a@- -- * @t f (t f f) a@- -- * @t f (t f (t f f)) a@- -- * @t f (t f (t f (t f f))) a@- -- * .. etc- --- -- For example, for ':*:', we have 'NonEmptyF'. This is because:- --- -- @- -- x ~ 'NonEmptyF' (x ':|' []) ~ 'inject' x- -- x ':*:' y ~ NonEmptyF (x :| [y]) ~ 'toNonEmptyBy' (x :*: y)- -- x :*: y :*: z ~ NonEmptyF (x :| [y,z])- -- -- etc.- -- @- --- -- You can create an "singleton" one with 'inject', or else one from- -- a single @t f f@ with 'toNonEmptyBy'.- --- -- See 'Data.HBifunctor.Tensor.ListBy' for a "possibly empty" version- -- of this type.- type NonEmptyBy t :: (Type -> Type) -> Type -> Type+ -- | The "semigroup functor combinator" generated by @t@.+ --+ -- A value of type @NonEmptyBy t f a@ is /equivalent/ to one of:+ --+ -- * @f a@+ -- * @t f f a@+ -- * @t f (t f f) a@+ -- * @t f (t f (t f f)) a@+ -- * @t f (t f (t f (t f f))) a@+ -- * .. etc+ --+ -- For example, for ':*:', we have 'NonEmptyF'. This is because:+ --+ -- @+ -- x ~ 'NonEmptyF' (x ':|' []) ~ 'inject' x+ -- x ':*:' y ~ NonEmptyF (x :| [y]) ~ 'toNonEmptyBy' (x :*: y)+ -- x :*: y :*: z ~ NonEmptyF (x :| [y,z])+ -- -- etc.+ -- @+ --+ -- You can create an "singleton" one with 'inject', or else one from+ -- a single @t f f@ with 'toNonEmptyBy'.+ --+ -- See 'Data.HBifunctor.Tensor.ListBy' for a "possibly empty" version+ -- of this type.+ type NonEmptyBy t :: (Type -> Type) -> Type -> Type - -- | A description of "what type of Functor" this tensor is expected to- -- be applied to. This should typically always be either 'Functor',- -- 'Contravariant', or 'Invariant'.- --- -- @since 0.3.0.0- type FunctorBy t :: (Type -> Type) -> Constraint- type FunctorBy t = Unconstrained+ -- | A description of "what type of Functor" this tensor is expected to+ -- be applied to. This should typically always be either 'Functor',+ -- 'Contravariant', or 'Invariant'.+ --+ -- @since 0.3.0.0+ type FunctorBy t :: (Type -> Type) -> Constraint - -- | The isomorphism between @t f (t g h) a@ and @t (t f g) h a@. To- -- use this isomorphism, see 'assoc' and 'disassoc'.- associating- :: (FunctorBy t f, FunctorBy t g, FunctorBy t h)- => t f (t g h) <~> t (t f g) h+ type FunctorBy t = Unconstrained - -- | If a @'NonEmptyBy' t f@ represents multiple applications of @t f@ to- -- itself, then we can also "append" two @'NonEmptyBy' t f@s applied to- -- themselves into one giant @'NonEmptyBy' t f@ containing all of the @t f@s.- --- -- Note that this essentially gives an instance for @'SemigroupIn'- -- t (NonEmptyBy t f)@, for any functor @f@.- appendNE :: t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f+ -- | The isomorphism between @t f (t g h) a@ and @t (t f g) h a@. To+ -- use this isomorphism, see 'assoc' and 'disassoc'.+ associating ::+ (FunctorBy t f, FunctorBy t g, FunctorBy t h) =>+ t f (t g h) <~> t (t f g) h - -- | If a @'NonEmptyBy' t f@ represents multiple applications of @t f@- -- to itself, then we can split it based on whether or not it is just- -- a single @f@ or at least one top-level application of @t f@.- --- -- Note that you can recursively "unroll" a 'NonEmptyBy' completely- -- into a 'Data.HFunctor.Chain.Chain1' by using- -- 'Data.HFunctor.Chain.unrollNE'.- matchNE :: FunctorBy t f => NonEmptyBy t f ~> f :+: t f (NonEmptyBy t f)+ -- | If a @'NonEmptyBy' t f@ represents multiple applications of @t f@ to+ -- itself, then we can also "append" two @'NonEmptyBy' t f@s applied to+ -- themselves into one giant @'NonEmptyBy' t f@ containing all of the @t f@s.+ --+ -- Note that this essentially gives an instance for @'SemigroupIn'+ -- t (NonEmptyBy t f)@, for any functor @f@.+ appendNE :: t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f - -- | Prepend an application of @t f@ to the front of a @'NonEmptyBy' t f@.- consNE :: t f (NonEmptyBy t f) ~> NonEmptyBy t f- consNE = appendNE . hleft inject+ -- | If a @'NonEmptyBy' t f@ represents multiple applications of @t f@+ -- to itself, then we can split it based on whether or not it is just+ -- a single @f@ or at least one top-level application of @t f@.+ --+ -- Note that you can recursively "unroll" a 'NonEmptyBy' completely+ -- into a 'Data.HFunctor.Chain.Chain1' by using+ -- 'Data.HFunctor.Chain.unrollNE'.+ matchNE :: FunctorBy t f => NonEmptyBy t f ~> f :+: t f (NonEmptyBy t f) - -- | Embed a direct application of @f@ to itself into a @'NonEmptyBy' t f@.- toNonEmptyBy :: t f f ~> NonEmptyBy t f- toNonEmptyBy = consNE . hright inject+ -- | Prepend an application of @t f@ to the front of a @'NonEmptyBy' t f@.+ consNE :: t f (NonEmptyBy t f) ~> NonEmptyBy t f+ consNE = appendNE . hleft inject - {-# MINIMAL associating, appendNE, matchNE #-}+ -- | Embed a direct application of @f@ to itself into a @'NonEmptyBy' t f@.+ toNonEmptyBy :: t f f ~> NonEmptyBy t f+ toNonEmptyBy = consNE . hright inject + {-# MINIMAL associating, appendNE, matchNE #-}+ -- | Reassociate an application of @t@.-assoc- :: (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h)- => t f (t g h)+assoc ::+ (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>+ t f (t g h) ~> t (t f g) h assoc = viewF associating -- | Reassociate an application of @t@.-disassoc- :: (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h)- => t (t f g) h+disassoc ::+ (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>+ t (t f g) h ~> t f (t g h) disassoc = reviewF associating @@ -255,31 +258,29 @@ -- -- This will prevent problems with overloaded instances. class (Associative t, FunctorBy t f) => SemigroupIn t f where- -- | The 'HBifunctor' analogy of 'retract'. It retracts /both/ @f@s- -- into a single @f@, effectively fully mixing them together.- --- -- This function makes @f@ a semigroup in the category of endofunctors- -- with respect to tensor @t@.- biretract :: t f f ~> f-- default biretract :: Interpret (NonEmptyBy t) f => t f f ~> f- biretract = retract . consNE . hright inject-- -- | The 'HBifunctor' analogy of 'interpret'. It takes two- -- interpreting functions, and mixes them together into a target- -- functor @h@.- --- -- Note that this is useful in the poly-kinded case, but it is not possible- -- to define generically for all 'SemigroupIn' because it only is defined- -- for @Type -> Type@ inputes. See '!+!' for a version that is poly-kinded- -- for ':+:' in specific.- binterpret- :: g ~> f- -> h ~> f- -> t g h ~> f+ -- | The 'HBifunctor' analogy of 'retract'. It retracts /both/ @f@s+ -- into a single @f@, effectively fully mixing them together.+ --+ -- This function makes @f@ a semigroup in the category of endofunctors+ -- with respect to tensor @t@.+ biretract :: t f f ~> f+ default biretract :: Interpret (NonEmptyBy t) f => t f f ~> f+ biretract = retract . consNE . hright inject - default binterpret :: Interpret (NonEmptyBy t) f => (g ~> f) -> (h ~> f) -> t g h ~> f- binterpret f g = retract . toNonEmptyBy . hbimap f g+ -- | The 'HBifunctor' analogy of 'interpret'. It takes two+ -- interpreting functions, and mixes them together into a target+ -- functor @h@.+ --+ -- Note that this is useful in the poly-kinded case, but it is not possible+ -- to define generically for all 'SemigroupIn' because it only is defined+ -- for @Type -> Type@ inputes. See '!+!' for a version that is poly-kinded+ -- for ':+:' in specific.+ binterpret ::+ g ~> f ->+ h ~> f ->+ t g h ~> f+ default binterpret :: Interpret (NonEmptyBy t) f => (g ~> f) -> (h ~> f) -> t g h ~> f+ binterpret f g = retract . toNonEmptyBy . hbimap f g -- | An implementation of 'retract' that works for any instance of -- @'SemigroupIn' t@ for @'NonEmptyBy' t@.@@ -287,8 +288,9 @@ -- Can be useful as a default implementation if you already have -- 'SemigroupIn' implemented. retractNE :: forall t f. SemigroupIn t f => NonEmptyBy t f ~> f-retractNE = (id !*! biretract @t . hright (retractNE @t))- . matchNE @t+retractNE =+ (id !*! biretract @t . hright (retractNE @t))+ . matchNE @t -- | An implementation of 'interpret' that works for any instance of -- @'SemigroupIn' t@ for @'NonEmptyBy' t@.@@ -335,12 +337,12 @@ -- :: 'Day' [] (Map Int) Char -- -> Sum Int -- @-biget- :: SemigroupIn t (AltConst b)- => (forall x. f x -> b)- -> (forall x. g x -> b)- -> t f g a- -> b+biget ::+ SemigroupIn t (AltConst b) =>+ (forall x. f x -> b) ->+ (forall x. g x -> b) ->+ t f g a ->+ b biget f g = getAltConst . binterpret (AltConst . f) (AltConst . g) -- | Infix alias for 'biget'@@ -357,13 +359,14 @@ -- :: 'Day' [] (Map Int) Char -- -> Sum Int -- @-(!$!)- :: SemigroupIn t (AltConst b)- => (forall x. f x -> b)- -> (forall x. g x -> b)- -> t f g a- -> b+(!$!) ::+ SemigroupIn t (AltConst b) =>+ (forall x. f x -> b) ->+ (forall x. g x -> b) ->+ t f g a ->+ b (!$!) = biget+ infixr 5 !$! -- | Infix alias for 'binterpret'@@ -372,24 +375,26 @@ -- to define generically for all 'SemigroupIn' because it only is defined -- for @Type -> Type@ inputes. See '!+!' for a version that is poly-kinded -- for ':+:' in specific.-(!*!)- :: SemigroupIn t h- => (f ~> h)- -> (g ~> h)- -> t f g+(!*!) ::+ SemigroupIn t h =>+ (f ~> h) ->+ (g ~> h) ->+ t f g ~> h (!*!) = binterpret+ infixr 5 !*! -- | A version of '!*!' specifically for ':+:' that is poly-kinded-(!+!)- :: (f ~> h)- -> (g ~> h)- -> (f :+: g)+(!+!) ::+ (f ~> h) ->+ (g ~> h) ->+ (f :+: g) ~> h (!+!) f g = \case- L1 x -> f x- R1 y -> g y+ L1 x -> f x+ R1 y -> g y+ infixr 5 !+! -- | Useful wrapper over 'binterpret' to allow you to directly extract@@ -406,330 +411,338 @@ -- For some constraints (like 'Monad'), this will not be usable. -- -- @since 0.3.2.0-biapply- :: SemigroupIn t (Op b)- => (forall x. f x -> x -> b)- -> (forall x. g x -> x -> b)- -> t f g a- -> a- -> b+biapply ::+ SemigroupIn t (Op b) =>+ (forall x. f x -> x -> b) ->+ (forall x. g x -> x -> b) ->+ t f g a ->+ a ->+ b biapply f g = getOp . binterpret (Op . f) (Op . g) instance Associative (:*:) where- type NonEmptyBy (:*:) = NonEmptyF+ type NonEmptyBy (:*:) = NonEmptyF - associating = isoF to_ from_- where- to_ (x :*: (y :*: z)) = (x :*: y) :*: z- from_ ((x :*: y) :*: z) = x :*: (y :*: z)+ associating = isoF to_ from_+ where+ to_ (x :*: (y :*: z)) = (x :*: y) :*: z+ from_ ((x :*: y) :*: z) = x :*: (y :*: z) - appendNE (NonEmptyF xs :*: NonEmptyF ys) = NonEmptyF (xs <> ys)- matchNE x = case ys of- L1 ~Proxy -> L1 y- R1 zs -> R1 $ y :*: zs- where- y :*: ys = fromListF `hright` nonEmptyProd x+ appendNE (NonEmptyF xs :*: NonEmptyF ys) = NonEmptyF (xs <> ys)+ matchNE x = case ys of+ L1 ~Proxy -> L1 y+ R1 zs -> R1 $ y :*: zs+ where+ y :*: ys = fromListF `hright` nonEmptyProd x - consNE (x :*: NonEmptyF xs) = NonEmptyF $ x :| toList xs- toNonEmptyBy (x :*: y ) = NonEmptyF $ x :| [y]+ consNE (x :*: NonEmptyF xs) = NonEmptyF $ x :| toList xs+ toNonEmptyBy (x :*: y) = NonEmptyF $ x :| [y] -- | Instances of 'Alt' are semigroups in the semigroupoidal category on -- ':*:'. instance Alt f => SemigroupIn (:*:) f where- biretract (x :*: y) = x <!> y- binterpret f g (x :*: y) = f x <!> g y+ biretract (x :*: y) = x <!> y+ binterpret f g (x :*: y) = f x <!> g y instance Associative Product where- type NonEmptyBy Product = NonEmptyF+ type NonEmptyBy Product = NonEmptyF - associating = isoF to_ from_- where- to_ (Pair x (Pair y z)) = Pair (Pair x y) z- from_ (Pair (Pair x y) z) = Pair x (Pair y z)+ associating = isoF to_ from_+ where+ to_ (Pair x (Pair y z)) = Pair (Pair x y) z+ from_ (Pair (Pair x y) z) = Pair x (Pair y z) - appendNE (NonEmptyF xs `Pair` NonEmptyF ys) = NonEmptyF (xs <> ys)- matchNE x = case ys of- L1 ~Proxy -> L1 y- R1 zs -> R1 $ Pair y zs- where- y :*: ys = fromListF `hright` nonEmptyProd x+ appendNE (NonEmptyF xs `Pair` NonEmptyF ys) = NonEmptyF (xs <> ys)+ matchNE x = case ys of+ L1 ~Proxy -> L1 y+ R1 zs -> R1 $ Pair y zs+ where+ y :*: ys = fromListF `hright` nonEmptyProd x - consNE (x `Pair` NonEmptyF xs) = NonEmptyF $ x :| toList xs- toNonEmptyBy (x `Pair` y ) = NonEmptyF $ x :| [y]+ consNE (x `Pair` NonEmptyF xs) = NonEmptyF $ x :| toList xs+ toNonEmptyBy (x `Pair` y) = NonEmptyF $ x :| [y] -- | Instances of 'Alt' are semigroups in the semigroupoidal category on -- 'Product'. instance Alt f => SemigroupIn Product f where- biretract (Pair x y) = x <!> y- binterpret f g (Pair x y) = f x <!> g y+ biretract (Pair x y) = x <!> y+ binterpret f g (Pair x y) = f x <!> g y instance Associative Day where- type NonEmptyBy Day = Ap1- type FunctorBy Day = Functor- associating = isoF D.assoc D.disassoc+ type NonEmptyBy Day = Ap1+ type FunctorBy Day = Functor+ associating = isoF D.assoc D.disassoc - appendNE (Day x y z) = z <$> x <.> y- matchNE a = case fromAp `hright` ap1Day a of- Day x y z -> case y of- L1 (Identity y') -> L1 $ (`z` y') <$> x- R1 ys -> R1 $ Day x ys z+ appendNE (Day x y z) = z <$> x <.> y+ matchNE a = case fromAp `hright` ap1Day a of+ Day x y z -> case y of+ L1 (Identity y') -> L1 $ (`z` y') <$> x+ R1 ys -> R1 $ Day x ys z - consNE (Day x y z) = Ap1 x $ flip z <$> toAp y- toNonEmptyBy (Day x y z) = z <$> inject x <.> inject y+ consNE (Day x y z) = Ap1 x $ flip z <$> toAp y+ toNonEmptyBy (Day x y z) = z <$> inject x <.> inject y -- | Instances of 'Apply' are semigroups in the semigroupoidal category on -- 'Day'. instance Apply f => SemigroupIn Day f where- biretract (Day x y z) = z <$> x <.> y- binterpret f g (Day x y z) = z <$> f x <.> g y+ biretract (Day x y z) = z <$> x <.> y+ binterpret f g (Day x y z) = z <$> f x <.> g y -- | @since 0.3.0.0 instance Associative CD.Day where- type NonEmptyBy CD.Day = Div1- type FunctorBy CD.Day = Contravariant- associating = isoF CD.assoc CD.disassoc+ type NonEmptyBy CD.Day = Div1+ type FunctorBy CD.Day = Contravariant+ associating = isoF CD.assoc CD.disassoc - appendNE (CD.Day x y f) = divise f x y- matchNE = hbimap CCY.lowerCoyoneda go . matchNE @(:*:) . NonEmptyF . unDiv1- where- go (CCY.Coyoneda f x :*: NonEmptyF xs) = CD.Day x (Div1 xs) (\y -> (f y, y))+ appendNE (CD.Day x y f) = divise f x y+ matchNE = hbimap CCY.lowerCoyoneda go . matchNE @(:*:) . NonEmptyF . unDiv1+ where+ go (CCY.Coyoneda f x :*: NonEmptyF xs) = CD.Day x (Div1 xs) (\y -> (f y, y)) - consNE (CD.Day x (Div1 xs) f) = Div1 . runNonEmptyF . consNE $- CCY.Coyoneda (fst . f) x :*: contramap (snd . f) (NonEmptyF xs)- toNonEmptyBy (CD.Day x y f) = Div1 . runNonEmptyF . toNonEmptyBy $- CCY.Coyoneda (fst . f) x :*: CCY.Coyoneda (snd . f) y+ consNE (CD.Day x (Div1 xs) f) =+ Div1 . runNonEmptyF . consNE $+ CCY.Coyoneda (fst . f) x :*: contramap (snd . f) (NonEmptyF xs)+ toNonEmptyBy (CD.Day x y f) =+ Div1 . runNonEmptyF . toNonEmptyBy $+ CCY.Coyoneda (fst . f) x :*: CCY.Coyoneda (snd . f) y -- | @since 0.3.0.0 instance Divise f => SemigroupIn CD.Day f where- biretract (CD.Day x y f) = divise f x y- binterpret f g (CD.Day x y h) = divise h (f x) (g y)+ biretract (CD.Day x y f) = divise f x y+ binterpret f g (CD.Day x y h) = divise h (f x) (g y) instance Associative ID.Day where- type NonEmptyBy ID.Day = DivAp1- type FunctorBy ID.Day = Invariant- associating = isoF assoc disassoc+ type NonEmptyBy ID.Day = DivAp1+ type FunctorBy ID.Day = Invariant+ associating = isoF assoc disassoc - appendNE = coerce appendNEIDay_- matchNE = coerce matchChain1+ appendNE = coerce appendNEIDay_+ matchNE = coerce matchChain1 - consNE = coerce More1- toNonEmptyBy = coerce toChain1+ consNE = coerce More1+ toNonEmptyBy = coerce toChain1 appendNEIDay_ :: ID.Day (Chain1 ID.Day f) (Chain1 ID.Day f) ~> Chain1 ID.Day f appendNEIDay_ (ID.Day xs ys g f) = case xs of- Done1 x -> More1 (ID.Day x ys g f)- More1 (ID.Day z zs j h) -> More1 $- ID.Day z (appendNEIDay_ (ID.Day zs ys (,) id))- (\a (b, c) -> g (j a b) c)- (B.assoc . first h . f)+ Done1 x -> More1 (ID.Day x ys g f)+ More1 (ID.Day z zs j h) ->+ More1 $+ ID.Day+ z+ (appendNEIDay_ (ID.Day zs ys (,) id))+ (\a (b, c) -> g (j a b) c)+ (B.assoc . first h . f) -- | @since 0.4.0.0 instance Inply f => SemigroupIn ID.Day f where- biretract = dather- binterpret = runDay+ biretract = dather+ binterpret = runDay instance Associative IN.Night where- type NonEmptyBy IN.Night = DecAlt1- type FunctorBy IN.Night = Invariant- associating = isoF IN.assoc IN.unassoc+ type NonEmptyBy IN.Night = DecAlt1+ type FunctorBy IN.Night = Invariant+ associating = isoF IN.assoc IN.unassoc - appendNE = coerce appendNEINight_- matchNE = coerce matchChain1+ appendNE = coerce appendNEINight_+ matchNE = coerce matchChain1 - consNE = coerce More1- toNonEmptyBy = coerce toChain1+ consNE = coerce More1+ toNonEmptyBy = coerce toChain1 appendNEINight_ :: IN.Night (Chain1 IN.Night f) (Chain1 IN.Night f) ~> Chain1 IN.Night f appendNEINight_ (IN.Night xs ys f g h) = case xs of- Done1 x -> More1 (IN.Night x ys f g h)- More1 (IN.Night z zs j k l) -> More1 $- IN.Night z (appendNEINight_ (IN.Night zs ys Left Right id))- (f . j)- (either (f . k) g)- (B.assoc . first l . h)+ Done1 x -> More1 (IN.Night x ys f g h)+ More1 (IN.Night z zs j k l) ->+ More1 $+ IN.Night+ z+ (appendNEINight_ (IN.Night zs ys Left Right id))+ (f . j)+ (either (f . k) g)+ (B.assoc . first l . h) -- | @since 0.4.0.0 instance Inalt f => SemigroupIn IN.Night f where- biretract = IN.nerve- binterpret = IN.runNight+ biretract = IN.nerve+ binterpret = IN.runNight -- | @since 0.3.0.0 instance Associative Night where- type NonEmptyBy Night = Dec1- type FunctorBy Night = Contravariant- associating = isoF N.assoc N.unassoc+ type NonEmptyBy Night = Dec1+ type FunctorBy Night = Contravariant+ associating = isoF N.assoc N.unassoc - appendNE (Night x y f) = decide f x y- matchNE (Dec1 f x xs) = case xs of- Lose g -> L1 $ contramap (either id (absurd . g) . f) x- Choose g y ys -> R1 $ Night x (Dec1 g y ys) f+ appendNE (Night x y f) = decide f x y+ matchNE (Dec1 f x xs) = case xs of+ Lose g -> L1 $ contramap (either id (absurd . g) . f) x+ Choose g y ys -> R1 $ Night x (Dec1 g y ys) f - consNE (Night x y f) = Dec1 f x (toDec y)- toNonEmptyBy (Night x y f) = Dec1 f x (inject y)+ consNE (Night x y f) = Dec1 f x (toDec y)+ toNonEmptyBy (Night x y f) = Dec1 f x (inject y) -- | @since 0.3.0.0 instance Decide f => SemigroupIn Night f where- biretract (Night x y f) = decide f x y- binterpret f g (Night x y h) = decide h (f x) (g y)+ biretract (Night x y f) = decide f x y+ binterpret f g (Night x y h) = decide h (f x) (g y) instance Associative (:+:) where- type NonEmptyBy (:+:) = Step+ type NonEmptyBy (:+:) = Step - associating = isoF to_ from_- where- to_ = \case- L1 x -> L1 (L1 x)- R1 (L1 y) -> L1 (R1 y)- R1 (R1 z) -> R1 z- from_ = \case- L1 (L1 x) -> L1 x- L1 (R1 y) -> R1 (L1 y)- R1 z -> R1 (R1 z)+ associating = isoF to_ from_+ where+ to_ = \case+ L1 x -> L1 (L1 x)+ R1 (L1 y) -> L1 (R1 y)+ R1 (R1 z) -> R1 z+ from_ = \case+ L1 (L1 x) -> L1 x+ L1 (R1 y) -> R1 (L1 y)+ R1 z -> R1 (R1 z) - appendNE = \case- L1 (Step i x) -> Step (i + 1) x- R1 (Step i y) -> Step (i + 2) y- matchNE = hright stepDown . stepDown+ appendNE = \case+ L1 (Step i x) -> Step (i + 1) x+ R1 (Step i y) -> Step (i + 2) y+ matchNE = hright stepDown . stepDown - consNE = stepUp . R1 . stepUp- toNonEmptyBy = \case- L1 x -> Step 1 x- R1 y -> Step 2 y+ consNE = stepUp . R1 . stepUp+ toNonEmptyBy = \case+ L1 x -> Step 1 x+ R1 y -> Step 2 y -- | All functors are semigroups in the semigroupoidal category on ':+:'. instance SemigroupIn (:+:) f where- biretract = \case- L1 x -> x- R1 y -> y- binterpret f g = \case- L1 x -> f x- R1 y -> g y+ biretract = \case+ L1 x -> x+ R1 y -> y+ binterpret f g = \case+ L1 x -> f x+ R1 y -> g y instance Associative Sum where- type NonEmptyBy Sum = Step- associating = isoF to_ from_- where- to_ = \case- InL x -> InL (InL x)- InR (InL y) -> InL (InR y)- InR (InR z) -> InR z- from_ = \case- InL (InL x) -> InL x- InL (InR y) -> InR (InL y)- InR z -> InR (InR z)+ type NonEmptyBy Sum = Step+ associating = isoF to_ from_+ where+ to_ = \case+ InL x -> InL (InL x)+ InR (InL y) -> InL (InR y)+ InR (InR z) -> InR z+ from_ = \case+ InL (InL x) -> InL x+ InL (InR y) -> InR (InL y)+ InR z -> InR (InR z) - appendNE = \case- InL (Step i x) -> Step (i + 1) x- InR (Step i y) -> Step (i + 2) y- matchNE = hright (viewF sumSum . stepDown) . stepDown+ appendNE = \case+ InL (Step i x) -> Step (i + 1) x+ InR (Step i y) -> Step (i + 2) y+ matchNE = hright (viewF sumSum . stepDown) . stepDown - consNE = stepUp . R1 . stepUp . reviewF sumSum- toNonEmptyBy = \case- InL x -> Step 1 x- InR y -> Step 2 y+ consNE = stepUp . R1 . stepUp . reviewF sumSum+ toNonEmptyBy = \case+ InL x -> Step 1 x+ InR y -> Step 2 y -- | All functors are semigroups in the semigroupoidal category on 'Sum'. instance SemigroupIn Sum f where- biretract = \case- InR x -> x- InL y -> y- binterpret f g = \case- InL x -> f x- InR y -> g y+ biretract = \case+ InR x -> x+ InL y -> y+ binterpret f g = \case+ InL x -> f x+ InR y -> g y -- | Ideally here 'NonEmptyBy' would be equivalent to 'Data.HBifunctor.Tensor.ListBy', -- just like for ':+:'. This should be possible if we can write -- a bijection. This bijection should be possible in theory --- but it has -- not yet been implemented. instance Associative These1 where- type NonEmptyBy These1 = ComposeT Flagged Steps- associating = isoF to_ from_- where- to_ = \case- This1 x -> This1 (This1 x )- That1 (This1 y ) -> This1 (That1 y)- That1 (That1 z) -> That1 z- That1 (These1 y z) -> These1 (That1 y) z- These1 x (This1 y ) -> This1 (These1 x y)- These1 x (That1 z) -> These1 (This1 x ) z- These1 x (These1 y z) -> These1 (These1 x y) z- from_ = \case- This1 (This1 x ) -> This1 x- This1 (That1 y) -> That1 (This1 y )- This1 (These1 x y) -> These1 x (This1 y )- That1 z -> That1 (That1 z)- These1 (This1 x ) z -> These1 x (That1 z)- These1 (That1 y) z -> That1 (These1 y z)- These1 (These1 x y) z -> These1 x (These1 y z)+ type NonEmptyBy These1 = ComposeT Flagged Steps+ associating = isoF to_ from_+ where+ to_ = \case+ This1 x -> This1 (This1 x)+ That1 (This1 y) -> This1 (That1 y)+ That1 (That1 z) -> That1 z+ That1 (These1 y z) -> These1 (That1 y) z+ These1 x (This1 y) -> This1 (These1 x y)+ These1 x (That1 z) -> These1 (This1 x) z+ These1 x (These1 y z) -> These1 (These1 x y) z+ from_ = \case+ This1 (This1 x) -> This1 x+ This1 (That1 y) -> That1 (This1 y)+ This1 (These1 x y) -> These1 x (This1 y)+ That1 z -> That1 (That1 z)+ These1 (This1 x) z -> These1 x (That1 z)+ These1 (That1 y) z -> That1 (These1 y z)+ These1 (These1 x y) z -> These1 x (These1 y z) - appendNE s = ComposeT $ case s of- This1 (ComposeT (Flagged _ q)) ->- Flagged True q- That1 (ComposeT (Flagged b q)) ->- Flagged b (stepsUp (That1 q))- These1 (ComposeT (Flagged a q)) (ComposeT (Flagged b r)) ->- Flagged (a || b) (q <> r)- matchNE (ComposeT (Flagged isImpure q)) = case stepsDown q of- This1 x- | isImpure -> R1 $ This1 x- | otherwise -> L1 x- That1 y -> R1 . That1 . ComposeT $ Flagged isImpure y- These1 x y -> R1 . These1 x . ComposeT $ Flagged isImpure y+ appendNE s = ComposeT $ case s of+ This1 (ComposeT (Flagged _ q)) ->+ Flagged True q+ That1 (ComposeT (Flagged b q)) ->+ Flagged b (stepsUp (That1 q))+ These1 (ComposeT (Flagged a q)) (ComposeT (Flagged b r)) ->+ Flagged (a || b) (q <> r)+ matchNE (ComposeT (Flagged isImpure q)) = case stepsDown q of+ This1 x+ | isImpure -> R1 $ This1 x+ | otherwise -> L1 x+ That1 y -> R1 . That1 . ComposeT $ Flagged isImpure y+ These1 x y -> R1 . These1 x . ComposeT $ Flagged isImpure y - consNE s = ComposeT $ case s of- This1 x -> Flagged True (inject x)- That1 (ComposeT (Flagged b y)) -> Flagged b (stepsUp (That1 y))- These1 x (ComposeT (Flagged b y)) -> Flagged b (stepsUp (These1 x y))- toNonEmptyBy s = ComposeT $ case s of- This1 x -> Flagged True . Steps $ NEM.singleton 0 x- That1 y -> Flagged False . Steps $ NEM.singleton 1 y- These1 x y -> Flagged False . Steps $ NEM.fromDistinctAscList $ (0, x) :| [(1, y)]+ consNE s = ComposeT $ case s of+ This1 x -> Flagged True (inject x)+ That1 (ComposeT (Flagged b y)) -> Flagged b (stepsUp (That1 y))+ These1 x (ComposeT (Flagged b y)) -> Flagged b (stepsUp (These1 x y))+ toNonEmptyBy s = ComposeT $ case s of+ This1 x -> Flagged True . Steps $ NEM.singleton 0 x+ That1 y -> Flagged False . Steps $ NEM.singleton 1 y+ These1 x y -> Flagged False . Steps $ NEM.fromDistinctAscList $ (0, x) :| [(1, y)] instance Alt f => SemigroupIn These1 f where- biretract = \case- This1 x -> x- That1 y -> y- These1 x y -> x <!> y- binterpret f g = \case- This1 x -> f x- That1 y -> g y- These1 x y -> f x <!> g y+ biretract = \case+ This1 x -> x+ That1 y -> y+ These1 x y -> x <!> y+ binterpret f g = \case+ This1 x -> f x+ That1 y -> g y+ These1 x y -> f x <!> g y instance Associative Void3 where- type NonEmptyBy Void3 = IdentityT- associating = isoF coerce coerce+ type NonEmptyBy Void3 = IdentityT+ associating = isoF coerce coerce - appendNE = \case {}- matchNE = L1 . runIdentityT+ appendNE = \case {}+ matchNE = L1 . runIdentityT - consNE = \case {}- toNonEmptyBy = \case {}+ consNE = \case {}+ toNonEmptyBy = \case {} -- | All functors are semigroups in the semigroupoidal category on 'Void3'. instance SemigroupIn Void3 f where- biretract = \case {}- binterpret _ _ = \case {}+ biretract = \case {}+ binterpret _ _ = \case {} instance Associative Comp where- type NonEmptyBy Comp = Free1- type FunctorBy Comp = Functor+ type NonEmptyBy Comp = Free1+ type FunctorBy Comp = Functor - associating = isoF to_ from_- where- to_ (x :>>= y) = (x :>>= (unComp . y)) :>>= id- from_ ((x :>>= y) :>>= z) = x :>>= ((:>>= z) . y)+ associating = isoF to_ from_+ where+ to_ (x :>>= y) = (x :>>= (unComp . y)) :>>= id+ from_ ((x :>>= y) :>>= z) = x :>>= ((:>>= z) . y) - appendNE (x :>>= y) = x >>- y- matchNE = matchFree1+ appendNE (x :>>= y) = x >>- y+ matchNE = matchFree1 - consNE (x :>>= y) = liftFree1 x >>- y- toNonEmptyBy (x :>>= g) = liftFree1 x >>- inject . g+ consNE (x :>>= y) = liftFree1 x >>- y+ toNonEmptyBy (x :>>= g) = liftFree1 x >>- inject . g -- | Instances of 'Bind' are semigroups in the semigroupoidal category on -- 'Comp'. instance Bind f => SemigroupIn Comp f where- biretract (x :>>= y) = x >>- y- binterpret f g (x :>>= y) = f x >>- (g . y)+ biretract (x :>>= y) = x >>- y+ binterpret f g (x :>>= y) = f x >>- (g . y) ---- data TC f a = TCA (f a) Bool ---- | TCB (Maybe (f a)) (TC f a)@@ -738,48 +751,54 @@ -- -- aka sparse non-empty list tagged with a bool instance Associative Joker where- type NonEmptyBy Joker = Flagged- associating = isoF (Joker . Joker . runJoker)- (Joker . runJoker . runJoker)- appendNE (Joker (Flagged _ x)) = Flagged True x- matchNE (Flagged False x) = L1 x- matchNE (Flagged True x) = R1 $ Joker x+ type NonEmptyBy Joker = Flagged+ associating =+ isoF+ (Joker . Joker . runJoker)+ (Joker . runJoker . runJoker)+ appendNE (Joker (Flagged _ x)) = Flagged True x+ matchNE (Flagged False x) = L1 x+ matchNE (Flagged True x) = R1 $ Joker x instance SemigroupIn Joker f where- biretract = runJoker- binterpret f _ = f . runJoker+ biretract = runJoker+ binterpret f _ = f . runJoker instance Associative LeftF where- type NonEmptyBy LeftF = Flagged- associating = isoF (LeftF . LeftF . runLeftF)- (LeftF . runLeftF . runLeftF)+ type NonEmptyBy LeftF = Flagged+ associating =+ isoF+ (LeftF . LeftF . runLeftF)+ (LeftF . runLeftF . runLeftF) - appendNE = hbind (Flagged True) . runLeftF- matchNE (Flagged False x) = L1 x- matchNE (Flagged True x) = R1 $ LeftF x+ appendNE = hbind (Flagged True) . runLeftF+ matchNE (Flagged False x) = L1 x+ matchNE (Flagged True x) = R1 $ LeftF x - consNE = Flagged True . runLeftF- toNonEmptyBy = Flagged True . runLeftF+ consNE = Flagged True . runLeftF+ toNonEmptyBy = Flagged True . runLeftF instance SemigroupIn LeftF f where- biretract = runLeftF- binterpret f _ = f . runLeftF+ biretract = runLeftF+ binterpret f _ = f . runLeftF instance Associative RightF where- type NonEmptyBy RightF = Step+ type NonEmptyBy RightF = Step - associating = isoF (RightF . runRightF . runRightF)- (RightF . RightF . runRightF)+ associating =+ isoF+ (RightF . runRightF . runRightF)+ (RightF . RightF . runRightF) - appendNE = stepUp . R1 . runRightF- matchNE = hright RightF . stepDown+ appendNE = stepUp . R1 . runRightF+ matchNE = hright RightF . stepDown - consNE = stepUp . R1 . runRightF- toNonEmptyBy = Step 1 . runRightF+ consNE = stepUp . R1 . runRightF+ toNonEmptyBy = Step 1 . runRightF instance SemigroupIn RightF f where- biretract = runRightF- binterpret _ g = g . runRightF+ biretract = runRightF+ binterpret _ g = g . runRightF -- | A newtype wrapper meant to be used to define polymorphic 'SemigroupIn' -- instances. See documentation for 'SemigroupIn' for more information.@@ -792,53 +811,56 @@ -- @ -- -- As that would globally ruin everything using 'WrapHBF'.-newtype WrapHBF t f g a = WrapHBF { unwrapHBF :: t f g a }+newtype WrapHBF t f g a = WrapHBF {unwrapHBF :: t f g a} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) instance Show1 (t f g) => Show1 (WrapHBF t f g) where- liftShowsPrec sp sl d (WrapHBF x) = showsUnaryWith (liftShowsPrec sp sl) "WrapHBF" d x+ liftShowsPrec sp sl d (WrapHBF x) = showsUnaryWith (liftShowsPrec sp sl) "WrapHBF" d x instance Eq1 (t f g) => Eq1 (WrapHBF t f g) where- liftEq eq (WrapHBF x) (WrapHBF y) = liftEq eq x y+ liftEq eq (WrapHBF x) (WrapHBF y) = liftEq eq x y instance Ord1 (t f g) => Ord1 (WrapHBF t f g) where- liftCompare c (WrapHBF x) (WrapHBF y) = liftCompare c x y+ liftCompare c (WrapHBF x) (WrapHBF y) = liftCompare c x y instance HBifunctor t => HBifunctor (WrapHBF t) where- hbimap f g (WrapHBF x) = WrapHBF (hbimap f g x)- hleft f (WrapHBF x) = WrapHBF (hleft f x)- hright g (WrapHBF x) = WrapHBF (hright g x)+ hbimap f g (WrapHBF x) = WrapHBF (hbimap f g x)+ hleft f (WrapHBF x) = WrapHBF (hleft f x)+ hright g (WrapHBF x) = WrapHBF (hright g x) -deriving via (WrappedHBifunctor (WrapHBF t) f)- instance HBifunctor t => HFunctor (WrapHBF t f)+deriving via+ (WrappedHBifunctor (WrapHBF t) f)+ instance+ HBifunctor t => HFunctor (WrapHBF t f) instance Associative t => Associative (WrapHBF t) where- type NonEmptyBy (WrapHBF t) = NonEmptyBy t- type FunctorBy (WrapHBF t) = FunctorBy t+ type NonEmptyBy (WrapHBF t) = NonEmptyBy t+ type FunctorBy (WrapHBF t) = FunctorBy t - associating = isoF (hright unwrapHBF . unwrapHBF) (WrapHBF . hright WrapHBF)- . associating @t- . isoF (WrapHBF . hleft WrapHBF) (hleft unwrapHBF . unwrapHBF)+ associating =+ isoF (hright unwrapHBF . unwrapHBF) (WrapHBF . hright WrapHBF)+ . associating @t+ . isoF (WrapHBF . hleft WrapHBF) (hleft unwrapHBF . unwrapHBF) - appendNE = appendNE . unwrapHBF- matchNE = hright WrapHBF . matchNE- consNE = consNE . unwrapHBF- toNonEmptyBy = toNonEmptyBy . unwrapHBF+ appendNE = appendNE . unwrapHBF+ matchNE = hright WrapHBF . matchNE+ consNE = consNE . unwrapHBF+ toNonEmptyBy = toNonEmptyBy . unwrapHBF -- | Any @'NonEmptyBy' t f@ is a @'SemigroupIn' t@ if we have -- @'Associative' t@. This newtype wrapper witnesses that fact. We require -- a newtype wrapper to avoid overlapping instances.-newtype WrapNE t f a = WrapNE { unwrapNE :: NonEmptyBy t f a }+newtype WrapNE t f a = WrapNE {unwrapNE :: NonEmptyBy t f a} instance Functor (NonEmptyBy t f) => Functor (WrapNE t f) where- fmap f (WrapNE x) = WrapNE (fmap f x)+ fmap f (WrapNE x) = WrapNE (fmap f x) instance Contravariant (NonEmptyBy t f) => Contravariant (WrapNE t f) where- contramap f (WrapNE x) = WrapNE (contramap f x)+ contramap f (WrapNE x) = WrapNE (contramap f x) instance Invariant (NonEmptyBy t f) => Invariant (WrapNE t f) where- invmap f g (WrapNE x) = WrapNE (invmap f g x)+ invmap f g (WrapNE x) = WrapNE (invmap f g x) instance (Associative t, FunctorBy t f, FunctorBy t (WrapNE t f)) => SemigroupIn (WrapHBF t) (WrapNE t f) where- biretract = WrapNE . appendNE . hbimap unwrapNE unwrapNE . unwrapHBF- binterpret f g = biretract . hbimap f g+ biretract = WrapNE . appendNE . hbimap unwrapNE unwrapNE . unwrapHBF+ binterpret f g = biretract . hbimap f g
src/Data/HBifunctor/Tensor.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Data.HBifunctor.Tensor--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -39,86 +39,88 @@ -- biretract :: 'Monad' f => 'Comp' f f a -> f a -- pureT :: Monad f => 'Identity' a -> f a -- @--- module Data.HBifunctor.Tensor ( -- * 'Tensor'- Tensor(..)- , rightIdentity- , leftIdentity- , sumLeftIdentity- , sumRightIdentity- , prodLeftIdentity- , prodRightIdentity+ Tensor (..),+ rightIdentity,+ leftIdentity,+ sumLeftIdentity,+ sumRightIdentity,+ prodLeftIdentity,+ prodRightIdentity,+ -- * 'MonoidIn'- , MonoidIn(..)- , nilLB- , consLB- , unconsLB- , retractLB- , interpretLB+ MonoidIn (..),+ nilLB,+ consLB,+ unconsLB,+ retractLB,+ interpretLB,+ -- ** Utility- , inL- , inR- , outL- , outR- , prodOutL- , prodOutR- , WrapF(..)- , WrapLB(..)+ inL,+ inR,+ outL,+ outR,+ prodOutL,+ prodOutR,+ WrapF (..),+ WrapLB (..),+ -- * 'Matchable'- , Matchable(..)- , splittingNE- , matchingLB- ) where+ Matchable (..),+ splittingNE,+ matchingLB,+) where -import Control.Applicative.Free-import Control.Applicative.ListF-import Control.Applicative.Step-import Control.Monad.Freer.Church-import Control.Monad.Trans.Compose-import Control.Natural-import Control.Natural.IsoF-import Data.Bifunctor-import Data.Coerce-import Data.Data-import Data.Function-import Data.Functor.Apply.Free-import Data.Functor.Bind-import Data.Functor.Classes-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Contravariant.Divisible.Free-import Data.Functor.Contravariant.Night (Night(..), Not(..))-import Data.Functor.Day (Day(..))-import Data.Functor.Identity-import Data.Functor.Invariant-import Data.Functor.Invariant.Internative-import Data.Functor.Invariant.Inplicative-import Data.Functor.Plus-import Data.Functor.Product-import Data.Functor.Sum-import Data.Functor.These-import Data.HBifunctor-import Data.HBifunctor.Associative-import Data.HBifunctor.Tensor.Internal-import Data.HFunctor-import Data.HFunctor.Chain.Internal-import Data.HFunctor.Internal-import Data.HFunctor.Interpret-import Data.List.NonEmpty (NonEmpty(..))-import Data.Void-import GHC.Generics-import qualified Data.Bifunctor.Assoc as B-import qualified Data.Functor.Contravariant.Coyoneda as CCY-import qualified Data.Functor.Contravariant.Day as CD-import qualified Data.Functor.Contravariant.Night as N-import qualified Data.Functor.Day as D-import qualified Data.Functor.Invariant.Day as ID-import qualified Data.Functor.Invariant.Night as IN-import qualified Data.Map.NonEmpty as NEM+import Control.Applicative.Free+import Control.Applicative.ListF+import Control.Applicative.Step+import Control.Monad.Freer.Church+import Control.Monad.Trans.Compose+import Control.Natural+import Control.Natural.IsoF+import Data.Bifunctor+import qualified Data.Bifunctor.Assoc as B+import Data.Coerce+import Data.Data+import Data.Function+import Data.Functor.Apply.Free+import Data.Functor.Bind+import Data.Functor.Classes+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import qualified Data.Functor.Contravariant.Coyoneda as CCY+import qualified Data.Functor.Contravariant.Day as CD+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Contravariant.Divisible.Free+import Data.Functor.Contravariant.Night (Night (..), Not (..))+import qualified Data.Functor.Contravariant.Night as N+import Data.Functor.Day (Day (..))+import qualified Data.Functor.Day as D+import Data.Functor.Identity+import Data.Functor.Invariant+import qualified Data.Functor.Invariant.Day as ID+import Data.Functor.Invariant.Inplicative+import Data.Functor.Invariant.Internative+import qualified Data.Functor.Invariant.Night as IN+import Data.Functor.Plus+import Data.Functor.Product+import Data.Functor.Sum+import Data.Functor.These+import Data.HBifunctor+import Data.HBifunctor.Associative+import Data.HBifunctor.Tensor.Internal+import Data.HFunctor+import Data.HFunctor.Chain.Internal+import Data.HFunctor.Internal+import Data.HFunctor.Interpret+import Data.List.NonEmpty (NonEmpty (..))+import qualified Data.Map.NonEmpty as NEM+import Data.Void+import GHC.Generics -- | @f@ is isomorphic to @t f i@: that is, @i@ is the identity of @t@, and -- leaves @f@ unchanged.@@ -127,7 +129,7 @@ -- | @g@ is isomorphic to @t i g@: that is, @i@ is the identity of @t@, and -- leaves @g@ unchanged.-leftIdentity :: (Tensor t i, FunctorBy t g) => g <~> t i g+leftIdentity :: (Tensor t i, FunctorBy t g) => g <~> t i g leftIdentity = isoF intro2 elim2 -- | 'leftIdentity' ('intro1' and 'elim1') for ':+:' actually does not@@ -228,28 +230,26 @@ -- -- This will prevent problems with overloaded instances. class (Tensor t i, SemigroupIn t f) => MonoidIn t i f where-- -- | If we have an @i@, we can generate an @f@ based on how it- -- interacts with @t@.- --- -- Specialized (and simplified), this type is:- --- -- @- -- 'pureT' \@'Day' :: 'Applicative' f => 'Identity' a -> f a -- 'pure'- -- pureT \@'Comp' :: 'Monad' f => Identity a -> f a -- 'return'- -- pureT \@(':*:') :: 'Plus' f => 'Proxy' a -> f a -- 'zero'- -- @- --- -- Note that because @t@ appears nowhere in the input or output types,- -- you must always use this with explicit type application syntax (like- -- @pureT \@Day@)- --- -- Along with 'biretract', this function makes @f@ a monoid in the- -- category of endofunctors with respect to tensor @t@.- pureT :: i ~> f-- default pureT :: Interpret (ListBy t) f => i ~> f- pureT = retract . reviewF (splittingLB @t) . L1+ -- | If we have an @i@, we can generate an @f@ based on how it+ -- interacts with @t@.+ --+ -- Specialized (and simplified), this type is:+ --+ -- @+ -- 'pureT' \@'Day' :: 'Applicative' f => 'Identity' a -> f a -- 'pure'+ -- pureT \@'Comp' :: 'Monad' f => Identity a -> f a -- 'return'+ -- pureT \@(':*:') :: 'Plus' f => 'Proxy' a -> f a -- 'zero'+ -- @+ --+ -- Note that because @t@ appears nowhere in the input or output types,+ -- you must always use this with explicit type application syntax (like+ -- @pureT \@Day@)+ --+ -- Along with 'biretract', this function makes @f@ a monoid in the+ -- category of endofunctors with respect to tensor @t@.+ pureT :: i ~> f+ default pureT :: Interpret (ListBy t) f => i ~> f+ pureT = retract . reviewF (splittingLB @t) . L1 -- | An implementation of 'retract' that works for any instance of -- @'MonoidIn' t i@ for @'ListBy' t@.@@ -257,8 +257,9 @@ -- Can be useful as a default implementation if you already have 'MonoidIn' -- implemented. retractLB :: forall t i f. MonoidIn t i f => ListBy t f ~> f-retractLB = (pureT @t !*! biretract @t . hright (retractLB @t))- . unconsLB @t+retractLB =+ (pureT @t !*! biretract @t . hright (retractLB @t))+ . unconsLB @t -- | An implementation of 'interpret' that works for any instance of -- @'MonoidIn' t i@ for @'ListBy' t@.@@ -272,18 +273,20 @@ -- functor @g@ to the right of an @f@. -- -- You can think of this as an 'HBifunctor' analogue of 'inject'.-inL- :: forall t i f g. MonoidIn t i g- => f ~> t f g+inL ::+ forall t i f g.+ MonoidIn t i g =>+ f ~> t f g inL = hright (pureT @t) . intro1 -- | Convenient wrapper over 'intro2' that lets us introduce an arbitrary -- functor @f@ to the right of a @g@. -- -- You can think of this as an 'HBifunctor' analogue of 'inject'.-inR- :: forall t i f g. MonoidIn t i f- => g ~> t f g+inR ::+ forall t i f g.+ MonoidIn t i f =>+ g ~> t f g inR = hleft (pureT @t) . intro2 -- | Convenient wrapper over 'elim1' that lets us drop one of the arguments@@ -292,9 +295,9 @@ -- -- See 'prodOutL' for a version that does not require @'Functor' f@, -- specifically for ':*:'.-outL- :: (Tensor t Proxy, FunctorBy t f)- => t f g ~> f+outL ::+ (Tensor t Proxy, FunctorBy t f) =>+ t f g ~> f outL = elim1 . hright absorb -- | Convenient wrapper over 'elim2' that lets us drop one of the arguments@@ -303,124 +306,125 @@ -- -- See 'prodOutR' for a version that does not require @'Functor' g@, -- specifically for ':*:'.-outR- :: (Tensor t Proxy, FunctorBy t g)- => t f g ~> g+outR ::+ (Tensor t Proxy, FunctorBy t g) =>+ t f g ~> g outR = elim2 . hleft absorb -- | For some @t@, we have the ability to "statically analyze" the @'ListBy' t@ -- and pattern match and manipulate the structure without ever -- interpreting or retracting. These are 'Matchable'. class Tensor t i => Matchable t i where- -- | The inverse of 'splitNE'. A consing of @f@ to @'ListBy' t f@ is- -- non-empty, so it can be represented as an @'NonEmptyBy' t f@.- --- -- This is analogous to a function @'uncurry' ('Data.List.NonEmpty.:|')- -- :: (a, [a]) -> 'Data.List.NonEmpty.NonEmpty' a@.- unsplitNE :: FunctorBy t f => t f (ListBy t f) ~> NonEmptyBy t f+ -- | The inverse of 'splitNE'. A consing of @f@ to @'ListBy' t f@ is+ -- non-empty, so it can be represented as an @'NonEmptyBy' t f@.+ --+ -- This is analogous to a function @'uncurry' ('Data.List.NonEmpty.:|')+ -- :: (a, [a]) -> 'Data.List.NonEmpty.NonEmpty' a@.+ unsplitNE :: FunctorBy t f => t f (ListBy t f) ~> NonEmptyBy t f - -- | "Pattern match" on an @'ListBy' t f@: it is either empty, or it is- -- non-empty (and so can be an @'NonEmptyBy' t f@).- --- -- This is analgous to a function @'Data.List.NonEmpty.nonEmpty' :: [a]- -- -> Maybe ('Data.List.NonEmpty.NonEmpty' a)@.- --- -- Note that because @t@ cannot be inferred from the input or output- -- type, you should use this with /-XTypeApplications/:- --- -- @- -- 'matchLB' \@'Day' :: 'Ap' f a -> ('Identity' :+: 'Ap1' f) a- -- @- --- -- Note that you can recursively "unroll" a 'ListBy' completely into- -- a 'Data.HFunctor.Chain.Chain' by using- -- 'Data.HFunctor.Chain.unrollLB'.- matchLB :: FunctorBy t f => ListBy t f ~> i :+: NonEmptyBy t f+ -- | "Pattern match" on an @'ListBy' t f@: it is either empty, or it is+ -- non-empty (and so can be an @'NonEmptyBy' t f@).+ --+ -- This is analgous to a function @'Data.List.NonEmpty.nonEmpty' :: [a]+ -- -> Maybe ('Data.List.NonEmpty.NonEmpty' a)@.+ --+ -- Note that because @t@ cannot be inferred from the input or output+ -- type, you should use this with /-XTypeApplications/:+ --+ -- @+ -- 'matchLB' \@'Day' :: 'Ap' f a -> ('Identity' :+: 'Ap1' f) a+ -- @+ --+ -- Note that you can recursively "unroll" a 'ListBy' completely into+ -- a 'Data.HFunctor.Chain.Chain' by using+ -- 'Data.HFunctor.Chain.unrollLB'.+ matchLB :: FunctorBy t f => ListBy t f ~> i :+: NonEmptyBy t f -- | An @'NonEmptyBy' t f@ is isomorphic to an @f@ consed with an @'ListBy' t f@, like -- how a @'Data.List.NonEmpty.NonEmpty' a@ is isomorphic to @(a, [a])@.-splittingNE- :: (Matchable t i, FunctorBy t f)- => NonEmptyBy t f <~> t f (ListBy t f)+splittingNE ::+ (Matchable t i, FunctorBy t f) =>+ NonEmptyBy t f <~> t f (ListBy t f) splittingNE = isoF splitNE unsplitNE -- | An @'ListBy' t f@ is isomorphic to either the empty case (@i@) or the -- non-empty case (@'NonEmptyBy' t f@), like how @[a]@ is isomorphic to @'Maybe' -- ('Data.List.NonEmpty.NonEmpty' a)@.-matchingLB- :: forall t i f. (Matchable t i, FunctorBy t f)- => ListBy t f <~> i :+: NonEmptyBy t f+matchingLB ::+ forall t i f.+ (Matchable t i, FunctorBy t f) =>+ ListBy t f <~> i :+: NonEmptyBy t f matchingLB = isoF (matchLB @t) (nilLB @t !*! fromNE @t) instance Tensor (:*:) Proxy where- type ListBy (:*:) = ListF- intro1 = (:*: Proxy)- intro2 = (Proxy :*:)- elim1 (x :*: ~Proxy) = x- elim2 (~Proxy :*: y ) = y+ type ListBy (:*:) = ListF+ intro1 = (:*: Proxy)+ intro2 = (Proxy :*:)+ elim1 (x :*: ~Proxy) = x+ elim2 (~Proxy :*: y) = y - appendLB (ListF xs :*: ListF ys) = ListF (xs ++ ys)- splitNE = nonEmptyProd- splittingLB = isoF to_ from_- where- to_ = \case- ListF [] -> L1 Proxy- ListF (x:xs) -> R1 (x :*: ListF xs)- from_ = \case- L1 ~Proxy -> ListF []- R1 (x :*: ListF xs) -> ListF (x:xs)+ appendLB (ListF xs :*: ListF ys) = ListF (xs ++ ys)+ splitNE = nonEmptyProd+ splittingLB = isoF to_ from_+ where+ to_ = \case+ ListF [] -> L1 Proxy+ ListF (x : xs) -> R1 (x :*: ListF xs)+ from_ = \case+ L1 ~Proxy -> ListF []+ R1 (x :*: ListF xs) -> ListF (x : xs) - toListBy (x :*: y) = ListF [x, y]+ toListBy (x :*: y) = ListF [x, y] -- | Instances of 'Plus' are monoids in the monoidal category on -- ':*:'. instance Plus f => MonoidIn (:*:) Proxy f where- pureT _ = zero+ pureT _ = zero instance Tensor Product Proxy where- type ListBy Product = ListF- intro1 = (`Pair` Proxy)- intro2 = (Proxy `Pair`)- elim1 (Pair x ~Proxy) = x- elim2 (Pair ~Proxy y) = y+ type ListBy Product = ListF+ intro1 = (`Pair` Proxy)+ intro2 = (Proxy `Pair`)+ elim1 (Pair x ~Proxy) = x+ elim2 (Pair ~Proxy y) = y - appendLB (ListF xs `Pair` ListF ys) = ListF (xs ++ ys)- splitNE = viewF prodProd . nonEmptyProd- splittingLB = isoF to_ from_- where- to_ = \case- ListF [] -> L1 Proxy- ListF (x:xs) -> R1 (x `Pair` ListF xs)- from_ = \case- L1 ~Proxy -> ListF []- R1 (x `Pair` ListF xs) -> ListF (x:xs)+ appendLB (ListF xs `Pair` ListF ys) = ListF (xs ++ ys)+ splitNE = viewF prodProd . nonEmptyProd+ splittingLB = isoF to_ from_+ where+ to_ = \case+ ListF [] -> L1 Proxy+ ListF (x : xs) -> R1 (x `Pair` ListF xs)+ from_ = \case+ L1 ~Proxy -> ListF []+ R1 (x `Pair` ListF xs) -> ListF (x : xs) - toListBy (Pair x y) = ListF [x, y]+ toListBy (Pair x y) = ListF [x, y] -- | Instances of 'Plus' are monoids in the monoidal category on -- 'Product'. instance Plus f => MonoidIn Product Proxy f where- pureT _ = zero+ pureT _ = zero instance Tensor Day Identity where- type ListBy Day = Ap- intro1 = D.intro2- intro2 = D.intro1- elim1 = D.elim2- elim2 = D.elim1+ type ListBy Day = Ap+ intro1 = D.intro2+ intro2 = D.intro1+ elim1 = D.elim2+ elim2 = D.elim1 - appendLB (Day x y z) = z <$> x <*> y- splitNE = ap1Day- splittingLB = isoF to_ from_- where- to_ = \case- Pure x -> L1 (Identity x)- Ap x xs -> R1 (Day x xs (&))- from_ = \case- L1 (Identity x) -> Pure x- R1 (Day x xs f) -> Ap x (flip f <$> xs)+ appendLB (Day x y z) = z <$> x <*> y+ splitNE = ap1Day+ splittingLB = isoF to_ from_+ where+ to_ = \case+ Pure x -> L1 (Identity x)+ Ap x xs -> R1 (Day x xs (&))+ from_ = \case+ L1 (Identity x) -> Pure x+ R1 (Day x xs f) -> Ap x (flip f <$> xs) - toListBy (Day x y z) = Ap x (Ap y (Pure (flip z)))+ toListBy (Day x y z) = Ap x (Ap y (Pure (flip z))) -- | Instances of 'Applicative' are monoids in the monoidal category on -- the covariant 'Day'.@@ -430,27 +434,28 @@ -- for any 'Applicative' using -- 'Data.Functor.Combinators.Unsafe.unsafeApply'. instance (Apply f, Applicative f) => MonoidIn Day Identity f where- pureT = generalize+ pureT = generalize -- | @since 0.3.0.0 instance Tensor CD.Day Proxy where- type ListBy CD.Day = Div- intro1 = CD.intro2- intro2 = CD.intro1- elim1 = CD.day1- elim2 = CD.day2+ type ListBy CD.Day = Div+ intro1 = CD.intro2+ intro2 = CD.intro1+ elim1 = CD.day1+ elim2 = CD.day2 - appendLB (CD.Day x y z) = divide z x y- splitNE = go . splitNE @(:*:) . NonEmptyF . unDiv1- where- go (CCY.Coyoneda f x :*: ListF xs) = CD.Day x (Div xs) (\y -> (f y, y))- splittingLB = isoF (ListF . unDiv) (Div . runListF) . splittingLB @(:*:) . isoF (hright to_) (hright from_)- where- to_ (CCY.Coyoneda f x :*: ListF xs) = CD.Day x (Div xs) (\y -> (f y, y))- from_ (CD.Day x (Div xs) f) = CCY.Coyoneda (fst . f) x :*: contramap (snd . f) (ListF xs)+ appendLB (CD.Day x y z) = divide z x y+ splitNE = go . splitNE @(:*:) . NonEmptyF . unDiv1+ where+ go (CCY.Coyoneda f x :*: ListF xs) = CD.Day x (Div xs) (\y -> (f y, y))+ splittingLB = isoF (ListF . unDiv) (Div . runListF) . splittingLB @(:*:) . isoF (hright to_) (hright from_)+ where+ to_ (CCY.Coyoneda f x :*: ListF xs) = CD.Day x (Div xs) (\y -> (f y, y))+ from_ (CD.Day x (Div xs) f) = CCY.Coyoneda (fst . f) x :*: contramap (snd . f) (ListF xs) - toListBy (CD.Day x y f) = Div . runListF . toListBy $- CCY.Coyoneda (fst . f) x :*: CCY.Coyoneda (snd . f) y+ toListBy (CD.Day x y f) =+ Div . runListF . toListBy $+ CCY.Coyoneda (fst . f) x :*: CCY.Coyoneda (snd . f) y -- | Instances of 'Divisible' are monoids in the monoidal category on -- contravariant 'CD.Day'.@@ -462,210 +467,216 @@ -- -- @since 0.3.0.0 instance (Divise f, Divisible f) => MonoidIn CD.Day Proxy f where- pureT _ = conquer+ pureT _ = conquer instance Tensor ID.Day Identity where- type ListBy ID.Day = DivAp+ type ListBy ID.Day = DivAp - intro1 = ID.intro2- intro2 = ID.intro1- elim1 = ID.elim2- elim2 = ID.elim1+ intro1 = ID.intro2+ intro2 = ID.intro1+ elim1 = ID.elim2+ elim2 = ID.elim1 - appendLB (ID.Day (DivAp xs) (DivAp ys) f g) = DivAp $ case xs of- Done (Identity x) -> invmap (f x) (snd . g) ys- More (ID.Day z zs h j) -> More $ ID.Day- z- (unDivAp $ appendLB (ID.Day (DivAp zs) (DivAp ys) (,) id))- (\q (r, s) -> f (h q r) s)- (B.assoc . first j . g)+ appendLB (ID.Day (DivAp xs) (DivAp ys) f g) = DivAp $ case xs of+ Done (Identity x) -> invmap (f x) (snd . g) ys+ More (ID.Day z zs h j) ->+ More $+ ID.Day+ z+ (unDivAp $ appendLB (ID.Day (DivAp zs) (DivAp ys) (,) id))+ (\q (r, s) -> f (h q r) s)+ (B.assoc . first j . g) - splitNE = coerce splitChain1- splittingLB = coercedF . splittingChain . coercedF+ splitNE = coerce splitChain1+ splittingLB = coercedF . splittingChain . coercedF - toListBy = DivAp . More . hright (unDivAp . inject)+ toListBy = DivAp . More . hright (unDivAp . inject) instance Matchable ID.Day Identity where- unsplitNE = coerce unsplitNEIDay_- matchLB = coerce matchLBIDay_+ unsplitNE = coerce unsplitNEIDay_+ matchLB = coerce matchLBIDay_ unsplitNEIDay_ :: Invariant f => ID.Day f (Chain ID.Day Identity f) ~> Chain1 ID.Day f unsplitNEIDay_ (ID.Day x xs g f) = case xs of Done (Identity r) -> Done1 $ invmap (`g` r) (fst . f) x- More ys -> More1 $ ID.Day x (unsplitNEIDay_ ys) g f+ More ys -> More1 $ ID.Day x (unsplitNEIDay_ ys) g f matchLBIDay_ :: Invariant f => Chain ID.Day Identity f ~> (Identity :+: Chain1 ID.Day f) matchLBIDay_ = \case- Done x -> L1 x+ Done x -> L1 x More xs -> R1 $ unsplitNEIDay_ xs instance Inplicative f => MonoidIn ID.Day Identity f where- pureT (Identity x) = knot x+ pureT (Identity x) = knot x instance Tensor IN.Night IN.Not where- type ListBy IN.Night = DecAlt+ type ListBy IN.Night = DecAlt - intro1 = IN.intro2- intro2 = IN.intro1- elim1 = IN.elim2- elim2 = IN.elim1+ intro1 = IN.intro2+ intro2 = IN.intro1+ elim1 = IN.elim2+ elim2 = IN.elim1 - appendLB (IN.Night (DecAlt xs) (DecAlt ys) f g h) = DecAlt $ case xs of- Done r -> invmap g (either (absurd . refute r) id . h) ys- More (IN.Night z zs j k l) -> More $ IN.Night- z- (unDecAlt $ appendLB (IN.Night (DecAlt zs) (DecAlt ys) Left Right id))- (f . j)- (either (f . k) g)- (B.assoc . first l . h)- splitNE = coerce splitChain1- splittingLB = coercedF . splittingChain . coercedF+ appendLB (IN.Night (DecAlt xs) (DecAlt ys) f g h) = DecAlt $ case xs of+ Done r -> invmap g (either (absurd . refute r) id . h) ys+ More (IN.Night z zs j k l) ->+ More $+ IN.Night+ z+ (unDecAlt $ appendLB (IN.Night (DecAlt zs) (DecAlt ys) Left Right id))+ (f . j)+ (either (f . k) g)+ (B.assoc . first l . h)+ splitNE = coerce splitChain1+ splittingLB = coercedF . splittingChain . coercedF - toListBy = DecAlt . More . hright (unDecAlt . inject)+ toListBy = DecAlt . More . hright (unDecAlt . inject) instance Matchable IN.Night Not where- unsplitNE = coerce unsplitNEINight_- matchLB = coerce matchLBINight_+ unsplitNE = coerce unsplitNEINight_+ matchLB = coerce matchLBINight_ unsplitNEINight_ :: Invariant f => IN.Night f (Chain IN.Night Not f) ~> Chain1 IN.Night f unsplitNEINight_ (IN.Night x xs f g h) = case xs of- Done r -> Done1 $ invmap f (either id (absurd . refute r) . h) x+ Done r -> Done1 $ invmap f (either id (absurd . refute r) . h) x More ys -> More1 $ IN.Night x (unsplitNEINight_ ys) f g h matchLBINight_ :: Invariant f => Chain IN.Night Not f ~> (Not :+: Chain1 IN.Night f) matchLBINight_ = \case- Done x -> L1 x+ Done x -> L1 x More xs -> R1 $ unsplitNEINight_ xs -- | @since 0.4.0.0 instance Inplus f => MonoidIn IN.Night IN.Not f where- pureT (Not x) = reject x+ pureT (Not x) = reject x -- | @since 0.3.0.0 instance Tensor Night Not where- type ListBy Night = Dec- intro1 = N.intro2- intro2 = N.intro1- elim1 = N.elim2- elim2 = N.elim1+ type ListBy Night = Dec+ intro1 = N.intro2+ intro2 = N.intro1+ elim1 = N.elim2+ elim2 = N.elim1 - appendLB (Night x y z) = decide z x y- splitNE (Dec1 f x xs) = Night x xs f- splittingLB = isoF to_ from_- where- to_ = \case- Lose f -> L1 (Not f)- Choose f x xs -> R1 (Night x xs f)- from_ = \case- L1 (Not f) -> Lose f- R1 (Night x xs f) -> Choose f x xs+ appendLB (Night x y z) = decide z x y+ splitNE (Dec1 f x xs) = Night x xs f+ splittingLB = isoF to_ from_+ where+ to_ = \case+ Lose f -> L1 (Not f)+ Choose f x xs -> R1 (Night x xs f)+ from_ = \case+ L1 (Not f) -> Lose f+ R1 (Night x xs f) -> Choose f x xs - toListBy (Night x y z) = Choose z x (inject y)+ toListBy (Night x y z) = Choose z x (inject y) -- | Instances of 'Conclude' are monoids in the monoidal category on 'Night'. instance Conclude f => MonoidIn Night Not f where- pureT (Not x) = conclude x+ pureT (Not x) = conclude x instance Tensor (:+:) V1 where- type ListBy (:+:) = Step- intro1 = L1- intro2 = R1+ type ListBy (:+:) = Step+ intro1 = L1+ intro2 = R1 - elim1 = \case- L1 x -> x- R1 y -> absurd1 y- elim2 = \case- L1 x -> absurd1 x- R1 y -> y+ elim1 = \case+ L1 x -> x+ R1 y -> absurd1 y+ elim2 = \case+ L1 x -> absurd1 x+ R1 y -> y - appendLB = id !*! stepUp . R1- splitNE = stepDown- splittingLB = stepping . sumLeftIdentity+ appendLB = id !*! stepUp . R1+ splitNE = stepDown+ splittingLB = stepping . sumLeftIdentity - toListBy = \case- L1 x -> Step 0 x- R1 x -> Step 1 x+ toListBy = \case+ L1 x -> Step 0 x+ R1 x -> Step 1 x -- | All functors are monoids in the monoidal category on ':+:'. instance MonoidIn (:+:) V1 f where- pureT = absurd1+ pureT = absurd1 instance Tensor Sum V1 where- type ListBy Sum = Step- intro1 = InL- intro2 = InR+ type ListBy Sum = Step+ intro1 = InL+ intro2 = InR - elim1 = \case- InL x -> x- InR y -> absurd1 y- elim2 = \case- InL x -> absurd1 x- InR y -> y+ elim1 = \case+ InL x -> x+ InR y -> absurd1 y+ elim2 = \case+ InL x -> absurd1 x+ InR y -> y - appendLB = id !*! stepUp . R1- splitNE = viewF sumSum . stepDown- splittingLB = stepping- . sumLeftIdentity- . overHBifunctor id sumSum+ appendLB = id !*! stepUp . R1+ splitNE = viewF sumSum . stepDown+ splittingLB =+ stepping+ . sumLeftIdentity+ . overHBifunctor id sumSum - toListBy = \case- InL x -> Step 0 x- InR x -> Step 1 x+ toListBy = \case+ InL x -> Step 0 x+ InR x -> Step 1 x -- | All functors are monoids in the monoidal category on 'Sum'. instance MonoidIn Sum V1 f where- pureT = absurd1-+ pureT = absurd1 instance Tensor These1 V1 where- type ListBy These1 = Steps- intro1 = This1- intro2 = That1- elim1 = \case- This1 x -> x- That1 y -> absurd1 y- These1 _ y -> absurd1 y- elim2 = \case- This1 x -> absurd1 x- That1 y -> y- These1 x _ -> absurd1 x+ type ListBy These1 = Steps+ intro1 = This1+ intro2 = That1+ elim1 = \case+ This1 x -> x+ That1 y -> absurd1 y+ These1 _ y -> absurd1 y+ elim2 = \case+ This1 x -> absurd1 x+ That1 y -> y+ These1 x _ -> absurd1 x - appendLB = \case- This1 x -> x- That1 y -> stepsUp . That1 $ y- These1 x y -> x <> y- splitNE = stepsDown . flaggedVal . getComposeT- splittingLB = steppings . sumLeftIdentity+ appendLB = \case+ This1 x -> x+ That1 y -> stepsUp . That1 $ y+ These1 x y -> x <> y+ splitNE = stepsDown . flaggedVal . getComposeT+ splittingLB = steppings . sumLeftIdentity - toListBy = \case- This1 x -> Steps $ NEM.singleton 0 x- That1 y -> Steps $ NEM.singleton 1 y- These1 x y -> Steps $ NEM.fromDistinctAscList ((0, x) :| [(1, y)])+ toListBy = \case+ This1 x -> Steps $ NEM.singleton 0 x+ That1 y -> Steps $ NEM.singleton 1 y+ These1 x y -> Steps $ NEM.fromDistinctAscList ((0, x) :| [(1, y)]) instance Alt f => MonoidIn These1 V1 f where- pureT = absurd1+ pureT = absurd1 instance Tensor Comp Identity where- type ListBy Comp = Free+ type ListBy Comp = Free - intro1 = (:>>= Identity)- intro2 = (Identity () :>>=) . const+ intro1 = (:>>= Identity)+ intro2 = (Identity () :>>=) . const - elim1 (x :>>= y) = runIdentity . y <$> x- elim2 (x :>>= y) = y (runIdentity x)+ elim1 (x :>>= y) = runIdentity . y <$> x+ elim2 (x :>>= y) = y (runIdentity x) - appendLB (x :>>= y) = x >>= y- splitNE = free1Comp- splittingLB = isoF to_ from_- where- to_ :: Free f ~> Identity :+: Comp f (Free f)- to_ = foldFree' (L1 . Identity) $ \y n -> R1 $- y :>>= (from_ . n)- from_ :: Identity :+: Comp f (Free f) ~> Free f- from_ = generalize- !*! (\case x :>>= f -> liftFree x >>= f)+ appendLB (x :>>= y) = x >>= y+ splitNE = free1Comp+ splittingLB = isoF to_ from_+ where+ to_ :: Free f ~> Identity :+: Comp f (Free f)+ to_ = foldFree' (L1 . Identity) $ \y n ->+ R1 $+ y :>>= (from_ . n)+ from_ :: Identity :+: Comp f (Free f) ~> Free f+ from_ =+ generalize+ !*! (\case x :>>= f -> liftFree x >>= f) - toListBy (x :>>= y) = liftFree x >>= (inject . y)+ toListBy (x :>>= y) = liftFree x >>= (inject . y) -- | Instances of 'Monad' are monoids in the monoidal category on -- 'Comp'.@@ -678,42 +689,43 @@ -- for any 'Monad' using -- 'Data.Functor.Combinators.Unsafe.unsafeBind'. instance (Bind f, Monad f) => MonoidIn Comp Identity f where- pureT = generalize+ pureT = generalize instance Matchable (:*:) Proxy where- unsplitNE = ProdNonEmpty- matchLB = fromListF+ unsplitNE = ProdNonEmpty+ matchLB = fromListF instance Matchable Product Proxy where- unsplitNE = ProdNonEmpty . reviewF prodProd- matchLB = fromListF+ unsplitNE = ProdNonEmpty . reviewF prodProd+ matchLB = fromListF instance Matchable Day Identity where- unsplitNE = DayAp1- matchLB = fromAp+ unsplitNE = DayAp1+ matchLB = fromAp -- | Instances of 'Conclude' are monoids in the monoidal category on 'Night'. -- -- @since 0.3.0.0 instance Matchable CD.Day Proxy where- unsplitNE (CD.Day x (Div xs) f) = Div1 . runNonEmptyF . unsplitNE $+ unsplitNE (CD.Day x (Div xs) f) =+ Div1 . runNonEmptyF . unsplitNE $ CCY.Coyoneda (fst . f) x :*: contramap (snd . f) (ListF xs)- matchLB = hright (Div1 . runNonEmptyF) . matchLB @(:*:) . ListF . unDiv+ matchLB = hright (Div1 . runNonEmptyF) . matchLB @(:*:) . ListF . unDiv -- | @since 0.3.0.0 instance Matchable Night Not where- unsplitNE (Night x xs f) = Dec1 f x xs- matchLB = \case- Lose f -> L1 (Not f)- Choose f x xs -> R1 (Dec1 f x xs)+ unsplitNE (Night x xs f) = Dec1 f x xs+ matchLB = \case+ Lose f -> L1 (Not f)+ Choose f x xs -> R1 (Dec1 f x xs) instance Matchable (:+:) V1 where- unsplitNE = stepUp- matchLB = R1+ unsplitNE = stepUp+ matchLB = R1 instance Matchable Sum V1 where- unsplitNE = stepUp . reviewF sumSum- matchLB = R1+ unsplitNE = stepUp . reviewF sumSum+ matchLB = R1 -- We can't write this until we get an isomorphism between MF These1 and SF These1 -- instance Matchable These1 where@@ -731,51 +743,52 @@ -- @ -- -- As that would globally ruin everything using 'WrapHBF'.-newtype WrapF f a = WrapF { unwrapF :: f a }+newtype WrapF f a = WrapF {unwrapF :: f a} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) instance Show1 f => Show1 (WrapF f) where- liftShowsPrec sp sl d (WrapF x) = showsUnaryWith (liftShowsPrec sp sl) "WrapF" d x+ liftShowsPrec sp sl d (WrapF x) = showsUnaryWith (liftShowsPrec sp sl) "WrapF" d x instance Eq1 f => Eq1 (WrapF f) where- liftEq eq (WrapF x) (WrapF y) = liftEq eq x y+ liftEq eq (WrapF x) (WrapF y) = liftEq eq x y instance Ord1 f => Ord1 (WrapF f) where- liftCompare c (WrapF x) (WrapF y) = liftCompare c x y+ liftCompare c (WrapF x) (WrapF y) = liftCompare c x y instance Tensor t i => Tensor (WrapHBF t) (WrapF i) where- type ListBy (WrapHBF t) = ListBy t+ type ListBy (WrapHBF t) = ListBy t - intro1 = WrapHBF . hright WrapF . intro1- intro2 = WrapHBF . hleft WrapF . intro2- elim1 = elim1 . hright unwrapF . unwrapHBF- elim2 = elim2 . hleft unwrapF . unwrapHBF- appendLB = appendLB . unwrapHBF- splitNE = WrapHBF . splitNE- splittingLB = splittingLB @t- . overHBifunctor (isoF WrapF unwrapF) (isoF WrapHBF unwrapHBF)- toListBy = toListBy . unwrapHBF- fromNE = fromNE @t+ intro1 = WrapHBF . hright WrapF . intro1+ intro2 = WrapHBF . hleft WrapF . intro2+ elim1 = elim1 . hright unwrapF . unwrapHBF+ elim2 = elim2 . hleft unwrapF . unwrapHBF+ appendLB = appendLB . unwrapHBF+ splitNE = WrapHBF . splitNE+ splittingLB =+ splittingLB @t+ . overHBifunctor (isoF WrapF unwrapF) (isoF WrapHBF unwrapHBF)+ toListBy = toListBy . unwrapHBF+ fromNE = fromNE @t -- | Any @'ListBy' t f@ is a @'SemigroupIn' t@ and a @'MonoidIn' t i@, if we -- have @'Tensor' t i@. This newtype wrapper witnesses that fact. We -- require a newtype wrapper to avoid overlapping instances.-newtype WrapLB t f a = WrapLB { unwrapLB :: ListBy t f a }+newtype WrapLB t f a = WrapLB {unwrapLB :: ListBy t f a} instance Functor (ListBy t f) => Functor (WrapLB t f) where- fmap f (WrapLB x) = WrapLB (fmap f x)+ fmap f (WrapLB x) = WrapLB (fmap f x) -- | @since 0.3.0.0 instance Contravariant (ListBy t f) => Contravariant (WrapLB t f) where- contramap f (WrapLB x) = WrapLB (contramap f x)+ contramap f (WrapLB x) = WrapLB (contramap f x) -- | @since 0.3.0.0 instance Invariant (ListBy t f) => Invariant (WrapLB t f) where- invmap f g (WrapLB x) = WrapLB (invmap f g x)+ invmap f g (WrapLB x) = WrapLB (invmap f g x) instance (Tensor t i, FunctorBy t f, FunctorBy t (WrapLB t f)) => SemigroupIn (WrapHBF t) (WrapLB t f) where- biretract = WrapLB . appendLB . hbimap unwrapLB unwrapLB . unwrapHBF- binterpret f g = biretract . hbimap f g+ biretract = WrapLB . appendLB . hbimap unwrapLB unwrapLB . unwrapHBF+ binterpret f g = biretract . hbimap f g instance (Tensor t i, FunctorBy t f, FunctorBy t (WrapLB t f)) => MonoidIn (WrapHBF t) (WrapF i) (WrapLB t f) where- pureT = WrapLB . nilLB @t . unwrapF+ pureT = WrapLB . nilLB @t . unwrapF
src/Data/HBifunctor/Tensor/Internal.hs view
@@ -1,26 +1,25 @@ {-# OPTIONS_HADDOCK hide, not-home #-} module Data.HBifunctor.Tensor.Internal (- Tensor(..)- , unconsLB- , nilLB- , consLB- , appendChain- , unroll- , reroll- , rerollNE- , splitChain1- ) where--import Control.Natural-import Control.Natural.IsoF-import Data.HBifunctor-import Data.HBifunctor.Associative-import Data.HFunctor-import Data.HFunctor.Chain.Internal-import Data.Kind-import GHC.Generics+ Tensor (..),+ unconsLB,+ nilLB,+ consLB,+ appendChain,+ unroll,+ reroll,+ rerollNE,+ splitChain1,+) where +import Control.Natural+import Control.Natural.IsoF+import Data.HBifunctor+import Data.HBifunctor.Associative+import Data.HFunctor+import Data.HFunctor.Chain.Internal+import Data.Kind+import GHC.Generics -- | An 'Associative' 'HBifunctor' can be a 'Tensor' if there is some -- identity @i@ where @t i f@ and @t f i@ are equivalent to just @f@.@@ -40,105 +39,106 @@ -- Different instances of @t@ each enrich the endofunctor category in -- different ways, giving a different monoidal category. class (Associative t, Inject (ListBy t)) => Tensor t i | t -> i where- -- | The "monoidal functor combinator" induced by @t@.- --- -- A value of type @ListBy t f a@ is /equivalent/ to one of:- --- -- * @I a@ -- zero fs- -- * @f a@ -- one f- -- * @t f f a@ -- two fs- -- * @t f (t f f) a@ -- three fs- -- * @t f (t f (t f f)) a@- -- * @t f (t f (t f (t f f))) a@- -- * .. etc- --- -- For example, for ':*:', we have 'ListF'. This is because:- --- -- @- -- 'Proxy' ~ 'ListF' [] ~ 'nilLB' \@(':*:')- -- x ~ ListF [x] ~ 'inject' x- -- x :*: y ~ ListF [x,y] ~ 'toListBy' (x :*: y)- -- x :*: y :*: z ~ ListF [x,y,z]- -- -- etc.- -- @- --- -- You can create an "empty" one with 'nilLB', a "singleton" one with- -- 'inject', or else one from a single @t f f@ with 'toListBy'.- --- -- See 'Data.HBifunctor.Associative.NonEmptyBy' for a "non-empty"- -- version of this type.- type ListBy t :: (Type -> Type) -> Type -> Type+ -- | The "monoidal functor combinator" induced by @t@.+ --+ -- A value of type @ListBy t f a@ is /equivalent/ to one of:+ --+ -- * @I a@ -- zero fs+ -- * @f a@ -- one f+ -- * @t f f a@ -- two fs+ -- * @t f (t f f) a@ -- three fs+ -- * @t f (t f (t f f)) a@+ -- * @t f (t f (t f (t f f))) a@+ -- * .. etc+ --+ -- For example, for ':*:', we have 'ListF'. This is because:+ --+ -- @+ -- 'Proxy' ~ 'ListF' [] ~ 'nilLB' \@(':*:')+ -- x ~ ListF [x] ~ 'inject' x+ -- x :*: y ~ ListF [x,y] ~ 'toListBy' (x :*: y)+ -- x :*: y :*: z ~ ListF [x,y,z]+ -- -- etc.+ -- @+ --+ -- You can create an "empty" one with 'nilLB', a "singleton" one with+ -- 'inject', or else one from a single @t f f@ with 'toListBy'.+ --+ -- See 'Data.HBifunctor.Associative.NonEmptyBy' for a "non-empty"+ -- version of this type.+ type ListBy t :: (Type -> Type) -> Type -> Type - -- | Because @t f (I t)@ is equivalent to @f@, we can always "insert"- -- @f@ into @t f (I t)@.- --- -- This is analogous to 'inject' from 'Inject', but for 'HBifunctor's.- intro1 :: f ~> t f i+ -- | Because @t f (I t)@ is equivalent to @f@, we can always "insert"+ -- @f@ into @t f (I t)@.+ --+ -- This is analogous to 'inject' from 'Inject', but for 'HBifunctor's.+ intro1 :: f ~> t f i - -- | Because @t (I t) g@ is equivalent to @f@, we can always "insert"- -- @g@ into @t (I t) g@.- --- -- This is analogous to 'inject' from 'Inject', but for 'HBifunctor's.- intro2 :: g ~> t i g+ -- | Because @t (I t) g@ is equivalent to @f@, we can always "insert"+ -- @g@ into @t (I t) g@.+ --+ -- This is analogous to 'inject' from 'Inject', but for 'HBifunctor's.+ intro2 :: g ~> t i g - -- | Witnesses the property that @i@ is the identity of @t@: @t- -- f i@ always leaves @f@ unchanged, so we can always just drop the- -- @i@.- elim1 :: FunctorBy t f => t f i ~> f+ -- | Witnesses the property that @i@ is the identity of @t@: @t+ -- f i@ always leaves @f@ unchanged, so we can always just drop the+ -- @i@.+ elim1 :: FunctorBy t f => t f i ~> f - -- | Witnesses the property that @i@ is the identity of @t@: @t i g@- -- always leaves @g@ unchanged, so we can always just drop the @i t@.- elim2 :: FunctorBy t g => t i g ~> g+ -- | Witnesses the property that @i@ is the identity of @t@: @t i g@+ -- always leaves @g@ unchanged, so we can always just drop the @i t@.+ elim2 :: FunctorBy t g => t i g ~> g - -- | If a @'ListBy' t f@ represents multiple applications of @t f@ to- -- itself, then we can also "append" two @'ListBy' t f@s applied to- -- themselves into one giant @'ListBy' t f@ containing all of the @t f@s.- --- -- Note that this essentially gives an instance for @'SemigroupIn'- -- t (ListBy t f)@, for any functor @f@; this is witnessed by- -- 'WrapLB'.- appendLB :: t (ListBy t f) (ListBy t f) ~> ListBy t f+ -- | If a @'ListBy' t f@ represents multiple applications of @t f@ to+ -- itself, then we can also "append" two @'ListBy' t f@s applied to+ -- themselves into one giant @'ListBy' t f@ containing all of the @t f@s.+ --+ -- Note that this essentially gives an instance for @'SemigroupIn'+ -- t (ListBy t f)@, for any functor @f@; this is witnessed by+ -- 'WrapLB'.+ appendLB :: t (ListBy t f) (ListBy t f) ~> ListBy t f - -- | Lets you convert an @'NonEmptyBy' t f@ into a single application of @f@ to- -- @'ListBy' t f@.- --- -- Analogous to a function @'Data.List.NonEmpty.NonEmpty' a -> (a,- -- [a])@- --- -- Note that this is not reversible in general unless we have- -- @'Matchable' t@.- splitNE :: NonEmptyBy t f ~> t f (ListBy t f)+ -- | Lets you convert an @'NonEmptyBy' t f@ into a single application of @f@ to+ -- @'ListBy' t f@.+ --+ -- Analogous to a function @'Data.List.NonEmpty.NonEmpty' a -> (a,+ -- [a])@+ --+ -- Note that this is not reversible in general unless we have+ -- @'Matchable' t@.+ splitNE :: NonEmptyBy t f ~> t f (ListBy t f) - -- | An @'ListBy' t f@ is either empty, or a single application of @t@ to @f@- -- and @ListBy t f@ (the "head" and "tail"). This witnesses that- -- isomorphism.- --- -- To /use/ this property, see 'nilLB', 'consLB', and 'unconsLB'.- splittingLB :: ListBy t f <~> i :+: t f (ListBy t f)+ -- | An @'ListBy' t f@ is either empty, or a single application of @t@ to @f@+ -- and @ListBy t f@ (the "head" and "tail"). This witnesses that+ -- isomorphism.+ --+ -- To /use/ this property, see 'nilLB', 'consLB', and 'unconsLB'.+ splittingLB :: ListBy t f <~> i :+: t f (ListBy t f) - -- | Embed a direct application of @f@ to itself into a @'ListBy' t f@.- toListBy :: t f f ~> ListBy t f- toListBy = reviewF (splittingLB @t)- . R1- . hright (inject @(ListBy t))+ -- | Embed a direct application of @f@ to itself into a @'ListBy' t f@.+ toListBy :: t f f ~> ListBy t f+ toListBy =+ reviewF (splittingLB @t)+ . R1+ . hright (inject @(ListBy t)) - -- | @'NonEmptyBy' t f@ is "one or more @f@s", and @'ListBy t f@ is "zero or more- -- @f@s". This function lets us convert from one to the other.- --- -- This is analogous to a function @'Data.List.NonEmpty.NonEmpty' a ->- -- [a]@.- --- -- Note that because @t@ is not inferrable from the input or output- -- type, you should call this using /-XTypeApplications/:- --- -- @- -- 'fromNE' \@(':*:') :: 'NonEmptyF' f a -> 'ListF' f a- -- fromNE \@'Comp' :: 'Free1' f a -> 'Free' f a- -- @- fromNE :: NonEmptyBy t f ~> ListBy t f- fromNE = reviewF (splittingLB @t) . R1 . splitNE @t+ -- | @'NonEmptyBy' t f@ is "one or more @f@s", and @'ListBy t f@ is "zero or more+ -- @f@s". This function lets us convert from one to the other.+ --+ -- This is analogous to a function @'Data.List.NonEmpty.NonEmpty' a ->+ -- [a]@.+ --+ -- Note that because @t@ is not inferrable from the input or output+ -- type, you should call this using /-XTypeApplications/:+ --+ -- @+ -- 'fromNE' \@(':*:') :: 'NonEmptyF' f a -> 'ListF' f a+ -- fromNE \@'Comp' :: 'Free1' f a -> 'Free' f a+ -- @+ fromNE :: NonEmptyBy t f ~> ListBy t f+ fromNE = reviewF (splittingLB @t) . R1 . splitNE @t - {-# MINIMAL intro1, intro2, elim1, elim2, appendLB, splitNE, splittingLB #-}+ {-# MINIMAL intro1, intro2, elim1, elim2, appendLB, splitNE, splittingLB #-} -- | Create the "empty 'ListBy'". --@@ -156,12 +156,12 @@ -- -- Note that this essentially gives an instance for @'MonoidIn' t i (ListBy -- t f)@, for any functor @f@; this is witnessed by 'WrapLB'.-nilLB :: forall t i f. Tensor t i => i ~> ListBy t f-nilLB = reviewF (splittingLB @t) . L1+nilLB :: forall t i f. Tensor t i => i ~> ListBy t f+nilLB = reviewF (splittingLB @t) . L1 -- | Lets us "cons" an application of @f@ to the front of an @'ListBy' t f@.-consLB :: Tensor t i => t f (ListBy t f) ~> ListBy t f-consLB = reviewF splittingLB . R1+consLB :: Tensor t i => t f (ListBy t f) ~> ListBy t f+consLB = reviewF splittingLB . R1 -- | "Pattern match" on an @'ListBy' t@ --@@ -173,7 +173,6 @@ unconsLB :: Tensor t i => ListBy t f ~> i :+: t f (ListBy t f) unconsLB = viewF splittingLB - -- | 'Chain' is a monoid with respect to @t@: we can "combine" them in -- an associative way. The identity here is anything made with the 'Done' -- constructor.@@ -183,12 +182,14 @@ -- 'pureT' is 'Done'. -- -- @since 0.1.1.0-appendChain- :: forall t i f. Tensor t i- => t (Chain t i f) (Chain t i f) ~> Chain t i f-appendChain = unroll- . appendLB- . hbimap reroll reroll+appendChain ::+ forall t i f.+ Tensor t i =>+ t (Chain t i f) (Chain t i f) ~> Chain t i f+appendChain =+ unroll+ . appendLB+ . hbimap reroll reroll -- | A type @'ListBy' t@ is supposed to represent the successive application of -- @t@s to itself. 'unroll' makes that successive application explicit,@@ -198,9 +199,9 @@ -- @ -- 'unroll' = 'unfoldChain' 'unconsLB' -- @-unroll- :: Tensor t i- => ListBy t f ~> Chain t i f+unroll ::+ Tensor t i =>+ ListBy t f ~> Chain t i f unroll = unfoldChain unconsLB -- | A type @'ListBy' t@ is supposed to represent the successive application of@@ -218,9 +219,10 @@ -- 'reroll' \@'Control.Monad.Freer.Church.Comp' -- :: 'Chain' Comp 'Data.Functor.Identity.Identity' f a -> 'Control.Monad.Freer.Church.Free' f a -- @-reroll- :: forall t i f. Tensor t i- => Chain t i f ~> ListBy t f+reroll ::+ forall t i f.+ Tensor t i =>+ Chain t i f ~> ListBy t f reroll = foldChain (nilLB @t) consLB -- | A type @'NonEmptyBy' t@ is supposed to represent the successive application of@@ -235,8 +237,8 @@ -- | The "forward" function representing 'splittingChain1'. Provided here -- as a separate function because it does not require @'Functor' f@.-splitChain1- :: forall t i f. Tensor t i- => Chain1 t f ~> t f (Chain t i f)+splitChain1 ::+ forall t i f.+ Tensor t i =>+ Chain1 t f ~> t f (Chain t i f) splitChain1 = hright (unroll @t) . splitNE @t . rerollNE-
src/Data/HFunctor.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.HFunctor--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -17,70 +17,76 @@ -- combinators that can represent interpretable schemas, and -- "Data.HBifunctor" for an abstraction over /binary/ functor combinators. module Data.HFunctor (- HFunctor(..)- , overHFunctor- , Inject(..)- , HBind(..)+ HFunctor (..),+ overHFunctor,+ Inject (..),+ HBind (..),+ -- * Simple instances- , ProxyF(..)- , ConstF(..)+ ProxyF (..),+ ConstF (..),+ -- * 'HFunctor' Combinators- , HLift(..), retractHLift- , HFree(..), foldHFree, retractHFree+ HLift (..),+ retractHLift,+ HFree (..),+ foldHFree,+ retractHFree,+ -- * Utility functions- , injectMap- , injectContramap- ) where+ injectMap,+ injectContramap,+) where -import Control.Applicative.Backwards-import Control.Applicative.Free-import Control.Applicative.Lift-import Control.Applicative.ListF-import Control.Applicative.Step-import Control.Comonad.Trans.Env-import Control.Monad.Freer.Church-import Control.Monad.Reader-import Control.Monad.Trans.Compose-import Control.Monad.Trans.Identity-import Control.Natural-import Control.Natural.IsoF-import Data.Coerce-import Data.Data-import Data.Deriving-import Data.Functor.Bind-import Data.Functor.Classes-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Coyoneda-import Data.Functor.Invariant-import Data.Functor.Plus-import Data.Functor.Product-import Data.Functor.Reverse-import Data.Functor.Sum-import Data.Functor.These-import Data.HFunctor.Internal-import Data.Kind-import Data.List.NonEmpty (NonEmpty(..))-import Data.Pointed-import Data.Semigroup.Foldable-import GHC.Generics-import qualified Control.Alternative.Free as Alt-import qualified Control.Applicative.Free.Fast as FAF-import qualified Control.Applicative.Free.Final as FA-import qualified Data.Functor.Contravariant.Coyoneda as CCY-import qualified Data.Map as M-import qualified Data.Map.NonEmpty as NEM+import qualified Control.Alternative.Free as Alt+import Control.Applicative.Backwards+import Control.Applicative.Free+import qualified Control.Applicative.Free.Fast as FAF+import qualified Control.Applicative.Free.Final as FA+import Control.Applicative.Lift+import Control.Applicative.ListF+import Control.Applicative.Step+import Control.Comonad.Trans.Env+import Control.Monad.Freer.Church+import Control.Monad.Reader+import Control.Monad.Trans.Compose+import Control.Monad.Trans.Identity+import Control.Natural+import Control.Natural.IsoF+import Data.Coerce+import Data.Data+import Data.Deriving+import Data.Functor.Bind+import Data.Functor.Classes+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import qualified Data.Functor.Contravariant.Coyoneda as CCY+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Coyoneda+import Data.Functor.Invariant+import Data.Functor.Plus+import Data.Functor.Product+import Data.Functor.Reverse+import Data.Functor.Sum+import Data.Functor.These+import Data.HFunctor.Internal+import Data.Kind+import Data.List.NonEmpty (NonEmpty (..))+import qualified Data.Map as M+import qualified Data.Map.NonEmpty as NEM+import Data.Pointed+import Data.Semigroup.Foldable+import GHC.Generics -- | Lift an isomorphism over an 'HFunctor'. -- -- Essentailly, if @f@ and @g@ are isomorphic, then so are @t f@ and @t g@.-overHFunctor- :: HFunctor t- => f <~> g- -> t f <~> t g+overHFunctor ::+ HFunctor t =>+ f <~> g ->+ t f <~> t g overHFunctor f = isoF (hmap (viewF f)) (hmap (reviewF f)) -- | The functor combinator that forgets all structure in the input.@@ -108,30 +114,36 @@ -- | @since 0.3.0.0 instance Contravariant (ProxyF f) where- contramap _ = coerce+ contramap _ = coerce+ -- | @since 0.3.0.0 instance Divisible (ProxyF f) where- divide _ _ _ = ProxyF- conquer = ProxyF+ divide _ _ _ = ProxyF+ conquer = ProxyF+ -- | @since 0.3.0.0 instance Divise (ProxyF f) where- divise _ _ _ = ProxyF+ divise _ _ _ = ProxyF+ -- | @since 0.3.0.0 instance Decide (ProxyF f) where- decide _ _ _ = ProxyF+ decide _ _ _ = ProxyF+ -- | @since 0.3.0.0 instance Conclude (ProxyF f) where- conclude _ = ProxyF+ conclude _ = ProxyF+ -- | @since 0.3.0.0 instance Decidable (ProxyF f) where- choose _ _ _ = ProxyF- lose _ = ProxyF+ choose _ _ _ = ProxyF+ lose _ = ProxyF+ -- | @since 0.3.0.0 instance Invariant (ProxyF f) where- invmap _ _ = coerce+ invmap _ _ = coerce instance HFunctor ProxyF where- hmap _ = coerce+ hmap _ = coerce -- | Functor combinator that forgets all structure on the input, and -- instead stores a value of type @e@.@@ -141,7 +153,7 @@ -- It can be 'inject'ed into (losing all information), but it is impossible -- to ever 'Data.HFunctor.Interpret.retract' or -- 'Data.HFunctor.Interpret.interpret' it.-data ConstF e f a = ConstF { getConstF :: e }+newtype ConstF e f a = ConstF {getConstF :: e} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) deriveShow1 ''ConstF@@ -151,20 +163,23 @@ -- | @since 0.3.0.0 instance Contravariant (ConstF e f) where- contramap _ = coerce+ contramap _ = coerce+ -- | @since 0.3.0.0 instance Monoid e => Divisible (ConstF e f) where- divide _ (ConstF x) (ConstF y) = ConstF (x <> y)- conquer = ConstF mempty+ divide _ (ConstF x) (ConstF y) = ConstF (x <> y)+ conquer = ConstF mempty+ -- | @since 0.3.0.0 instance Semigroup e => Divise (ConstF e f) where- divise _ (ConstF x) (ConstF y) = ConstF (x <> y)+ divise _ (ConstF x) (ConstF y) = ConstF (x <> y)+ -- | @since 0.3.0.0 instance Invariant (ConstF e f) where- invmap _ _ = coerce+ invmap _ _ = coerce instance HFunctor (ConstF e) where- hmap _ = coerce+ hmap _ = coerce -- | An "'HFunctor' combinator" that enhances an 'HFunctor' with the -- ability to hold a single @f a@. This is the higher-order analogue of@@ -174,14 +189,15 @@ -- -- Note that @'HLift' 'IdentityT'@ is equivalent to @'EnvT' -- 'Data.Semigroup.Any'@.-data HLift t f a = HPure (f a)- | HOther (t f a)- deriving Functor+data HLift t f a+ = HPure (f a)+ | HOther (t f a)+ deriving (Functor) instance (Show1 (t f), Show1 f) => Show1 (HLift t f) where- liftShowsPrec sp sl d = \case- HPure x -> showsUnaryWith (liftShowsPrec sp sl) "HPure" d x- HOther x -> showsUnaryWith (liftShowsPrec sp sl) "HOther" d x+ liftShowsPrec sp sl d = \case+ HPure x -> showsUnaryWith (liftShowsPrec sp sl) "HPure" d x+ HOther x -> showsUnaryWith (liftShowsPrec sp sl) "HOther" d x deriving instance (Show (f a), Show (t f a)) => Show (HLift t f a) deriving instance (Read (f a), Read (t f a)) => Read (HLift t f a)@@ -189,51 +205,51 @@ deriving instance (Ord (f a), Ord (t f a)) => Ord (HLift t f a) instance (Eq1 (t f), Eq1 f) => Eq1 (HLift t f) where- liftEq eq = \case- HPure x -> \case- HPure y -> liftEq eq x y- HOther _ -> False- HOther x -> \case- HPure _ -> False- HOther y -> liftEq eq x y+ liftEq eq = \case+ HPure x -> \case+ HPure y -> liftEq eq x y+ HOther _ -> False+ HOther x -> \case+ HPure _ -> False+ HOther y -> liftEq eq x y instance (Ord1 (t f), Ord1 f) => Ord1 (HLift t f) where- liftCompare c = \case- HPure x -> \case- HPure y -> liftCompare c x y- HOther _ -> LT- HOther x -> \case- HPure _ -> GT- HOther y -> liftCompare c x y+ liftCompare c = \case+ HPure x -> \case+ HPure y -> liftCompare c x y+ HOther _ -> LT+ HOther x -> \case+ HPure _ -> GT+ HOther y -> liftCompare c x y instance HFunctor t => HFunctor (HLift t) where- hmap f = \case- HPure x -> HPure (f x)- HOther x -> HOther (hmap f x)+ hmap f = \case+ HPure x -> HPure (f x)+ HOther x -> HOther (hmap f x) -- | @since 0.3.0.0 instance (Contravariant f, Contravariant (t f)) => Contravariant (HLift t f) where- contramap f = \case- HPure x -> HPure (contramap f x)- HOther xs -> HOther (contramap f xs)+ contramap f = \case+ HPure x -> HPure (contramap f x)+ HOther xs -> HOther (contramap f xs) -- | @since 0.3.0.0 instance (Invariant f, Invariant (t f)) => Invariant (HLift t f) where- invmap f g = \case- HPure x -> HPure (invmap f g x)- HOther xs -> HOther (invmap f g xs)+ invmap f g = \case+ HPure x -> HPure (invmap f g x)+ HOther xs -> HOther (invmap f g xs) -- | A higher-level 'Data.HFunctor.Interpret.retract' to get a @t f a@ back -- out of an @'HLift' t f a@, provided @t@ is an instance of 'Inject'. -- -- This witnesses the fact that 'HLift' is the "Free 'Inject'".-retractHLift- :: Inject t- => HLift t f a- -> t f a+retractHLift ::+ Inject t =>+ HLift t f a ->+ t f a retractHLift = \case- HPure x -> inject x- HOther x -> x+ HPure x -> inject x+ HOther x -> x -- | An "'HFunctor' combinator" that turns an 'HFunctor' into potentially -- infinite nestings of that 'HFunctor'.@@ -281,20 +297,21 @@ -- t@. -- -- Note that @'HFree' 'IdentityT'@ is equivalent to 'Step'.-data HFree t f a = HReturn (f a)- | HJoin (t (HFree t f) a)+data HFree t f a+ = HReturn (f a)+ | HJoin (t (HFree t f) a) deriving instance (Functor f, Functor (t (HFree t f))) => Functor (HFree t f) instance (Contravariant f, Contravariant (t (HFree t f))) => Contravariant (HFree t f) where- contramap f = \case- HReturn x -> HReturn (contramap f x)- HJoin xs -> HJoin (contramap f xs)+ contramap f = \case+ HReturn x -> HReturn (contramap f x)+ HJoin xs -> HJoin (contramap f xs) instance (Invariant f, Invariant (t (HFree t f))) => Invariant (HFree t f) where- invmap f g = \case- HReturn x -> HReturn (invmap f g x)- HJoin xs -> HJoin (invmap f g xs)+ invmap f g = \case+ HReturn x -> HReturn (invmap f g x)+ HJoin xs -> HJoin (invmap f g xs) -- | Recursively fold down an 'HFree' into a single @g@ result, by handling -- each branch. Can be more useful than@@ -302,45 +319,46 @@ -- branch separately, and also does not require any constraint on @g@. -- -- This is the catamorphism on 'HFree'.-foldHFree- :: forall t f g. HFunctor t- => (f ~> g)- -> (t g ~> g)- -> (HFree t f ~> g)+foldHFree ::+ forall t f g.+ HFunctor t =>+ (f ~> g) ->+ (t g ~> g) ->+ (HFree t f ~> g) foldHFree f g = go where go :: HFree t f ~> g go (HReturn x) = f x- go (HJoin x) = g (hmap go x)+ go (HJoin x) = g (hmap go x) -- | A higher-level 'Data.HFunctor.Interpret.retract' to get a @t f a@ back -- out of an @'HFree' t f a@, provided @t@ is an instance of 'Bind'. -- -- This witnesses the fact that 'HFree' is the "Free 'Bind'".-retractHFree- :: HBind t- => HFree t f a- -> t f a+retractHFree ::+ HBind t =>+ HFree t f a ->+ t f a retractHFree = \case- HReturn x -> inject x- HJoin x -> hbind retractHFree x+ HReturn x -> inject x+ HJoin x -> hbind retractHFree x instance (Show1 (t (HFree t f)), Show1 f) => Show1 (HFree t f) where- liftShowsPrec sp sl d = \case- HReturn x -> showsUnaryWith (liftShowsPrec sp sl) "HReturn" d x- HJoin x -> showsUnaryWith (liftShowsPrec sp sl) "HJoin" d x+ liftShowsPrec sp sl d = \case+ HReturn x -> showsUnaryWith (liftShowsPrec sp sl) "HReturn" d x+ HJoin x -> showsUnaryWith (liftShowsPrec sp sl) "HJoin" d x instance (Show1 (t (HFree t f)), Show1 f, Show a) => Show (HFree t f a) where- showsPrec = liftShowsPrec showsPrec showList+ showsPrec = liftShowsPrec showsPrec showList instance HFunctor t => HFunctor (HFree t) where- hmap :: forall f g. (f ~> g) -> HFree t f ~> HFree t g- hmap f = go- where- go :: HFree t f ~> HFree t g- go = \case- HReturn x -> HReturn (f x)- HJoin x -> HJoin (hmap go x)+ hmap :: forall f g. (f ~> g) -> HFree t f ~> HFree t g+ hmap f = go+ where+ go :: HFree t f ~> HFree t g+ go = \case+ HReturn x -> HReturn (f x)+ HJoin x -> HJoin (hmap go x) -- | A typeclass for 'HFunctor's where you can "inject" an @f a@ into a @t -- f a@:@@ -357,15 +375,15 @@ -- 'Data.HFunctor.Interpret.Interpret' to allow us to interpret or retrieve -- back the @f@. class HFunctor t => Inject t where- -- | Lift from @f@ into the enhanced @t f@ structure. Analogous to- -- 'lift' from 'MonadTrans'.- --- -- Note that this lets us "lift" a @f a@; if you want to lift an @a@- -- with @a -> t f a@, check if @t f@ is an instance of 'Applicative' or- -- 'Pointed'.- inject :: f ~> t f+ -- | Lift from @f@ into the enhanced @t f@ structure. Analogous to+ -- 'lift' from 'MonadTrans'.+ --+ -- Note that this lets us "lift" a @f a@; if you want to lift an @a@+ -- with @a -> t f a@, check if @t f@ is an instance of 'Applicative' or+ -- 'Pointed'.+ inject :: f ~> t f - {-# MINIMAL inject #-}+ {-# MINIMAL inject #-} -- | A useful wrapper over the common pattern of -- fmap-before-inject/inject-and-fmap.@@ -416,254 +434,259 @@ -- This class is similar to 'Control.Monad.Morph.MMonad' from -- "Control.Monad.Morph", but instances must work without a 'Monad' constraint. class Inject t => HBind t where- -- | Bind a continuation to a @t f@ into some context @g@.- hbind :: (f ~> t g) -> t f ~> t g- hbind f = hjoin . hmap f+ -- | Bind a continuation to a @t f@ into some context @g@.+ hbind :: (f ~> t g) -> t f ~> t g+ hbind f = hjoin . hmap f - -- | Collapse a nested @t (t f)@ into a single @t f@.- hjoin :: t (t f) ~> t f- hjoin = hbind id- {-# MINIMAL hbind | hjoin #-}+ -- | Collapse a nested @t (t f)@ into a single @t f@.+ hjoin :: t (t f) ~> t f+ hjoin = hbind id + {-# MINIMAL hbind | hjoin #-}+ instance Inject Coyoneda where- inject = liftCoyoneda+ inject = liftCoyoneda -- | @since 0.3.0.0 instance Inject CCY.Coyoneda where- inject = CCY.liftCoyoneda+ inject = CCY.liftCoyoneda instance Inject Ap where- inject = liftAp+ inject = liftAp instance Inject ListF where- inject = ListF . (:[])+ inject = ListF . (: []) instance Inject NonEmptyF where- inject = NonEmptyF . (:| [])+ inject = NonEmptyF . (:| []) instance Inject MaybeF where- inject = MaybeF . Just+ inject = MaybeF . Just -- | Injects into a singleton map at 'mempty'. instance Monoid k => Inject (NEMapF k) where- inject = NEMapF . NEM.singleton mempty+ inject = NEMapF . NEM.singleton mempty -- | Injects into a singleton map at 'mempty'. instance Monoid k => Inject (MapF k) where- inject = MapF . M.singleton mempty+ inject = MapF . M.singleton mempty -- | Injects with 0. -- -- Equivalent to instance for @'EnvT' ('Data.Semigroup.Sum' -- 'Numeric.Natural.Natural')@. instance Inject Step where- inject = Step 0+ inject = Step 0 -- | Injects into a singleton map at 0; same behavior as @'NEMapF' -- ('Data.Semigroup.Sum' 'Numeric.Natural.Natural')@. instance Inject Steps where- inject = Steps . NEM.singleton 0+ inject = Steps . NEM.singleton 0 -- | Injects with 'False'. -- -- Equivalent to instance for @'EnvT' 'Data.Semigroup.Any'@ and @'HLift' -- 'IdentityT'@. instance Inject Flagged where- inject = Flagged False+ inject = Flagged False instance Inject (These1 f) where- inject = That1+ inject = That1 instance Applicative f => Inject (Comp f :: (Type -> Type) -> Type -> Type) where- inject x = pure () :>>= const x+ inject x = pure () :>>= const x instance Applicative f => Inject ((:.:) f) where- inject x = Comp1 $ pure x+ inject x = Comp1 $ pure x -- | Only uses 'zero' instance Plus f => Inject ((:*:) f) where- inject = (zero :*:)+ inject = (zero :*:) -- | Only uses 'zero' instance Plus f => Inject (Product f) where- inject = Pair zero+ inject = Pair zero instance Inject ((:+:) f) where- inject = R1+ inject = R1 instance Inject (Sum f) where- inject = InR+ inject = InR instance Inject (M1 i c) where- inject = M1+ inject = M1 instance Inject Alt.Alt where- inject = Alt.liftAlt+ inject = Alt.liftAlt instance Inject Free where- inject = liftFree+ inject = liftFree instance Inject Free1 where- inject = liftFree1+ inject = liftFree1 instance Inject FA.Ap where- inject = FA.liftAp+ inject = FA.liftAp instance Inject FAF.Ap where- inject = FAF.liftAp+ inject = FAF.liftAp instance Inject IdentityT where- inject = coerce+ inject = coerce instance Inject Lift where- inject = Other+ inject = Other instance Inject MaybeApply where- inject = MaybeApply . Left+ inject = MaybeApply . Left instance Inject Backwards where- inject = Backwards+ inject = Backwards instance Inject WrappedApplicative where- inject = WrapApplicative+ inject = WrapApplicative instance Inject (ReaderT r) where- inject = ReaderT . const+ inject = ReaderT . const instance Monoid e => Inject (EnvT e) where- inject = EnvT mempty+ inject = EnvT mempty instance Inject Reverse where- inject = Reverse+ inject = Reverse instance Inject ProxyF where- inject _ = ProxyF+ inject _ = ProxyF instance Monoid e => Inject (ConstF e) where- inject _ = ConstF mempty+ inject _ = ConstF mempty instance (Inject s, Inject t) => Inject (ComposeT s t) where- inject = ComposeT . inject . inject+ inject = ComposeT . inject . inject instance HFunctor t => Inject (HLift t) where- inject = HPure+ inject = HPure -- | 'HFree' is the "free 'HBind' and 'Inject'" for any 'HFunctor' instance HFunctor t => Inject (HFree t) where- inject = HReturn+ inject = HReturn instance HBind Coyoneda where- hbind f (Coyoneda g x) = g <$> f x+ hbind f (Coyoneda g x) = g <$> f x instance HBind Ap where- hbind f x = runAp f x+ hbind f x = runAp f x instance HBind ListF where- hbind f = foldMap f . runListF+ hbind f = foldMap f . runListF instance HBind NonEmptyF where- hbind f = foldMap1 f . runNonEmptyF+ hbind f = foldMap1 f . runNonEmptyF instance HBind MaybeF where- hbind f = foldMap f . runMaybeF+ hbind f = foldMap f . runMaybeF -- | Equivalent to instance for @'EnvT' ('Data.Semigroup.Sum' -- 'Numeric.Natural.Natural')@. instance HBind Step where- hbind f (Step n x) = Step (n + m) y- where- Step m y = f x+ hbind f (Step n x) = Step (n + m) y+ where+ Step m y = f x -- | Equivalent to instance for @'EnvT' 'Data.Semigroup.Any'@ and @'HLift' -- 'IdentityT'@. instance HBind Flagged where- hbind f (Flagged p x) = Flagged (p || q) y- where- Flagged q y = f x+ hbind f (Flagged p x) = Flagged (p || q) y+ where+ Flagged q y = f x instance Alt f => HBind (These1 f) where- hbind f = \case- This1 x -> This1 x- That1 y -> f y- These1 x y -> case f y of- This1 x' -> This1 (x <!> x')- That1 y' -> That1 y'- These1 x' y' -> These1 (x <!> x') y'+ hbind f = \case+ This1 x -> This1 x+ That1 y -> f y+ These1 x y -> case f y of+ This1 x' -> This1 (x <!> x')+ That1 y' -> That1 y'+ These1 x' y' -> These1 (x <!> x') y' instance Plus f => HBind ((:*:) f) where- hbind f (x :*: y) = (x <!> x') :*: y'- where- x' :*: y' = f y+ hbind f (x :*: y) = (x <!> x') :*: y'+ where+ x' :*: y' = f y instance Plus f => HBind (Product f) where- hbind f (Pair x y) = Pair (x <!> x') y'- where- Pair x' y' = f y+ hbind f (Pair x y) = Pair (x <!> x') y'+ where+ Pair x' y' = f y instance HBind ((:+:) f) where- hbind f = \case- L1 x -> L1 x- R1 y -> f y+ hbind f = \case+ L1 x -> L1 x+ R1 y -> f y instance HBind (Sum f) where- hbind f = \case- InL x -> InL x- InR y -> f y+ hbind f = \case+ InL x -> InL x+ InR y -> f y instance HBind (M1 i c) where- hbind f (M1 x) = f x+ hbind f (M1 x) = f x instance HBind Alt.Alt where- hbind f x = Alt.runAlt f x+ hbind f x = Alt.runAlt f x instance HBind Free where- hbind f x = interpretFree f x+ hbind f x = interpretFree f x instance HBind Free1 where- hbind f x = interpretFree1 f x+ hbind f x = interpretFree1 f x instance HBind FA.Ap where- hbind f x = FA.runAp f x+ hbind f x = FA.runAp f x instance HBind FAF.Ap where- hbind f x = FAF.runAp f x+ hbind f x = FAF.runAp f x instance HBind IdentityT where- hbind f = f . runIdentityT+ hbind f = f . runIdentityT instance HBind Lift where- hbind f x = elimLift point f x+ hbind f x = elimLift point f x instance HBind MaybeApply where- hbind f = either f point . runMaybeApply+ hbind f = either f point . runMaybeApply instance HBind Backwards where- hbind f = f . forwards+ hbind f = f . forwards instance HBind WrappedApplicative where- hbind f = f . unwrapApplicative+ hbind f = f . unwrapApplicative instance HBind Reverse where- hbind f = f . getReverse+ hbind f = f . getReverse instance HBind ProxyF where- hbind _ = coerce+ hbind _ = coerce -- | Combines the accumulators, Writer-style instance Monoid e => HBind (EnvT e) where- hbind f (EnvT e x) = EnvT (e <> e') y- where- EnvT e' y = f x+ hbind f (EnvT e x) = EnvT (e <> e') y+ where+ EnvT e' y = f x instance HBind t => HBind (HLift t) where- hbind f = \case- HPure x -> f x- HOther x -> HOther $ (\y -> case f y of- HPure z -> inject z- HOther z -> z) `hbind` x+ hbind f = \case+ HPure x -> f x+ HOther x ->+ HOther $+ ( \y -> case f y of+ HPure z -> inject z+ HOther z -> z+ )+ `hbind` x -- | 'HFree' is the "free 'HBind'" for any 'HFunctor' instance HFunctor t => HBind (HFree t) where- hbind f = \case- HReturn x -> f x- HJoin x -> HJoin $ hmap (hbind f) x+ hbind f = \case+ HReturn x -> f x+ HJoin x -> HJoin $ hmap (hbind f) x
src/Data/HFunctor/Chain.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Data.HFunctor.Chain--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -26,79 +26,84 @@ -- combinators you might encounter. module Data.HFunctor.Chain ( -- * 'Chain'- Chain(..)- , foldChain, foldChainA- , unfoldChain- , unroll- , reroll- , unrolling- , appendChain- , splittingChain- , toChain- , injectChain- , unconsChain+ Chain (..),+ foldChain,+ foldChainA,+ unfoldChain,+ unroll,+ reroll,+ unrolling,+ appendChain,+ splittingChain,+ toChain,+ injectChain,+ unconsChain,+ -- * 'Chain1'- , Chain1(..)- , foldChain1, foldChain1A- , unfoldChain1- , unrollingNE- , unrollNE- , rerollNE- , appendChain1- , fromChain1- , matchChain1- , toChain1- , injectChain1+ Chain1 (..),+ foldChain1,+ foldChain1A,+ unfoldChain1,+ unrollingNE,+ unrollNE,+ rerollNE,+ appendChain1,+ fromChain1,+ matchChain1,+ toChain1,+ injectChain1,+ -- ** Matchable+ -- | The following conversions between 'Chain' and 'Chain1' are only -- possible if @t@ is 'Matchable'- , splittingChain1- , splitChain1- , matchingChain- , unmatchChain- ) where+ splittingChain1,+ splitChain1,+ matchingChain,+ unmatchChain,+) where -import Control.Monad.Freer.Church-import Control.Natural-import Control.Natural.IsoF-import Data.Functor.Bind-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Day hiding (intro1, intro2, elim1, elim2)-import Data.Functor.Identity-import Data.Functor.Invariant-import Data.Functor.Invariant.Inplicative-import Data.Functor.Invariant.Internative-import Data.Functor.Plus-import Data.Functor.Product-import Data.HBifunctor-import Data.HBifunctor.Associative-import Data.HBifunctor.Tensor-import Data.HBifunctor.Tensor.Internal-import Data.HFunctor-import Data.HFunctor.Chain.Internal-import Data.HFunctor.Interpret-import Data.Typeable-import GHC.Generics-import qualified Data.Functor.Contravariant.Day as CD-import qualified Data.Functor.Contravariant.Night as N-import qualified Data.Functor.Invariant.Day as ID-import qualified Data.Functor.Invariant.Night as IN+import Control.Monad.Freer.Church+import Control.Natural+import Control.Natural.IsoF+import Data.Functor.Bind+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import qualified Data.Functor.Contravariant.Day as CD+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import qualified Data.Functor.Contravariant.Night as N+import Data.Functor.Day hiding (elim1, elim2, intro1, intro2)+import Data.Functor.Identity+import Data.Functor.Invariant+import qualified Data.Functor.Invariant.Day as ID+import Data.Functor.Invariant.Inplicative+import Data.Functor.Invariant.Internative+import qualified Data.Functor.Invariant.Night as IN+import Data.Functor.Plus+import Data.Functor.Product+import Data.HBifunctor+import Data.HBifunctor.Associative+import Data.HBifunctor.Tensor+import Data.HBifunctor.Tensor.Internal+import Data.HFunctor+import Data.HFunctor.Chain.Internal+import Data.HFunctor.Interpret+import Data.Typeable+import GHC.Generics instance SemigroupIn t f => Interpret (Chain1 t) f where- retract = \case- Done1 x -> x- More1 xs -> binterpret id retract xs- interpret :: forall g. g ~> f -> Chain1 t g ~> f- interpret f = go- where- go :: Chain1 t g ~> f- go = \case- Done1 x -> f x- More1 xs -> binterpret f go xs+ retract = \case+ Done1 x -> x+ More1 xs -> binterpret id retract xs+ interpret :: forall g. g ~> f -> Chain1 t g ~> f+ interpret f = go+ where+ go :: Chain1 t g ~> f+ go = \case+ Done1 x -> f x+ More1 xs -> binterpret f go xs -- | A type @'NonEmptyBy' t@ is supposed to represent the successive application of -- @t@s to itself. The type @'Chain1' t f@ is an actual concrete ADT that contains@@ -129,48 +134,50 @@ -- t@". -- -- @since 0.1.1.0-appendChain1- :: forall t f. (Associative t, FunctorBy t f)- => t (Chain1 t f) (Chain1 t f) ~> Chain1 t f-appendChain1 = unrollNE- . appendNE- . hbimap rerollNE rerollNE+appendChain1 ::+ forall t f.+ (Associative t, FunctorBy t f) =>+ t (Chain1 t f) (Chain1 t f) ~> Chain1 t f+appendChain1 =+ unrollNE+ . appendNE+ . hbimap rerollNE rerollNE -- | @'Chain1' t@ is the "free @'SemigroupIn' t@". However, we have to -- wrap @t@ in 'WrapHBF' to prevent overlapping instances. instance (Associative t, FunctorBy t f, FunctorBy t (Chain1 t f)) => SemigroupIn (WrapHBF t) (Chain1 t f) where- biretract = appendChain1 . unwrapHBF- binterpret f g = biretract . hbimap f g+ biretract = appendChain1 . unwrapHBF+ binterpret f g = biretract . hbimap f g -- | @'Chain1' 'Day'@ is the free "semigroup in the semigroupoidal category -- of endofunctors enriched by 'Day'" --- aka, the free 'Apply'. instance Functor f => Apply (Chain1 Day f) where- f <.> x = appendChain1 $ Day f x ($)+ f <.> x = appendChain1 $ Day f x ($) instance Functor f => Apply (Chain1 Comp f) where- (<.>) = apDefault+ (<.>) = apDefault -- | @'Chain1' 'Comp'@ is the free "semigroup in the semigroupoidal -- category of endofunctors enriched by 'Comp'" --- aka, the free 'Bind'. instance Functor f => Bind (Chain1 Comp f) where- x >>- f = appendChain1 (x :>>= f)+ x >>- f = appendChain1 (x :>>= f) -- | @'Chain1' (':*:')@ is the free "semigroup in the semigroupoidal -- category of endofunctors enriched by ':*:'" --- aka, the free 'Alt'. instance Functor f => Alt (Chain1 (:*:) f) where- x <!> y = appendChain1 (x :*: y)+ x <!> y = appendChain1 (x :*: y) -- | @'Chain1' 'Product'@ is the free "semigroup in the semigroupoidal -- category of endofunctors enriched by 'Product'" --- aka, the free 'Alt'. instance Functor f => Alt (Chain1 Product f) where- x <!> y = appendChain1 (Pair x y)+ x <!> y = appendChain1 (Pair x y) -- | @'Chain1' 'CD.Day'@ is the free "semigroup in the semigroupoidal -- category of endofunctors enriched by 'CD.Day'" --- aka, the free 'Divise'. -- -- @since 0.3.0.0 instance Contravariant f => Divise (Chain1 CD.Day f) where- divise f x y = appendChain1 $ CD.Day x y f+ divise f x y = appendChain1 $ CD.Day x y f -- | @'Chain1' 'N.Night'@ is the free "semigroup in the semigroupoidal -- category of endofunctors enriched by 'N.Night'" --- aka, the free@@ -178,31 +185,32 @@ -- -- @since 0.3.0.0 instance Contravariant f => Decide (Chain1 N.Night f) where- decide f x y = appendChain1 $ N.Night x y f+ decide f x y = appendChain1 $ N.Night x y f -- | @since 0.4.0.0 instance Invariant f => Inply (Chain1 ID.Day f) where- gather f g x y = appendChain1 (ID.Day x y f g)+ gather f g x y = appendChain1 (ID.Day x y f g) instance Tensor t i => Inject (Chain t i) where- inject = injectChain+ inject = injectChain -- | @since 0.4.0.0 instance Invariant f => Inalt (Chain1 IN.Night f) where- swerve f g h x y = appendChain1 (IN.Night x y f g h)+ swerve f g h x y = appendChain1 (IN.Night x y f g h) -- | We can collapse and interpret an @'Chain' t i@ if we have @'Tensor' t@. instance MonoidIn t i f => Interpret (Chain t i) f where- interpret- :: forall g. ()- => g ~> f- -> Chain t i g ~> f- interpret f = go- where- go :: Chain t i g ~> f- go = \case- Done x -> pureT @t x- More xs -> binterpret f go xs+ interpret ::+ forall g.+ () =>+ g ~> f ->+ Chain t i g ~> f+ interpret f = go+ where+ go :: Chain t i g ~> f+ go = \case+ Done x -> pureT @t x+ More xs -> binterpret f go xs -- | Convert a tensor value pairing two @f@s into a two-item 'Chain'. An -- analogue of 'toListBy'.@@ -222,9 +230,9 @@ -- always has at least one @f@. -- -- The result of this function always is made with 'More' at the top level.-fromChain1- :: Tensor t i- => Chain1 t f ~> Chain t i f+fromChain1 ::+ Tensor t i =>+ Chain1 t f ~> Chain t i f fromChain1 = foldChain1 (More . hright Done . intro1) More -- | A type @'ListBy' t@ is supposed to represent the successive application of@@ -234,62 +242,67 @@ -- -- 'unrolling' states that the two types are isormorphic. Use 'unroll' -- and 'reroll' to convert between the two.-unrolling- :: Tensor t i- => ListBy t f <~> Chain t i f+unrolling ::+ Tensor t i =>+ ListBy t f <~> Chain t i f unrolling = isoF unroll reroll -- | A @'Chain1' t f@ is like a non-empty linked list of @f@s, and -- a @'Chain' t i f@ is a possibly-empty linked list of @f@s. This -- witnesses the fact that the former is isomorphic to @f@ consed to the -- latter.-splittingChain1- :: forall t i f. (Matchable t i, FunctorBy t f)- => Chain1 t f <~> t f (Chain t i f)-splittingChain1 = fromF unrollingNE- . splittingNE @t- . overHBifunctor id unrolling+splittingChain1 ::+ forall t i f.+ (Matchable t i, FunctorBy t f) =>+ Chain1 t f <~> t f (Chain t i f)+splittingChain1 =+ fromF unrollingNE+ . splittingNE @t+ . overHBifunctor id unrolling -- | A @'Chain' t i f@ is a linked list of @f@s, and a @'Chain1' t f@ is -- a non-empty linked list of @f@s. This witnesses the fact that -- a @'Chain' t i f@ is either empty (@i@) or non-empty (@'Chain1' t f@).-matchingChain- :: forall t i f. (Matchable t i, FunctorBy t f)- => Chain t i f <~> i :+: Chain1 t f-matchingChain = fromF unrolling- . matchingLB @t- . overHBifunctor id unrollingNE+matchingChain ::+ forall t i f.+ (Matchable t i, FunctorBy t f) =>+ Chain t i f <~> i :+: Chain1 t f+matchingChain =+ fromF unrolling+ . matchingLB @t+ . overHBifunctor id unrollingNE -- | The "reverse" function representing 'matchingChain'. Provided here -- as a separate function because it does not require @'Functor' f@.-unmatchChain- :: forall t i f. Tensor t i- => i :+: Chain1 t f ~> Chain t i f+unmatchChain ::+ forall t i f.+ Tensor t i =>+ i :+: Chain1 t f ~> Chain t i f unmatchChain = unroll . (nilLB @t !*! fromNE @t) . hright rerollNE -- | We have to wrap @t@ in 'WrapHBF' to prevent overlapping instances. instance (Tensor t i, FunctorBy t (Chain t i f)) => SemigroupIn (WrapHBF t) (Chain t i f) where- biretract = appendChain . unwrapHBF- binterpret f g = biretract . hbimap f g+ biretract = appendChain . unwrapHBF+ binterpret f g = biretract . hbimap f g -- | @'Chain' t i@ is the "free @'MonoidIn' t i@". However, we have to -- wrap @t@ in 'WrapHBF' and @i@ in 'WrapF' to prevent overlapping instances. instance (Tensor t i, FunctorBy t (Chain t i f)) => MonoidIn (WrapHBF t) (WrapF i) (Chain t i f) where- pureT = Done . unwrapF+ pureT = Done . unwrapF instance Apply (Chain Day Identity f) where- f <.> x = appendChain $ Day f x ($)+ f <.> x = appendChain $ Day f x ($) -- | @'Chain' 'Day' 'Identity'@ is the free "monoid in the monoidal -- category of endofunctors enriched by 'Day'" --- aka, the free -- 'Applicative'. instance Applicative (Chain Day Identity f) where- pure = Done . Identity- (<*>) = (<.>)+ pure = Done . Identity+ (<*>) = (<.>) -- | @since 0.3.0.0 instance Divise (Chain CD.Day Proxy f) where- divise f x y = appendChain $ CD.Day x y f+ divise f x y = appendChain $ CD.Day x y f -- | @'Chain' 'CD.Day' 'Proxy'@ is the free "monoid in the monoidal -- category of endofunctors enriched by contravariant 'CD.Day'" --- aka,@@ -297,28 +310,28 @@ -- -- @since 0.3.0.0 instance Divisible (Chain CD.Day Proxy f) where- divide f x y = appendChain $ CD.Day x y f- conquer = Done Proxy+ divide f x y = appendChain $ CD.Day x y f+ conquer = Done Proxy -- | @since 0.4.0.0 instance Inply (Chain ID.Day Identity f) where- gather f g x y = appendChain (ID.Day x y f g)+ gather f g x y = appendChain (ID.Day x y f g) -- | @since 0.4.0.0 instance Inplicative (Chain ID.Day Identity f) where- knot = Done . Identity+ knot = Done . Identity -- | @since 0.4.0.0 instance Inalt (Chain IN.Night IN.Not f) where- swerve f g h x y = appendChain (IN.Night x y f g h)+ swerve f g h x y = appendChain (IN.Night x y f g h) -- | @since 0.4.0.0 instance Inplus (Chain IN.Night IN.Not f) where- reject = Done . IN.Not+ reject = Done . IN.Not -- | @since 0.3.0.0 instance Decide (Chain N.Night N.Not f) where- decide f x y = appendChain $ N.Night x y f+ decide f x y = appendChain $ N.Night x y f -- | @'Chain' 'N.Night' 'N.Refutec'@ is the free "monoid in the monoidal -- category of endofunctors enriched by 'N.Night'" --- aka, the free@@ -326,39 +339,38 @@ -- -- @since 0.3.0.0 instance Conclude (Chain N.Night N.Not f) where- conclude = Done . N.Not+ conclude = Done . N.Not instance Apply (Chain Comp Identity f) where- (<.>) = apDefault+ (<.>) = apDefault instance Applicative (Chain Comp Identity f) where- pure = Done . Identity- (<*>) = (<.>)+ pure = Done . Identity+ (<*>) = (<.>) instance Bind (Chain Comp Identity f) where- x >>- f = appendChain (x :>>= f)+ x >>- f = appendChain (x :>>= f) -- | @'Chain' 'Comp' 'Identity'@ is the free "monoid in the monoidal -- category of endofunctors enriched by 'Comp'" --- aka, the free -- 'Monad'. instance Monad (Chain Comp Identity f) where- (>>=) = (>>-)+ (>>=) = (>>-) instance Functor f => Alt (Chain (:*:) Proxy f) where- x <!> y = appendChain (x :*: y)+ x <!> y = appendChain (x :*: y) -- | @'Chain' (':*:') 'Proxy'@ is the free "monoid in the monoidal -- category of endofunctors enriched by ':*:'" --- aka, the free -- 'Plus'. instance Functor f => Plus (Chain (:*:) Proxy f) where- zero = Done Proxy+ zero = Done Proxy instance Functor f => Alt (Chain Product Proxy f) where- x <!> y = appendChain (Pair x y)+ x <!> y = appendChain (Pair x y) -- | @'Chain' (':*:') 'Proxy'@ is the free "monoid in the monoidal -- category of endofunctors enriched by ':*:'" --- aka, the free -- 'Plus'. instance Functor f => Plus (Chain Product Proxy f) where- zero = Done Proxy-+ zero = Done Proxy
src/Data/HFunctor/Chain/Internal.hs view
@@ -1,41 +1,44 @@ {-# 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+ 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 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 qualified Data.Functor.Invariant.Day as ID+import Data.Functor.Invariant.Internative import qualified Data.Functor.Invariant.Night as IN-+import Data.HBifunctor+import Data.HFunctor+import Data.HFunctor.HTraversable+import Data.HFunctor.Interpret+import Data.Kind+import Data.Typeable+import Data.Void+import GHC.Generics -- | A useful construction that works like a "non-empty linked list" of @t -- f@ applied to itself multiple times. That is, it contains @t f f@, @t@@ -92,8 +95,9 @@ -- -- -- This construction is inspired by iteratees and machines.-data Chain1 t f a = Done1 (f a)- | More1 (t f (Chain1 t f) a)+data Chain1 t f a+ = Done1 (f a)+ | More1 (t f (Chain1 t f) a) deriving (Typeable, Generic) deriving instance (Eq (f a), Eq (t f (Chain1 t f) a)) => Eq (Chain1 t f a)@@ -105,50 +109,51 @@ 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 eq = \case- Done1 x -> \case- Done1 y -> liftEq eq x y- More1 _ -> False- More1 x -> \case- Done1 _ -> False- More1 y -> liftEq eq x y+ liftEq eq = \case+ Done1 x -> \case+ Done1 y -> liftEq eq x y+ More1 _ -> False+ More1 x -> \case+ Done1 _ -> False+ More1 y -> liftEq eq x y instance (Ord1 f, Ord1 (t f (Chain1 t f))) => Ord1 (Chain1 t f) where- liftCompare c = \case- Done1 x -> \case- Done1 y -> liftCompare c x y- More1 _ -> LT- More1 x -> \case- Done1 _ -> GT- More1 y -> liftCompare c x y+ liftCompare c = \case+ Done1 x -> \case+ Done1 y -> liftCompare c x y+ More1 _ -> LT+ More1 x -> \case+ Done1 _ -> GT+ More1 y -> liftCompare c x y instance (Show1 (t f (Chain1 t f)), Show1 f) => Show1 (Chain1 t f) where- liftShowsPrec sp sl d = \case- Done1 x -> showsUnaryWith (liftShowsPrec sp sl) "Done1" d x- More1 xs -> showsUnaryWith (liftShowsPrec sp sl) "More1" d xs+ liftShowsPrec sp sl d = \case+ Done1 x -> showsUnaryWith (liftShowsPrec sp sl) "Done1" d x+ More1 xs -> showsUnaryWith (liftShowsPrec sp sl) "More1" d xs instance (Functor f, Read1 (t f (Chain1 t f)), Read1 f) => Read1 (Chain1 t f) where- liftReadsPrec rp rl = readsData $- readsUnaryWith (liftReadsPrec rp rl) "Done1" Done1- <> readsUnaryWith (liftReadsPrec rp rl) "More1" More1+ liftReadsPrec rp rl =+ readsData $+ readsUnaryWith (liftReadsPrec rp rl) "Done1" Done1+ <> readsUnaryWith (liftReadsPrec rp rl) "More1" More1 -- | @since 0.3.0.0 instance (Contravariant f, Contravariant (t f (Chain1 t f))) => Contravariant (Chain1 t f) where- contramap f = \case- Done1 x -> Done1 (contramap f x )- More1 xs -> More1 (contramap f xs)+ contramap f = \case+ Done1 x -> Done1 (contramap f x)+ More1 xs -> More1 (contramap f xs) -- | @since 0.3.0.0 instance (Invariant f, Invariant (t f (Chain1 t f))) => Invariant (Chain1 t f) where- invmap f g = \case- Done1 x -> Done1 (invmap f g x )- More1 xs -> More1 (invmap f g xs)+ invmap f g = \case+ Done1 x -> Done1 (invmap f g x)+ More1 xs -> More1 (invmap f g xs) instance HBifunctor t => HFunctor (Chain1 t) where- hmap f = foldChain1 (Done1 . f) (More1 . hleft f)+ hmap f = foldChain1 (Done1 . f) (More1 . hleft f) instance HBifunctor t => Inject (Chain1 t) where- inject = injectChain1+ inject = injectChain1 -- | Recursively fold down a 'Chain1'. Provide a function on how to handle -- the "single @f@ case" ('inject'), and how to handle the "combined @t@@ -156,27 +161,32 @@ -- @g@. -- -- This is a catamorphism.-foldChain1- :: forall t f g. HBifunctor t- => f ~> g -- ^ handle 'Done1'- -> t f g ~> g -- ^ handle 'More1'- -> Chain1 t f ~> g+foldChain1 ::+ forall t f g.+ HBifunctor t =>+ -- | handle 'Done1'+ f ~> g ->+ -- | handle 'More1'+ t f g ~> g ->+ Chain1 t f ~> g foldChain1 f g = go where go :: Chain1 t f ~> g go = \case- Done1 x -> f x+ Done1 x -> f x More1 xs -> g (hright go xs) -- | An "effectful" version of 'foldChain1', weaving Applicative effects. -- -- @since 0.3.6.0-foldChain1A- :: (HBifunctor t, Functor h)- => (forall x. f x -> h (g x)) -- ^ handle 'Done1'- -> (forall x. t f (Comp h g) x -> h (g x)) -- ^ handle 'More1'- -> Chain1 t f a- -> h (g a)+foldChain1A ::+ (HBifunctor t, Functor h) =>+ -- | handle 'Done1'+ (forall x. f x -> h (g x)) ->+ -- | handle 'More1'+ (forall x. t f (Comp h g) x -> h (g x)) ->+ Chain1 t f a ->+ h (g a) foldChain1A f g = unComp . foldChain1 (Comp . f) (Comp . g) -- | Recursively build up a 'Chain1'. Provide a function that takes some@@ -184,10 +194,11 @@ -- (@t f g@), and it will create a @'Chain1' t f@ from a @g@. -- -- This is an anamorphism.-unfoldChain1- :: forall t f (g :: Type -> Type). HBifunctor t- => (g ~> f :+: t f g)- -> g ~> Chain1 t f+unfoldChain1 ::+ forall t f (g :: Type -> Type).+ HBifunctor t =>+ (g ~> f :+: t f g) ->+ g ~> Chain1 t f unfoldChain1 f = go where go :: g ~> Chain1 t f@@ -212,8 +223,8 @@ -- @since 0.3.0.0 matchChain1 :: Chain1 t f ~> (f :+: t f (Chain1 t f)) matchChain1 = \case- Done1 x -> L1 x- More1 xs -> R1 xs+ Done1 x -> L1 x+ More1 xs -> R1 xs -- | A useful construction that works like a "linked list" of @t f@ applied -- to itself multiple times. That is, it contains @t f f@, @t f (t f f)@,@@ -260,8 +271,9 @@ -- -- This construction is inspired by -- <http://oleg.fi/gists/posts/2018-02-21-single-free.html>-data Chain t i f a = Done (i a)- | More (t f (Chain t i f) a)+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)@@ -272,72 +284,78 @@ 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 eq = \case- Done x -> \case- Done y -> liftEq eq x y- More _ -> False- More x -> \case- Done _ -> False- More y -> liftEq eq x y+ liftEq eq = \case+ Done x -> \case+ Done y -> liftEq eq x y+ More _ -> False+ More x -> \case+ Done _ -> False+ More y -> liftEq eq x y instance (Ord1 i, Ord1 (t f (Chain t i f))) => Ord1 (Chain t i f) where- liftCompare c = \case- Done x -> \case- Done y -> liftCompare c x y- More _ -> LT- More x -> \case- Done _ -> GT- More y -> liftCompare c x y+ liftCompare c = \case+ Done x -> \case+ Done y -> liftCompare c x y+ More _ -> LT+ More x -> \case+ Done _ -> GT+ More y -> liftCompare c x y instance (Show1 (t f (Chain t i f)), Show1 i) => Show1 (Chain t i f) where- liftShowsPrec sp sl d = \case- Done x -> showsUnaryWith (liftShowsPrec sp sl) "Done" d x- More xs -> showsUnaryWith (liftShowsPrec sp sl) "More" d xs+ liftShowsPrec sp sl d = \case+ Done x -> showsUnaryWith (liftShowsPrec sp sl) "Done" d x+ More xs -> showsUnaryWith (liftShowsPrec sp sl) "More" d xs instance (Functor i, Read1 (t f (Chain t i f)), Read1 i) => Read1 (Chain t i f) where- liftReadsPrec rp rl = readsData $- readsUnaryWith (liftReadsPrec rp rl) "Done" Done- <> readsUnaryWith (liftReadsPrec rp rl) "More" More+ liftReadsPrec rp rl =+ readsData $+ readsUnaryWith (liftReadsPrec rp rl) "Done" Done+ <> readsUnaryWith (liftReadsPrec rp rl) "More" More instance (Contravariant i, Contravariant (t f (Chain t i f))) => Contravariant (Chain t i f) where- contramap f = \case- Done x -> Done (contramap f x )- More xs -> More (contramap f xs)+ contramap f = \case+ Done x -> Done (contramap f x)+ More xs -> More (contramap f xs) instance (Invariant i, Invariant (t f (Chain t i f))) => Invariant (Chain t i f) where- invmap f g = \case- Done x -> Done (invmap f g x )- More xs -> More (invmap f g xs)+ invmap f g = \case+ Done x -> Done (invmap f g x)+ More xs -> More (invmap f g xs) instance HBifunctor t => HFunctor (Chain t i) where- hmap f = foldChain Done (More . hleft f)+ hmap f = foldChain Done (More . hleft f) -- | Recursively fold down a 'Chain'. Provide a function on how to handle -- the "single @f@ case" ('nilLB'), and how to handle the "combined @t f g@ -- case", and this will fold the entire @'Chain' t i) f@ into a single @g@. -- -- This is a catamorphism.-foldChain- :: forall t i f g. HBifunctor t- => (i ~> g) -- ^ Handle 'Done'- -> (t f g ~> g) -- ^ Handle 'More'- -> Chain t i f ~> g+foldChain ::+ forall t i f g.+ HBifunctor t =>+ -- | Handle 'Done'+ (i ~> g) ->+ -- | Handle 'More'+ (t f g ~> g) ->+ Chain t i f ~> g foldChain f g = go where go :: Chain t i f ~> g go = \case- Done x -> f x+ Done x -> f x More xs -> g (hright go xs) -- | An "effectful" version of 'foldChain', weaving Applicative effects. -- -- @since 0.3.6.0-foldChainA- :: (HBifunctor t, Functor h)- => (forall x. i x -> h (g x)) -- ^ Handle 'Done'- -> (forall x. t f (Comp h g) x -> h (g x)) -- ^ Handle 'More'- -> Chain t i f a- -> h (g a)+foldChainA ::+ (HBifunctor t, Functor h) =>+ -- | Handle 'Done'+ (forall x. i x -> h (g x)) ->+ -- | Handle 'More'+ (forall x. t f (Comp h g) x -> h (g x)) ->+ Chain t i f a ->+ h (g a) foldChainA f g = unComp . foldChain (Comp . f) (Comp . g) -- | Recursively build up a 'Chain'. Provide a function that takes some@@ -345,14 +363,15 @@ -- (@t f g@), and it will create a @'Chain' t i f@ from a @g@. -- -- This is an anamorphism.-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 :: Type -> Type) i.+ HBifunctor t =>+ (g ~> i :+: t f g) ->+ g ~> Chain t i f unfoldChain f = go where go :: g a -> Chain t i f a- go = (\case L1 x -> Done x; R1 y -> More (hright go y)) . f+ go = (\case L1 x -> Done x; R1 y -> More (hright go y)) . f -- | For completeness, an isomorphism between 'Chain' and its two -- constructors, to match 'splittingLB'.@@ -360,8 +379,8 @@ -- @since 0.3.0.0 splittingChain :: Chain t i f <~> (i :+: t f (Chain t i f)) splittingChain = isoF unconsChain $ \case- L1 x -> Done x- R1 xs -> More xs+ L1 x -> Done x+ R1 xs -> More xs -- | An analogue of 'unconsLB': match one of the two constructors of -- a 'Chain'.@@ -369,8 +388,8 @@ -- @since 0.3.0.0 unconsChain :: Chain t i f ~> i :+: t f (Chain t i f) unconsChain = \case- Done x -> L1 x- More xs -> R1 xs+ Done x -> L1 x+ More xs -> R1 xs -- | The invariant version of 'Ap1' and 'Div1': combines the capabilities -- of both 'Ap1' and 'Div1' together.@@ -401,27 +420,31 @@ -- it. -- -- @since 0.3.5.0-newtype DivAp1 f a = DivAp1_ { unDivAp1 :: Chain1 ID.Day f a }+newtype DivAp1 f a = DivAp1_ {unDivAp1 :: Chain1 ID.Day f a} deriving (Invariant, HFunctor, Inject) instance HTraversable DivAp1 where- htraverse f =- foldChain1A- (fmap (DivAp1_ . Done1) . f)- (\case ID.Day x (Comp y) g h ->- (\x' y' -> DivAp1_ (More1 (ID.Day x' y' g h)))- <$> f x <*> (unDivAp1 <$> y)- )+ htraverse f =+ foldChain1A+ (fmap (DivAp1_ . Done1) . f)+ ( \case+ ID.Day x (Comp y) g h ->+ (\x' y' -> DivAp1_ (More1 (ID.Day x' y' g h)))+ <$> f x+ <*> (unDivAp1 <$> y)+ ) . unDivAp1 instance HTraversable1 DivAp1 where- htraverse1 f =- foldChain1A- (fmap (DivAp1_ . Done1) . f)- (\case ID.Day x (Comp y) g h ->- (\x' y' -> DivAp1_ (More1 (ID.Day x' y' g h)))- <$> f x <.> (unDivAp1 <$> y)- )+ htraverse1 f =+ foldChain1A+ (fmap (DivAp1_ . Done1) . f)+ ( \case+ ID.Day x (Comp y) g h ->+ (\x' y' -> DivAp1_ (More1 (ID.Day x' y' g h)))+ <$> f x+ <.> (unDivAp1 <$> y)+ ) . unDivAp1 -- | The invariant version of 'Ap' and 'Div': combines the capabilities of@@ -454,23 +477,24 @@ -- assemble it. -- -- @since 0.3.5.0-newtype DivAp f a = DivAp { unDivAp :: Chain ID.Day Identity f a }+newtype DivAp f a = DivAp {unDivAp :: Chain ID.Day Identity f a} deriving (Invariant, HFunctor) instance Inject DivAp where- inject x = DivAp $ More (ID.Day x (Done (Identity ())) const (,()))+ inject x = DivAp $ More (ID.Day x (Done (Identity ())) const (,())) instance HTraversable DivAp where- htraverse f =- foldChainA- (pure . DivAp . Done)- (\case ID.Day x (Comp y) g h ->- (\x' y' -> DivAp (More (ID.Day x' y' g h)))- <$> f x <*> (unDivAp <$> y)- )+ htraverse f =+ foldChainA+ (pure . DivAp . Done)+ ( \case+ ID.Day x (Comp y) g h ->+ (\x' y' -> DivAp (More (ID.Day x' y' g h)))+ <$> f x+ <*> (unDivAp <$> y)+ ) . unDivAp - -- | The invariant version of 'NonEmptyF' and 'Dec1': combines the -- capabilities of both 'NonEmptyF' and 'Dec1' together. --@@ -499,32 +523,36 @@ -- assemble it. -- -- @since 0.3.5.0-newtype DecAlt1 f a = DecAlt1_ { unDecAlt1 :: Chain1 IN.Night f a }+newtype DecAlt1 f a = DecAlt1_ {unDecAlt1 :: Chain1 IN.Night f a} deriving (Invariant, HFunctor, Inject) instance HTraversable DecAlt1 where- htraverse f =- foldChain1A- (fmap (DecAlt1_ . Done1) . f)- (\case IN.Night x (Comp y) g h k ->- (\x' y' -> DecAlt1_ (More1 (IN.Night x' y' g h k)))- <$> f x <*> (unDecAlt1 <$> y)- )+ htraverse f =+ foldChain1A+ (fmap (DecAlt1_ . Done1) . f)+ ( \case+ IN.Night x (Comp y) g h k ->+ (\x' y' -> DecAlt1_ (More1 (IN.Night x' y' g h k)))+ <$> f x+ <*> (unDecAlt1 <$> y)+ ) . unDecAlt1 instance HTraversable1 DecAlt1 where- htraverse1 f =- foldChain1A- (fmap (DecAlt1_ . Done1) . f)- (\case IN.Night x (Comp y) g h k ->- (\x' y' -> DecAlt1_ (More1 (IN.Night x' y' g h k)))- <$> f x <.> (unDecAlt1 <$> y)- )+ htraverse1 f =+ foldChain1A+ (fmap (DecAlt1_ . Done1) . f)+ ( \case+ IN.Night x (Comp y) g h k ->+ (\x' y' -> DecAlt1_ (More1 (IN.Night x' y' g h k)))+ <$> f x+ <.> (unDecAlt1 <$> y)+ ) . unDecAlt1 -- | A free 'Inalt' instance Inalt f => Interpret DecAlt1 f where- interpret f (DecAlt1_ x) = foldChain1 f (IN.runNight f id) x+ interpret f (DecAlt1_ x) = foldChain1 f (IN.runNight f id) x -- | The invariant version of 'ListF' and 'Dec': combines the capabilities of -- both 'ListF' and 'Dec' together.@@ -556,21 +584,24 @@ -- assemble it. -- -- @since 0.3.5.0-newtype DecAlt f a = DecAlt { unDecAlt :: Chain IN.Night IN.Not f a }+newtype DecAlt f a = DecAlt {unDecAlt :: Chain IN.Night IN.Not f a} deriving (Invariant, HFunctor) instance Inject DecAlt where- inject x = DecAlt $ More (IN.Night x (Done IN.refuted) id absurd Left)+ inject x = DecAlt $ More (IN.Night x (Done IN.refuted) id absurd Left) instance HTraversable DecAlt where- htraverse f =- foldChainA (pure . DecAlt . Done)- (\case IN.Night x (Comp y) g h k ->- (\x' y' -> DecAlt (More (IN.Night x' y' g h k)))- <$> f x <*> (unDecAlt <$> y)- )+ htraverse f =+ foldChainA+ (pure . DecAlt . Done)+ ( \case+ IN.Night x (Comp y) g h k ->+ (\x' y' -> DecAlt (More (IN.Night x' y' g h k)))+ <$> f x+ <*> (unDecAlt <$> y)+ ) . unDecAlt -- | A free 'Inplus' instance Inplus f => Interpret DecAlt f where- interpret f (DecAlt x) = foldChain (reject . IN.refute) (IN.runNight f id) x+ interpret f (DecAlt x) = foldChain (reject . IN.refute) (IN.runNight f id) x
src/Data/HFunctor/Final.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.HFunctor.Final--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -11,48 +11,50 @@ -- a constraint": generate a handy 'Interpret' instance for any constraint -- @c@. module Data.HFunctor.Final (- Final(..)- , fromFinal, toFinal- , FreeOf(..), finalizing- , hoistFinalC- , liftFinal0- , liftFinal1- , liftFinal2- ) where+ Final (..),+ fromFinal,+ toFinal,+ FreeOf (..),+ finalizing,+ hoistFinalC,+ liftFinal0,+ liftFinal1,+ liftFinal2,+) where -import Control.Applicative-import Control.Applicative.Free-import Control.Applicative.Lift-import Control.Applicative.ListF-import Control.Monad-import Control.Monad.Freer.Church hiding (toFree)-import Control.Monad.Reader-import Control.Monad.Trans.Identity-import Control.Natural-import Control.Natural.IsoF-import Data.Constraint.Trivial-import Data.Functor.Apply.Free-import Data.Functor.Bind-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Contravariant.Divisible.Free-import Data.Functor.Coyoneda-import Data.Functor.Invariant-import Data.Functor.Invariant.Inplicative-import Data.Functor.Invariant.Inplicative.Free-import Data.Functor.Invariant.Internative-import Data.Functor.Invariant.Internative.Free-import Data.Functor.Plus-import Data.HFunctor-import Data.HFunctor.Interpret-import Data.Kind-import Data.Pointed-import qualified Control.Alternative.Free as Alt-import qualified Control.Applicative.Free.Fast as FAF-import qualified Data.Functor.Contravariant.Coyoneda as CCY+import qualified Control.Alternative.Free as Alt+import Control.Applicative+import Control.Applicative.Free+import qualified Control.Applicative.Free.Fast as FAF+import Control.Applicative.Lift+import Control.Applicative.ListF+import Control.Monad+import Control.Monad.Freer.Church hiding (toFree)+import Control.Monad.Reader+import Control.Monad.Trans.Identity+import Control.Natural+import Control.Natural.IsoF+import Data.Constraint.Trivial+import Data.Functor.Apply.Free+import Data.Functor.Bind+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import qualified Data.Functor.Contravariant.Coyoneda as CCY+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Contravariant.Divisible.Free+import Data.Functor.Coyoneda+import Data.Functor.Invariant+import Data.Functor.Invariant.Inplicative+import Data.Functor.Invariant.Inplicative.Free+import Data.Functor.Invariant.Internative+import Data.Functor.Invariant.Internative.Free+import Data.Functor.Plus+import Data.HFunctor+import Data.HFunctor.Interpret+import Data.Kind+import Data.Pointed -- | A simple way to inject/reject into any eventual typeclass. --@@ -89,277 +91,314 @@ -- to use @'Final' c@ as an /instance/ of @c@ (using 'liftFinal0', -- 'liftFinal1', 'liftFinal2' for help). newtype Final c f a = Final- { runFinal :: forall g. c g => (forall x. f x -> g x) -> g a }+ {runFinal :: forall g. c g => (forall x. f x -> g x) -> g a} -- | Lift an action into a 'Final'.-liftFinal0- :: (forall g. c g => g a)- -> Final c f a+liftFinal0 ::+ (forall g. c g => g a) ->+ Final c f a liftFinal0 x = Final $ \_ -> x -- | Map the action in a 'Final'.-liftFinal1- :: (forall g. c g => g a -> g b)- -> Final c f a- -> Final c f b+liftFinal1 ::+ (forall g. c g => g a -> g b) ->+ Final c f a ->+ Final c f b liftFinal1 f x = Final $ \r -> f (runFinal x r) -- | Merge two 'Final' actions.-liftFinal2- :: (forall g. c g => g a -> g b -> g d)- -> Final c f a- -> Final c f b- -> Final c f d+liftFinal2 ::+ (forall g. c g => g a -> g b -> g d) ->+ Final c f a ->+ Final c f b ->+ Final c f d liftFinal2 f x y = Final $ \r -> f (runFinal x r) (runFinal y r) instance Functor (Final Functor f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Functor (Final Apply f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Apply (Final Apply f) where- (<.>) = liftFinal2 (<.>)- liftF2 f = liftFinal2 (liftF2 f)+ (<.>) = liftFinal2 (<.>)+ (.>) = liftFinal2 (.>)+ liftF2 f = liftFinal2 (liftF2 f) instance Functor (Final Bind f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Apply (Final Bind f) where- (<.>) = liftFinal2 (<.>)- liftF2 f = liftFinal2 (liftF2 f)+ (<.>) = liftFinal2 (<.>)+ (.>) = liftFinal2 (.>)+ liftF2 f = liftFinal2 (liftF2 f) instance Bind (Final Bind f) where- x >>- f = Final $ \r -> runFinal x r >>- \y -> runFinal (f y) r+ x >>- f = Final $ \r -> runFinal x r >>- \y -> runFinal (f y) r instance Functor (Final Applicative f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Apply (Final Applicative f) where- (<.>) = liftFinal2 (<*>)- liftF2 f = liftFinal2 (liftA2 f)+ (<.>) = liftFinal2 (<*>)+ (.>) = liftFinal2 (*>)+ liftF2 f = liftFinal2 (liftA2 f) instance Applicative (Final Applicative f) where- pure x = liftFinal0 (pure x)- (<*>) = liftFinal2 (<*>)- liftA2 f = liftFinal2 (liftA2 f)+ pure x = liftFinal0 (pure x)+ (<*>) = liftFinal2 (<*>)+ (*>) = liftFinal2 (*>)+ liftA2 f = liftFinal2 (liftA2 f) instance Functor (Final Alternative f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Apply (Final Alternative f) where- (<.>) = liftFinal2 (<*>)- liftF2 f = liftFinal2 (liftA2 f)+ (<.>) = liftFinal2 (<*>)+ (.>) = liftFinal2 (*>)+ liftF2 f = liftFinal2 (liftA2 f) instance Applicative (Final Alternative f) where- pure x = liftFinal0 (pure x)- (<*>) = liftFinal2 (<*>)- liftA2 f = liftFinal2 (liftA2 f)+ pure x = liftFinal0 (pure x)+ (<*>) = liftFinal2 (<*>)+ (*>) = liftFinal2 (*>)+ liftA2 f = liftFinal2 (liftA2 f)+ -- | @since 0.3.0.0 instance Alt (Final Alternative f) where- (<!>) = liftFinal2 (<|>)+ (<!>) = liftFinal2 (<|>)+ -- | @since 0.3.0.0 instance Plus (Final Alternative f) where- zero = liftFinal0 empty+ zero = liftFinal0 empty+ instance Alternative (Final Alternative f) where- empty = liftFinal0 empty- (<|>) = liftFinal2 (<|>)+ empty = liftFinal0 empty+ (<|>) = liftFinal2 (<|>) instance Functor (Final Monad f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Apply (Final Monad f) where- (<.>) = liftFinal2 (<*>)- liftF2 f = liftFinal2 (liftA2 f)+ (<.>) = liftFinal2 (<*>)+ (.>) = liftFinal2 (*>)+ liftF2 f = liftFinal2 (liftA2 f) instance Applicative (Final Monad f) where- pure x = liftFinal0 (pure x)- (<*>) = liftFinal2 (<*>)- liftA2 f = liftFinal2 (liftA2 f)+ pure x = liftFinal0 (pure x)+ (<*>) = liftFinal2 (<*>)+ (*>) = liftFinal2 (*>)+ liftA2 f = liftFinal2 (liftA2 f) instance Monad (Final Monad f) where- x >>= f = Final $ \r -> do- y <- runFinal x r- runFinal (f y) r+ x >>= f = Final $ \r -> do+ y <- runFinal x r+ runFinal (f y) r instance Functor (Final MonadPlus f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Applicative (Final MonadPlus f) where- pure x = liftFinal0 (pure x)- (<*>) = liftFinal2 (<*>)- liftA2 f = liftFinal2 (liftA2 f)+ pure x = liftFinal0 (pure x)+ (<*>) = liftFinal2 (<*>)+ (*>) = liftFinal2 (*>)+ liftA2 f = liftFinal2 (liftA2 f) instance Monad (Final MonadPlus f) where- x >>= f = Final $ \r -> do- y <- runFinal x r- runFinal (f y) r+ x >>= f = Final $ \r -> do+ y <- runFinal x r+ runFinal (f y) r+ -- | @since 0.3.0.0 instance Alt (Final MonadPlus f) where- (<!>) = liftFinal2 (<|>)+ (<!>) = liftFinal2 (<|>)+ -- | @since 0.3.0.0 instance Plus (Final MonadPlus f) where- zero = liftFinal0 empty+ zero = liftFinal0 empty+ instance Alternative (Final MonadPlus f) where- empty = liftFinal0 empty- (<|>) = liftFinal2 (<|>)+ empty = liftFinal0 empty+ (<|>) = liftFinal2 (<|>) instance MonadPlus (Final MonadPlus f) where- mzero = liftFinal0 mzero- mplus = liftFinal2 mplus+ mzero = liftFinal0 mzero+ mplus = liftFinal2 mplus instance Pointed (Final Pointed f) where- point x = liftFinal0 (point x)+ point x = liftFinal0 (point x) instance Functor (Final (MonadReader r) f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Applicative (Final (MonadReader r) f) where- pure x = liftFinal0 (pure x)- (<*>) = liftFinal2 (<*>)- liftA2 f = liftFinal2 (liftA2 f)+ pure x = liftFinal0 (pure x)+ (<*>) = liftFinal2 (<*>)+ (*>) = liftFinal2 (*>)+ liftA2 f = liftFinal2 (liftA2 f) instance Apply (Final (MonadReader r) f) where- (<.>) = liftFinal2 (<*>)- liftF2 f = liftFinal2 (liftA2 f)+ (<.>) = liftFinal2 (<*>)+ (.>) = liftFinal2 (*>)+ liftF2 f = liftFinal2 (liftA2 f) instance Monad (Final (MonadReader r) f) where- x >>= f = Final $ \r -> do- y <- runFinal x r- runFinal (f y) r+ x >>= f = Final $ \r -> do+ y <- runFinal x r+ runFinal (f y) r instance MonadReader r (Final (MonadReader r) f) where- ask = liftFinal0 ask- local f = liftFinal1 (local f)+ ask = liftFinal0 ask+ local f = liftFinal1 (local f) instance Functor (Final Alt f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Alt (Final Alt f) where- (<!>) = liftFinal2 (<!>)+ (<!>) = liftFinal2 (<!>) instance Functor (Final Plus f) where- fmap f = liftFinal1 (fmap f)+ fmap f = liftFinal1 (fmap f) instance Alt (Final Plus f) where- (<!>) = liftFinal2 (<!>)+ (<!>) = liftFinal2 (<!>) instance Plus (Final Plus f) where- zero = liftFinal0 zero+ zero = liftFinal0 zero -- | @since 0.3.0.0 instance Contravariant (Final Contravariant f) where- contramap f = liftFinal1 (contramap f)+ contramap f = liftFinal1 (contramap f) -- | @since 0.3.0.0 instance Contravariant (Final Divise f) where- contramap f = liftFinal1 (contramap f)+ contramap f = liftFinal1 (contramap f)+ -- | @since 0.3.0.0 instance Divise (Final Divise f) where- divise f = liftFinal2 (divise f)+ divise f = liftFinal2 (divise f) -- | @since 0.3.0.0 instance Contravariant (Final Divisible f) where- contramap f = liftFinal1 (contramap f)+ contramap f = liftFinal1 (contramap f)+ -- | @since 0.3.0.0 instance Divise (Final Divisible f) where- divise f = liftFinal2 (divide f)+ divise f = liftFinal2 (divide f)+ -- | @since 0.3.0.0 instance Divisible (Final Divisible f) where- divide f = liftFinal2 (divide f)- conquer = liftFinal0 conquer+ divide f = liftFinal2 (divide f)+ conquer = liftFinal0 conquer -- | @since 0.3.0.0 instance Contravariant (Final Decide f) where- contramap f = liftFinal1 (contramap f)+ contramap f = liftFinal1 (contramap f)+ -- | @since 0.3.0.0 instance Decide (Final Decide f) where- decide f = liftFinal2 (decide f)+ decide f = liftFinal2 (decide f) -- | @since 0.3.0.0 instance Contravariant (Final Conclude f) where- contramap f = liftFinal1 (contramap f)+ contramap f = liftFinal1 (contramap f)+ -- | @since 0.3.0.0 instance Decide (Final Conclude f) where- decide f = liftFinal2 (decide f)+ decide f = liftFinal2 (decide f)+ -- | @since 0.3.0.0 instance Conclude (Final Conclude f) where- conclude f = liftFinal0 (conclude f)+ conclude f = liftFinal0 (conclude f) -- | @since 0.3.0.0 instance Contravariant (Final Decidable f) where- contramap f = liftFinal1 (contramap f)+ contramap f = liftFinal1 (contramap f)+ -- | @since 0.3.0.0 instance Divisible (Final Decidable f) where- divide f = liftFinal2 (divide f)- conquer = liftFinal0 conquer+ divide f = liftFinal2 (divide f)+ conquer = liftFinal0 conquer+ -- | @since 0.3.0.0 instance Decide (Final Decidable f) where- decide f = liftFinal2 (choose f)+ decide f = liftFinal2 (choose f)+ -- | @since 0.3.0.0 instance Conclude (Final Decidable f) where- conclude f = liftFinal0 (lose f)+ conclude f = liftFinal0 (lose f)+ -- | @since 0.3.0.0 instance Decidable (Final Decidable f) where- choose f = liftFinal2 (choose f)- lose f = liftFinal0 (lose f)+ choose f = liftFinal2 (choose f)+ lose f = liftFinal0 (lose f) -- | @since 0.3.0.0 instance Invariant (Final Invariant f) where- invmap f g = liftFinal1 (invmap f g)+ invmap f g = liftFinal1 (invmap f g) -- | @since 0.4.0.0 instance Invariant (Final Inply f) where- invmap f g = liftFinal1 (invmap f g)+ invmap f g = liftFinal1 (invmap f g)+ -- | @since 0.4.0.0 instance Inply (Final Inply f) where- gather f g = liftFinal2 (gather f g)- gathered = liftFinal2 gathered+ gather f g = liftFinal2 (gather f g)+ gathered = liftFinal2 gathered -- | @since 0.4.0.0 instance Invariant (Final Inplicative f) where- invmap f g = liftFinal1 (invmap f g)+ invmap f g = liftFinal1 (invmap f g)+ -- | @since 0.4.0.0 instance Inply (Final Inplicative f) where- gather f g = liftFinal2 (gather f g)- gathered = liftFinal2 gathered+ gather f g = liftFinal2 (gather f g)+ gathered = liftFinal2 gathered+ -- | @since 0.4.0.0 instance Inplicative (Final Inplicative f) where- knot x = liftFinal0 (knot x)+ knot x = liftFinal0 (knot x) -- | @since 0.4.0.0 instance Invariant (Final Inalt f) where- invmap f g = liftFinal1 (invmap f g)+ invmap f g = liftFinal1 (invmap f g)+ -- | @since 0.4.0.0 instance Inalt (Final Inalt f) where- swerve f g h = liftFinal2 (swerve f g h)- swerved = liftFinal2 swerved+ swerve f g h = liftFinal2 (swerve f g h)+ swerved = liftFinal2 swerved -- | @since 0.4.0.0 instance Invariant (Final Inplus f) where- invmap f g = liftFinal1 (invmap f g)+ invmap f g = liftFinal1 (invmap f g)+ -- | @since 0.4.0.0 instance Inalt (Final Inplus f) where- swerve f g h = liftFinal2 (swerve f g h)- swerved = liftFinal2 swerved+ swerve f g h = liftFinal2 (swerve f g h)+ swerved = liftFinal2 swerved+ -- | @since 0.4.0.0 instance Inplus (Final Inplus f) where- reject f = liftFinal0 (reject f)+ reject f = liftFinal0 (reject f) -- | @since 0.4.0.0 instance Invariant (Final Internative f) where- invmap f g = liftFinal1 (invmap f g)+ invmap f g = liftFinal1 (invmap f g)+ -- | @since 0.4.0.0 instance Inply (Final Internative f) where- gather f g = liftFinal2 (gather f g)- gathered = liftFinal2 gathered+ gather f g = liftFinal2 (gather f g)+ gathered = liftFinal2 gathered+ -- | @since 0.4.0.0 instance Inplicative (Final Internative f) where- knot x = liftFinal0 (knot x)+ knot x = liftFinal0 (knot x)+ -- | @since 0.4.0.0 instance Inalt (Final Internative f) where- swerve f g h = liftFinal2 (swerve f g h)- swerved = liftFinal2 swerved+ swerve f g h = liftFinal2 (swerve f g h)+ swerved = liftFinal2 swerved+ -- | @since 0.4.0.0 instance Inplus (Final Internative f) where- reject f = liftFinal0 (reject f)+ reject f = liftFinal0 (reject f) -- | Re-interpret the context under a 'Final'.-hoistFinalC- :: (forall g x. (c g => g x) -> (d g => g x))- -> Final c f a- -> Final d f a+hoistFinalC ::+ (forall g x. (c g => g x) -> (d g => g x)) ->+ Final c f a ->+ Final d f a hoistFinalC f (Final x) = Final $ \r -> f (x (\y -> f (r y))) instance HFunctor (Final c) where- hmap f x = Final $ \r -> runFinal x (r . f)+ hmap f x = Final $ \r -> runFinal x (r . f) instance Inject (Final c) where- inject x = Final $ \f -> f x+ inject x = Final $ \f -> f x instance c f => Interpret (Final c) f where- retract x = runFinal x id- interpret f x = runFinal x f+ retract x = runFinal x id+ interpret f x = runFinal x f -- | "Finalize" an 'Interpret' instance. --@@ -424,58 +463,72 @@ -- that you can pattern match on and inspect, but @t@ might. This lets you -- work on a concrete structure if you desire. class FreeOf c t | t -> c where- -- | What "type" of functor is expected: should be either- -- 'Unconstrained', 'Functor', 'Contravariant', or 'Invariant'.- --- -- @since 0.3.0.0- type FreeFunctorBy t :: (Type -> Type) -> Constraint- type FreeFunctorBy t = Unconstrained+ -- | What "type" of functor is expected: should be either+ -- 'Unconstrained', 'Functor', 'Contravariant', or 'Invariant'.+ --+ -- @since 0.3.0.0+ type FreeFunctorBy t :: (Type -> Type) -> Constraint - fromFree :: t f ~> Final c f- toFree :: FreeFunctorBy t f => Final c f ~> t f+ type FreeFunctorBy t = Unconstrained - default fromFree :: Interpret t (Final c f) => t f ~> Final c f- fromFree = toFinal- default toFree :: (Inject t, c (t f)) => Final c f ~> t f- toFree = fromFinal+ fromFree :: t f ~> Final c f+ toFree :: FreeFunctorBy t f => Final c f ~> t f + default fromFree :: Interpret t (Final c f) => t f ~> Final c f+ fromFree = toFinal+ default toFree :: (Inject t, c (t f)) => Final c f ~> t f+ toFree = fromFinal+ -- | The isomorphism between a free structure and its encoding as 'Final'. finalizing :: (FreeOf c t, FreeFunctorBy t f) => t f <~> Final c f finalizing = isoF fromFree toFree -instance FreeOf Functor Coyoneda+instance FreeOf Functor Coyoneda+ -- | @since 0.3.0.0 instance FreeOf Contravariant CCY.Coyoneda-instance FreeOf Applicative Ap-instance FreeOf Apply Ap1-instance FreeOf Applicative FAF.Ap-instance FreeOf Alternative Alt.Alt-instance FreeOf Monad Free-instance FreeOf Bind Free1-instance FreeOf Pointed Lift-instance FreeOf Pointed MaybeApply++instance FreeOf Applicative Ap+instance FreeOf Apply Ap1+instance FreeOf Applicative FAF.Ap+instance FreeOf Alternative Alt.Alt+instance FreeOf Monad Free+instance FreeOf Bind Free1+instance FreeOf Pointed Lift+instance FreeOf Pointed MaybeApply+ -- | This could also be @'FreeOf' 'Divise'@ if @'FreeFunctorBy' 'NonEmptyF' -- ~ 'Contravariant'@. However, there isn't really a way to express this -- at the moment.-instance FreeOf Alt NonEmptyF where type FreeFunctorBy NonEmptyF = Functor+instance FreeOf Alt NonEmptyF where type FreeFunctorBy NonEmptyF = Functor+ -- | This could also be @'FreeOf' 'Divisible'@ if @'FreeFunctorBy' 'ListF' -- ~ 'Contravariant'@. However, there isn't really a way to express this -- at the moment.-instance FreeOf Plus ListF where type FreeFunctorBy ListF = Functor+instance FreeOf Plus ListF where type FreeFunctorBy ListF = Functor+ -- | @since 0.3.0.0-instance FreeOf Divise Div1+instance FreeOf Divise Div1+ -- | @since 0.3.0.0-instance FreeOf Divisible Div+instance FreeOf Divisible Div+ -- | @since 0.3.0.0-instance FreeOf Decide Dec1+instance FreeOf Decide Dec1+ -- | @since 0.3.0.0-instance FreeOf Conclude Dec+instance FreeOf Conclude Dec+ -- | @since 0.4.0.0-instance FreeOf Inply DivAp1 where type FreeFunctorBy DivAp1 = Invariant+instance FreeOf Inply DivAp1 where type FreeFunctorBy DivAp1 = Invariant+ -- | @since 0.4.0.0-instance FreeOf Inplicative DivAp+instance FreeOf Inplicative DivAp+ -- | @since 0.4.0.0-instance FreeOf Inalt DecAlt1 where type FreeFunctorBy DecAlt1 = Invariant+instance FreeOf Inalt DecAlt1 where type FreeFunctorBy DecAlt1 = Invariant+ -- | @since 0.4.0.0-instance FreeOf Inplus DecAlt+instance FreeOf Inplus DecAlt+ instance FreeOf Unconstrained IdentityT
src/Data/HFunctor/HTraversable.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.HFunctor.HTraversable--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -25,56 +25,63 @@ -- @since 0.3.6.0 module Data.HFunctor.HTraversable ( -- * 'HTraversable'- HTraversable(..)- , hsequence, hfoldMap, htoList, hmapDefault, hfor+ HTraversable (..),+ hsequence,+ hfoldMap,+ htoList,+ hmapDefault,+ hfor,+ -- * 'HTraversable1'- , HTraversable1(..)- , hsequence1, hfoldMap1, htoNonEmpty, hfor1- ) where+ HTraversable1 (..),+ hsequence1,+ hfoldMap1,+ htoNonEmpty,+ hfor1,+) where -import Control.Applicative-import Control.Applicative.Backwards-import Control.Applicative.Free-import Control.Applicative.Lift-import Control.Applicative.ListF-import Control.Applicative.Step-import Control.Comonad.Trans.Env-import Control.Monad.Trans.Compose-import Control.Monad.Trans.Identity-import Control.Monad.Trans.Maybe-import Control.Natural-import Data.Bifunctor.Joker-import Data.Bitraversable-import Data.Coerce-import Data.Functor.Apply-import Data.Functor.Coyoneda-import Data.Functor.Day (Day(..))-import Data.Functor.Identity-import Data.Functor.Product-import Data.Functor.Reverse-import Data.Functor.Sum-import Data.Functor.These-import Data.HFunctor-import Data.HFunctor.Internal-import Data.HFunctor.Interpret-import Data.List.NonEmpty (NonEmpty)-import Data.Semigroup (Endo(..))-import Data.Semigroup.Traversable-import Data.Tagged-import Data.Vinyl.CoRec-import Data.Vinyl.Core (Rec)-import Data.Vinyl.Recursive-import GHC.Generics-import qualified Control.Alternative.Free as Alt-import qualified Control.Applicative.Free as Ap-import qualified Control.Applicative.Free.Fast as FAF-import qualified Control.Applicative.Free.Final as FA-import qualified Control.Applicative.Lift as Lift+import qualified Control.Alternative.Free as Alt+import Control.Applicative+import Control.Applicative.Backwards+import Control.Applicative.Free+import qualified Control.Applicative.Free as Ap+import qualified Control.Applicative.Free.Fast as FAF+import qualified Control.Applicative.Free.Final as FA+import Control.Applicative.Lift+import qualified Control.Applicative.Lift as Lift+import Control.Applicative.ListF+import Control.Applicative.Step+import Control.Comonad.Trans.Env+import Control.Monad.Trans.Compose+import Control.Monad.Trans.Identity+import Control.Monad.Trans.Maybe+import Control.Natural+import Data.Bifunctor.Joker+import Data.Bitraversable+import Data.Coerce+import Data.Functor.Apply import qualified Data.Functor.Contravariant.Coyoneda as CCY-import qualified Data.Functor.Invariant.Day as ID-import qualified Data.Functor.Invariant.Night as IN-import qualified Data.SOP as SOP-+import Data.Functor.Coyoneda+import Data.Functor.Day (Day (..))+import Data.Functor.Identity+import qualified Data.Functor.Invariant.Day as ID+import qualified Data.Functor.Invariant.Night as IN+import Data.Functor.Product+import Data.Functor.Reverse+import Data.Functor.Sum+import Data.Functor.These+import Data.HFunctor+import Data.HFunctor.Internal+import Data.HFunctor.Interpret+import Data.List.NonEmpty (NonEmpty)+import qualified Data.SOP as SOP+import Data.Semigroup (Endo (..))+import Data.Semigroup.Traversable+import Data.Tagged+import Data.Vinyl.CoRec+import Data.Vinyl.Core (Rec)+import Data.Vinyl.Recursive+import GHC.Generics -- | A higher-kinded version of 'Traversable1', in the same way that -- 'HFunctor' is the higher-kinded version of 'Functor'. Gives you an@@ -85,9 +92,9 @@ -- -- @since 0.3.6.0 class HTraversable t => HTraversable1 t where- -- | An "effectful" 'hmap', in the same way that 'traverse1' is an- -- effectful 'fmap', guaranteeing at least one item.- htraverse1 :: Apply h => (forall x. f x -> h (g x)) -> t f a -> h (t g a)+ -- | An "effectful" 'hmap', in the same way that 'traverse1' is an+ -- effectful 'fmap', guaranteeing at least one item.+ htraverse1 :: Apply h => (forall x. f x -> h (g x)) -> t f a -> h (t g a) -- | A wrapper over a common pattern of "inverting" layers of a functor -- combinator that always contains at least one @f@ item.@@ -129,9 +136,9 @@ -- -- @since 0.3.6.0 class HFunctor t => HTraversable t where- -- | An "effectful" 'hmap', in the same way that 'traverse' is an- -- effectful 'fmap'.- htraverse :: Applicative h => (forall x. f x -> h (g x)) -> t f a -> h (t g a)+ -- | An "effectful" 'hmap', in the same way that 'traverse' is an+ -- effectful 'fmap'.+ htraverse :: Applicative h => (forall x. f x -> h (g x)) -> t f a -> h (t g a) -- | A wrapper over a common pattern of "inverting" layers of a functor -- combinator.@@ -171,261 +178,265 @@ hmapDefault f = runIdentity . htraverse (Identity . f) instance HTraversable Coyoneda where- htraverse f (Coyoneda g x) = Coyoneda g <$> f x+ htraverse f (Coyoneda g x) = Coyoneda g <$> f x instance HTraversable1 Coyoneda where- htraverse1 f (Coyoneda g x) = Coyoneda g <$> f x+ htraverse1 f (Coyoneda g x) = Coyoneda g <$> f x instance HTraversable CCY.Coyoneda where- htraverse f (CCY.Coyoneda g x) = CCY.Coyoneda g <$> f x+ htraverse f (CCY.Coyoneda g x) = CCY.Coyoneda g <$> f x instance HTraversable1 CCY.Coyoneda where- htraverse1 f (CCY.Coyoneda g x) = CCY.Coyoneda g <$> f x+ htraverse1 f (CCY.Coyoneda g x) = CCY.Coyoneda g <$> f x instance HTraversable Ap where- htraverse :: forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> Ap f a -> h (Ap g a)- htraverse f = go- where- go :: Ap f b -> h (Ap g b)- go = \case- Ap.Pure x -> pure (Ap.Pure x)- Ap.Ap x xs -> Ap.Ap <$> f x <*> go xs+ htraverse :: forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> Ap f a -> h (Ap g a)+ htraverse f = go+ where+ go :: Ap f b -> h (Ap g b)+ go = \case+ Ap.Pure x -> pure (Ap.Pure x)+ Ap.Ap x xs -> Ap.Ap <$> f x <*> go xs instance HTraversable ListF where- htraverse f (ListF xs) = ListF <$> traverse f xs+ htraverse f (ListF xs) = ListF <$> traverse f xs instance HTraversable NonEmptyF where- htraverse f (NonEmptyF xs) = NonEmptyF <$> traverse f xs+ htraverse f (NonEmptyF xs) = NonEmptyF <$> traverse f xs instance HTraversable1 NonEmptyF where- htraverse1 f (NonEmptyF xs) = NonEmptyF <$> traverse1 f xs+ htraverse1 f (NonEmptyF xs) = NonEmptyF <$> traverse1 f xs instance HTraversable MaybeF where- htraverse f (MaybeF xs) = MaybeF <$> traverse f xs+ htraverse f (MaybeF xs) = MaybeF <$> traverse f xs instance HTraversable (MapF k) where- htraverse f (MapF xs) = MapF <$> traverse f xs+ htraverse f (MapF xs) = MapF <$> traverse f xs instance HTraversable (NEMapF k) where- htraverse f (NEMapF xs) = NEMapF <$> traverse f xs+ htraverse f (NEMapF xs) = NEMapF <$> traverse f xs instance HTraversable1 (NEMapF k) where- htraverse1 f (NEMapF xs) = NEMapF <$> traverse1 f xs+ htraverse1 f (NEMapF xs) = NEMapF <$> traverse1 f xs instance HTraversable Alt.Alt where- htraverse f (Alt.Alt xs) = Alt.Alt <$> traverse (htraverse f) xs+ htraverse f (Alt.Alt xs) = Alt.Alt <$> traverse (htraverse f) xs instance HTraversable Alt.AltF where- htraverse f = \case- Alt.Ap x xs -> Alt.Ap <$> f x <*> htraverse f xs- Alt.Pure x -> pure (Alt.Pure x)+ htraverse f = \case+ Alt.Ap x xs -> Alt.Ap <$> f x <*> htraverse f xs+ Alt.Pure x -> pure (Alt.Pure x) instance HTraversable Step where- htraverse f (Step n x) = Step n <$> f x+ htraverse f (Step n x) = Step n <$> f x instance HTraversable1 Step where- htraverse1 f (Step n x) = Step n <$> f x+ htraverse1 f (Step n x) = Step n <$> f x instance HTraversable Steps where- htraverse f (Steps x) = Steps <$> traverse f x+ htraverse f (Steps x) = Steps <$> traverse f x instance HTraversable1 Steps where- htraverse1 f (Steps x) = Steps <$> traverse1 f x+ htraverse1 f (Steps x) = Steps <$> traverse1 f x instance HTraversable Flagged where- htraverse f (Flagged b x) = Flagged b <$> f x+ htraverse f (Flagged b x) = Flagged b <$> f x instance HTraversable1 Flagged where- htraverse1 f (Flagged b x) = Flagged b <$> f x+ htraverse1 f (Flagged b x) = Flagged b <$> f x instance HTraversable MaybeT where- htraverse f (MaybeT x) = MaybeT <$> f x+ htraverse f (MaybeT x) = MaybeT <$> f x instance HTraversable1 MaybeT where- htraverse1 f (MaybeT x) = MaybeT <$> f x+ htraverse1 f (MaybeT x) = MaybeT <$> f x instance HTraversable FAF.Ap where- htraverse = itraverse+ htraverse = itraverse instance HTraversable FA.Ap where- htraverse = itraverse+ htraverse = itraverse instance HTraversable IdentityT where- htraverse f (IdentityT x) = IdentityT <$> f x+ htraverse f (IdentityT x) = IdentityT <$> f x instance HTraversable1 IdentityT where- htraverse1 f (IdentityT x) = IdentityT <$> f x+ htraverse1 f (IdentityT x) = IdentityT <$> f x instance HTraversable Lift where- htraverse f = \case- Lift.Pure x -> pure (Lift.Pure x)- Lift.Other y -> Lift.Other <$> f y+ htraverse f = \case+ Lift.Pure x -> pure (Lift.Pure x)+ Lift.Other y -> Lift.Other <$> f y instance HTraversable MaybeApply where- htraverse f (MaybeApply x) = MaybeApply <$> bitraverse f pure x+ htraverse f (MaybeApply x) = MaybeApply <$> bitraverse f pure x instance HTraversable Backwards where- htraverse f (Backwards x) = Backwards <$> f x+ htraverse f (Backwards x) = Backwards <$> f x instance HTraversable WrappedApplicative where- htraverse f (WrapApplicative x) = WrapApplicative <$> f x+ htraverse f (WrapApplicative x) = WrapApplicative <$> f x instance HTraversable Tagged where- htraverse _ = pure . coerce+ htraverse _ = pure . coerce instance HTraversable Reverse where- htraverse f (Reverse x) = Reverse <$> f x+ htraverse f (Reverse x) = Reverse <$> f x instance HTraversable1 Reverse where- htraverse1 f (Reverse x) = Reverse <$> f x+ htraverse1 f (Reverse x) = Reverse <$> f x instance (HTraversable s, HTraversable t) => HTraversable (ComposeT s t) where- htraverse f (ComposeT x) = ComposeT <$> htraverse (htraverse f) x+ htraverse f (ComposeT x) = ComposeT <$> htraverse (htraverse f) x instance Traversable f => HTraversable ((:.:) f) where- htraverse f (Comp1 x) = Comp1 <$> traverse f x+ htraverse f (Comp1 x) = Comp1 <$> traverse f x instance Traversable1 f => HTraversable1 ((:.:) f) where- htraverse1 f (Comp1 x) = Comp1 <$> traverse1 f x+ htraverse1 f (Comp1 x) = Comp1 <$> traverse1 f x instance HTraversable (M1 i c) where- htraverse f (M1 x) = M1 <$> f x+ htraverse f (M1 x) = M1 <$> f x instance HTraversable1 (M1 i c) where- htraverse1 f (M1 x) = M1 <$> f x+ htraverse1 f (M1 x) = M1 <$> f x instance HTraversable Void2 where- htraverse _ = \case {}+ htraverse _ = \case {} instance HTraversable1 Void2 where- htraverse1 _ = \case {}+ htraverse1 _ = \case {} instance HTraversable (EnvT e) where- htraverse f (EnvT e x) = EnvT e <$> f x+ htraverse f (EnvT e x) = EnvT e <$> f x instance HTraversable1 (EnvT e) where- htraverse1 f (EnvT e x) = EnvT e <$> f x+ htraverse1 f (EnvT e x) = EnvT e <$> f x instance HTraversable Rec where- htraverse = rtraverse+ htraverse = rtraverse instance HTraversable CoRec where- htraverse f (CoRec x) = CoRec <$> f x+ htraverse f (CoRec x) = CoRec <$> f x instance HTraversable SOP.NP where- htraverse :: forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> SOP.NP f a -> h (SOP.NP g a)- htraverse f = go- where- go :: SOP.NP f b -> h (SOP.NP g b)- go = \case- SOP.Nil -> pure SOP.Nil- x SOP.:* xs -> (SOP.:*) <$> f x <*> go xs+ htraverse ::+ forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> SOP.NP f a -> h (SOP.NP g a)+ htraverse f = go+ where+ go :: SOP.NP f b -> h (SOP.NP g b)+ go = \case+ SOP.Nil -> pure SOP.Nil+ x SOP.:* xs -> (SOP.:*) <$> f x <*> go xs instance HTraversable SOP.NS where- htraverse :: forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> SOP.NS f a -> h (SOP.NS g a)- htraverse f = go- where- go :: SOP.NS f b -> h (SOP.NS g b)- go = \case- SOP.Z x -> SOP.Z <$> f x- SOP.S xs -> SOP.S <$> go xs+ htraverse ::+ forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> SOP.NS f a -> h (SOP.NS g a)+ htraverse f = go+ where+ go :: SOP.NS f b -> h (SOP.NS g b)+ go = \case+ SOP.Z x -> SOP.Z <$> f x+ SOP.S xs -> SOP.S <$> go xs instance HTraversable1 SOP.NS where- htraverse1- :: forall f g h a. Apply h- => (forall x. f x -> h (g x))- -> SOP.NS f a- -> h (SOP.NS g a)- htraverse1 f = go- where- go :: SOP.NS f b -> h (SOP.NS g b)- go = \case- SOP.Z x -> SOP.Z <$> f x- SOP.S xs -> SOP.S <$> go xs+ htraverse1 ::+ forall f g h a.+ Apply h =>+ (forall x. f x -> h (g x)) ->+ SOP.NS f a ->+ h (SOP.NS g a)+ htraverse1 f = go+ where+ go :: SOP.NS f b -> h (SOP.NS g b)+ go = \case+ SOP.Z x -> SOP.Z <$> f x+ SOP.S xs -> SOP.S <$> go xs instance HTraversable (Day f) where- htraverse f (Day x y g) = (\y' -> Day x y' g) <$> f y+ htraverse f (Day x y g) = (\y' -> Day x y' g) <$> f y instance HTraversable1 (Day f) where- htraverse1 f (Day x y g) = (\y' -> Day x y' g) <$> f y+ htraverse1 f (Day x y g) = (\y' -> Day x y' g) <$> f y instance HTraversable (ID.Day f) where- htraverse f (ID.Day x y g h) = (\y' -> ID.Day x y' g h) <$> f y+ htraverse f (ID.Day x y g h) = (\y' -> ID.Day x y' g h) <$> f y instance HTraversable1 (ID.Day f) where- htraverse1 f (ID.Day x y g h) = (\y' -> ID.Day x y' g h) <$> f y+ htraverse1 f (ID.Day x y g h) = (\y' -> ID.Day x y' g h) <$> f y instance HTraversable (IN.Night f) where- htraverse f (IN.Night x y g h j) = (\y' -> IN.Night x y' g h j) <$> f y+ htraverse f (IN.Night x y g h j) = (\y' -> IN.Night x y' g h j) <$> f y instance HTraversable1 (IN.Night f) where- htraverse1 f (IN.Night x y g h j) = (\y' -> IN.Night x y' g h j) <$> f y+ htraverse1 f (IN.Night x y g h j) = (\y' -> IN.Night x y' g h j) <$> f y instance HTraversable ((:*:) f) where- htraverse f (x :*: y) = (x :*:) <$> f y+ htraverse f (x :*: y) = (x :*:) <$> f y instance HTraversable1 ((:*:) f) where- htraverse1 f (x :*: y) = (x :*:) <$> f y+ htraverse1 f (x :*: y) = (x :*:) <$> f y instance HTraversable ((:+:) f) where- htraverse f = \case- L1 x -> pure (L1 x)- R1 y -> R1 <$> f y+ htraverse f = \case+ L1 x -> pure (L1 x)+ R1 y -> R1 <$> f y instance HTraversable (Product f) where- htraverse f (Pair x y) = Pair x <$> f y+ htraverse f (Pair x y) = Pair x <$> f y instance HTraversable1 (Product f) where- htraverse1 f (Pair x y) = Pair x <$> f y+ htraverse1 f (Pair x y) = Pair x <$> f y instance HTraversable (Sum f) where- htraverse f = \case- InL x -> pure (InL x)- InR y -> InR <$> f y+ htraverse f = \case+ InL x -> pure (InL x)+ InR y -> InR <$> f y instance HTraversable (Joker f) where- htraverse _ = pure . coerce+ htraverse _ = pure . coerce instance HTraversable (These1 f) where- htraverse f = \case- This1 x -> pure $ This1 x- That1 y -> That1 <$> f y- These1 x y -> These1 x <$> f y+ htraverse f = \case+ This1 x -> pure $ This1 x+ That1 y -> That1 <$> f y+ These1 x y -> These1 x <$> f y instance HTraversable (Void3 f) where- htraverse _ = \case {}+ htraverse _ = \case {} instance HTraversable ProxyF where- htraverse _ = pure . coerce+ htraverse _ = pure . coerce instance HTraversable (ConstF e) where- htraverse _ = pure . coerce+ htraverse _ = pure . coerce instance HTraversable t => HTraversable (HLift t) where- htraverse f = \case- HPure x -> HPure <$> f x- HOther x -> HOther <$> htraverse f x+ htraverse f = \case+ HPure x -> HPure <$> f x+ HOther x -> HOther <$> htraverse f x instance HTraversable1 t => HTraversable1 (HLift t) where- htraverse1 f = \case- HPure x -> HPure <$> f x- HOther x -> HOther <$> htraverse1 f x+ htraverse1 f = \case+ HPure x -> HPure <$> f x+ HOther x -> HOther <$> htraverse1 f x instance HTraversable t => HTraversable (HFree t) where- htraverse :: forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> HFree t f a -> h (HFree t g a)- htraverse f = go- where- go :: HFree t f b -> h (HFree t g b)- go = \case- HReturn x -> HReturn <$> f x- HJoin x -> HJoin <$> htraverse go x+ htraverse ::+ forall f g h a. Applicative h => (forall x. f x -> h (g x)) -> HFree t f a -> h (HFree t g a)+ htraverse f = go+ where+ go :: HFree t f b -> h (HFree t g b)+ go = \case+ HReturn x -> HReturn <$> f x+ HJoin x -> HJoin <$> htraverse go x instance HTraversable1 t => HTraversable1 (HFree t) where- htraverse1 :: forall f g h a. Apply h => (forall x. f x -> h (g x)) -> HFree t f a -> h (HFree t g a)- htraverse1 f = go- where- go :: HFree t f b -> h (HFree t g b)- go = \case- HReturn x -> HReturn <$> f x- HJoin x -> HJoin <$> htraverse1 go x-+ htraverse1 ::+ forall f g h a. Apply h => (forall x. f x -> h (g x)) -> HFree t f a -> h (HFree t g a)+ htraverse1 f = go+ where+ go :: HFree t f b -> h (HFree t g b)+ go = \case+ HReturn x -> HReturn <$> f x+ HJoin x -> HJoin <$> htraverse1 go x
src/Data/HFunctor/Internal.hs view
@@ -1,63 +1,67 @@-{-# LANGUAGE DerivingVia #-}+{-# LANGUAGE DerivingVia #-} {-# OPTIONS_HADDOCK hide, not-home #-} module Data.HFunctor.Internal (- HFunctor(..)- , HBifunctor(..)- , WrappedHBifunctor(..)- , sumSum, prodProd- , generalize, absorb- , NDL, ndlSingleton, fromNDL- ) where+ HFunctor (..),+ HBifunctor (..),+ WrappedHBifunctor (..),+ sumSum,+ prodProd,+ generalize,+ absorb,+ NDL,+ ndlSingleton,+ fromNDL,+) where -import Control.Applicative.Backwards-import Control.Applicative.Free-import Control.Applicative.Lift-import Control.Applicative.ListF-import Control.Applicative.Step-import Control.Comonad.Trans.Env-import Control.Monad.Freer.Church-import Control.Monad.Trans.Compose-import Control.Monad.Trans.Identity-import Control.Monad.Trans.Maybe-import Control.Monad.Trans.Reader-import Control.Natural-import Control.Natural.IsoF-import Data.Bifunctor-import Data.Bifunctor.Joker-import Data.Coerce-import Data.Foldable-import Data.Functor.Bind-import Data.Functor.Contravariant.Night (Night(..))-import Data.Functor.Coyoneda-import Data.Functor.Day (Day(..))-import Data.Functor.Identity-import Data.Functor.Product-import Data.Functor.Reverse-import Data.Functor.Sum-import Data.Functor.These-import Data.Functor.Yoneda-import Data.Kind-import Data.List.NonEmpty (NonEmpty(..))-import Data.Proxy-import Data.Tagged-import Data.Vinyl.CoRec-import Data.Vinyl.Core (Rec)-import Data.Vinyl.Recursive-import GHC.Generics-import qualified Control.Alternative.Free as Alt-import qualified Control.Applicative.Free.Fast as FAF-import qualified Control.Applicative.Free.Final as FA-import qualified Control.Monad.Free.Church as MC+import qualified Control.Alternative.Free as Alt+import Control.Applicative.Backwards+import Control.Applicative.Free+import qualified Control.Applicative.Free.Fast as FAF+import qualified Control.Applicative.Free.Final as FA+import Control.Applicative.Lift+import Control.Applicative.ListF+import Control.Applicative.Step+import Control.Comonad.Trans.Env+import qualified Control.Monad.Free.Church as MC+import Control.Monad.Freer.Church+import Control.Monad.Trans.Compose+import Control.Monad.Trans.Identity+import Control.Monad.Trans.Maybe+import Control.Monad.Trans.Reader+import Control.Natural+import Control.Natural.IsoF+import Data.Bifunctor+import Data.Bifunctor.Joker+import Data.Coerce+import Data.Foldable+import Data.Functor.Bind import qualified Data.Functor.Contravariant.Coyoneda as CCY-import qualified Data.Functor.Contravariant.Day as CD-import qualified Data.Functor.Contravariant.Night as N-import qualified Data.Functor.Day as D-import qualified Data.Functor.Invariant.Day as ID-import qualified Data.Functor.Invariant.Night as IN-import qualified Data.SOP as SOP-import qualified Data.SOP.NP as SOP-import qualified Data.SOP.NS as SOP+import qualified Data.Functor.Contravariant.Day as CD+import Data.Functor.Contravariant.Night (Night (..))+import qualified Data.Functor.Contravariant.Night as N+import Data.Functor.Coyoneda+import Data.Functor.Day (Day (..))+import qualified Data.Functor.Day as D+import Data.Functor.Identity+import qualified Data.Functor.Invariant.Day as ID+import qualified Data.Functor.Invariant.Night as IN+import Data.Functor.Product+import Data.Functor.Reverse+import Data.Functor.Sum+import Data.Functor.These+import Data.Functor.Yoneda+import Data.Kind+import Data.List.NonEmpty (NonEmpty (..))+import Data.Proxy+import qualified Data.SOP as SOP+import qualified Data.SOP.NP as SOP+import qualified Data.SOP.NS as SOP+import Data.Tagged+import Data.Vinyl.CoRec+import Data.Vinyl.Core (Rec)+import Data.Vinyl.Recursive+import GHC.Generics -- | An 'HFunctor' can be thought of a unary "functor transformer" --- -- a basic functor combinator. It takes a functor as input and returns@@ -83,29 +87,29 @@ -- -- This class is also found in the /hschema/ library with the same name. class HFunctor t where- -- | If we can turn an @f@ into a @g@, then we can turn a @t f@ into- -- a @t g@.- --- -- It must be the case that- --- -- @- -- 'hmap' 'id' == id- -- @- --- -- Essentially, @t f@ adds some "extra structure" to @f@. 'hmap'- -- must swap out the functor, /without affecting the added structure/.- --- -- For example, @'ListF' f a@ is essentially a list of @f a@s. If we- -- 'hmap' to swap out the @f a@s for @g a@s, then we must ensure that- -- the "added structure" (here, the number of items in the list, and- -- the ordering of those items) remains the same. So, 'hmap' must- -- preserve the number of items in the list, and must maintain the- -- ordering.- --- -- The law @'hmap' 'id' == id@ is a way of formalizing this property.- hmap :: f ~> g -> t f ~> t g+ -- | If we can turn an @f@ into a @g@, then we can turn a @t f@ into+ -- a @t g@.+ --+ -- It must be the case that+ --+ -- @+ -- 'hmap' 'id' == id+ -- @+ --+ -- Essentially, @t f@ adds some "extra structure" to @f@. 'hmap'+ -- must swap out the functor, /without affecting the added structure/.+ --+ -- For example, @'ListF' f a@ is essentially a list of @f a@s. If we+ -- 'hmap' to swap out the @f a@s for @g a@s, then we must ensure that+ -- the "added structure" (here, the number of items in the list, and+ -- the ordering of those items) remains the same. So, 'hmap' must+ -- preserve the number of items in the list, and must maintain the+ -- ordering.+ --+ -- The law @'hmap' 'id' == id@ is a way of formalizing this property.+ hmap :: f ~> g -> t f ~> t g - {-# MINIMAL hmap #-}+ {-# MINIMAL hmap #-} -- | A 'HBifunctor' is like an 'HFunctor', but it enhances /two/ different -- functors instead of just one.@@ -135,19 +139,19 @@ -- This ensures that 'hleft', 'hright', and 'hbimap' do not affect the -- structure that @t@ adds on top of the underlying functors. class HBifunctor (t :: (k -> Type) -> (k -> Type) -> k -> Type) where- -- | Swap out the first transformed functor.- hleft :: f ~> j -> t f g ~> t j g- hleft f x = hbimap f id x+ -- | Swap out the first transformed functor.+ hleft :: f ~> j -> t f g ~> t j g+ hleft f x = hbimap f id x - -- | Swap out the second transformed functor.- hright :: g ~> l -> t f g ~> t f l- hright f x = hbimap id f x+ -- | Swap out the second transformed functor.+ hright :: g ~> l -> t f g ~> t f l+ hright f x = hbimap id f x - -- | Swap out both transformed functors at the same time.- hbimap :: f ~> j -> g ~> l -> t f g ~> t j l- hbimap f g = hleft f . hright g+ -- | Swap out both transformed functors at the same time.+ hbimap :: f ~> j -> g ~> l -> t f g ~> t j l+ hbimap f g = hleft f . hright g - {-# MINIMAL hleft, hright | hbimap #-}+ {-# MINIMAL hleft, hright | hbimap #-} -- | Useful newtype to allow us to derive an 'HFunctor' instance from any -- instance of 'HBifunctor', using -XDerivingVia.@@ -160,16 +164,15 @@ -- @ -- -- to give us an automatic 'HFunctor' instance and save us some work.-newtype WrappedHBifunctor t (f :: k -> Type) (g :: k -> Type) (a :: k)- = WrapHBifunctor { unwrapHBifunctor :: t f g a }- deriving Functor+newtype WrappedHBifunctor t (f :: k -> Type) (g :: k -> Type) (a :: k) = WrapHBifunctor {unwrapHBifunctor :: t f g a}+ deriving (Functor) -- | Isomorphism between different varieities of ':+:'. sumSum :: (f :+: g) <~> Sum f g sumSum = isoF to_ from_ where- to_ (L1 x) = InL x- to_ (R1 y) = InR y+ to_ (L1 x) = InL x+ to_ (R1 y) = InR y from_ (InL x) = L1 x from_ (InR y) = R1 y @@ -177,7 +180,7 @@ prodProd :: (f :*: g) <~> Product f g prodProd = isoF to_ from_ where- to_ (x :*: y) = Pair x y+ to_ (x :*: y) = Pair x y from_ (Pair x y) = x :*: y -- | Turn 'Identity' into any @'Applicative' f@. Can be useful as an@@ -198,235 +201,235 @@ newtype NDL a = NDL ([a] -> NonEmpty a) ndlSingleton :: a -> NDL a-ndlSingleton x = NDL (x:|)+ndlSingleton x = NDL (x :|) fromNDL :: NDL a -> NonEmpty a fromNDL (NDL f) = f [] instance Semigroup (NDL a) where- NDL x <> NDL y = NDL (x . toList . y)+ NDL x <> NDL y = NDL (x . toList . y) instance HFunctor Coyoneda where- hmap f x = hoistCoyoneda f x+ hmap f x = hoistCoyoneda f x -- | @since 0.3.0.0 instance HFunctor CCY.Coyoneda where- hmap f (CCY.Coyoneda g x) = CCY.Coyoneda g (f x)+ hmap f (CCY.Coyoneda g x) = CCY.Coyoneda g (f x) instance HFunctor Ap where- hmap f x = hoistAp f x+ hmap f x = hoistAp f x instance HFunctor ListF where- hmap f (ListF xs) = ListF (map f xs)+ hmap f (ListF xs) = ListF (map f xs) instance HFunctor NonEmptyF where- hmap f (NonEmptyF xs) = NonEmptyF (fmap f xs)+ hmap f (NonEmptyF xs) = NonEmptyF (fmap f xs) instance HFunctor MaybeF where- hmap f (MaybeF xs) = MaybeF (fmap f xs)+ hmap f (MaybeF xs) = MaybeF (fmap f xs) instance HFunctor (MapF k) where- hmap f (MapF xs) = MapF (fmap f xs)+ hmap f (MapF xs) = MapF (fmap f xs) instance HFunctor (NEMapF k) where- hmap f (NEMapF xs) = NEMapF (fmap f xs)+ hmap f (NEMapF xs) = NEMapF (fmap f xs) instance HFunctor Alt.Alt where- hmap f x = Alt.hoistAlt f x+ hmap f x = Alt.hoistAlt f x -- | @since 0.3.6.0 instance HFunctor Alt.AltF where- hmap f = \case- Alt.Ap x xs -> Alt.Ap (f x) (hmap f xs)- Alt.Pure x -> Alt.Pure x+ hmap f = \case+ Alt.Ap x xs -> Alt.Ap (f x) (hmap f xs)+ Alt.Pure x -> Alt.Pure x instance HFunctor Step where- hmap f (Step n x) = Step n (f x)+ hmap f (Step n x) = Step n (f x) instance HFunctor Steps where- hmap f (Steps xs) = Steps (f <$> xs)+ hmap f (Steps xs) = Steps (f <$> xs) instance HFunctor Flagged where- hmap f (Flagged b x) = Flagged b (f x)+ hmap f (Flagged b x) = Flagged b (f x) instance HFunctor Free where- hmap f x = hoistFree f x+ hmap f x = hoistFree f x instance HFunctor Free1 where- hmap f x = hoistFree1 f x+ hmap f x = hoistFree1 f x -- | Note that there is no 'Data.HFunctor.Interpret.Interpret' or -- 'Data.HFunctor.Bind' instance, because 'Data.HFunctor.inject' requires -- @'Functor' f@. instance HFunctor MC.F where- hmap f x = MC.hoistF f x+ hmap f x = MC.hoistF f x -- | Note that there is no 'Data.HFunctor.Interpret.Interpret' or -- 'Data.HFunctor.Bind' instance, because 'Data.HFunctor.inject' requires -- @'Functor' f@. instance HFunctor MaybeT where- hmap f x = mapMaybeT f x+ hmap f x = mapMaybeT f x instance HFunctor Yoneda where- hmap f x = Yoneda $ f . runYoneda x+ hmap f x = Yoneda $ f . runYoneda x instance HFunctor FA.Ap where- hmap f x = FA.hoistAp f x+ hmap f x = FA.hoistAp f x instance HFunctor FAF.Ap where- hmap f x = FAF.hoistAp f x+ hmap f x = FAF.hoistAp f x instance HFunctor IdentityT where- hmap f x = mapIdentityT f x+ hmap f x = mapIdentityT f x instance HFunctor Lift where- hmap f x = mapLift f x+ hmap f x = mapLift f x instance HFunctor MaybeApply where- hmap f (MaybeApply x) = MaybeApply (first f x)+ hmap f (MaybeApply x) = MaybeApply (first f x) instance HFunctor Backwards where- hmap f (Backwards x) = Backwards (f x)+ hmap f (Backwards x) = Backwards (f x) instance HFunctor WrappedApplicative where- hmap f (WrapApplicative x) = WrapApplicative (f x)+ hmap f (WrapApplicative x) = WrapApplicative (f x) instance HFunctor (ReaderT r) where- hmap f x = mapReaderT f x+ hmap f x = mapReaderT f x instance HFunctor Tagged where- hmap _ x = coerce x+ hmap _ x = coerce x instance HFunctor Reverse where- hmap f (Reverse x) = Reverse (f x)+ hmap f (Reverse x) = Reverse (f x) instance (HFunctor s, HFunctor t) => HFunctor (ComposeT s t) where- hmap f (ComposeT x) = ComposeT $ hmap (hmap f) x+ hmap f (ComposeT x) = ComposeT $ hmap (hmap f) x instance Functor f => HFunctor ((:.:) f) where- hmap f (Comp1 x) = Comp1 (f <$> x)+ hmap f (Comp1 x) = Comp1 (f <$> x) instance HFunctor (M1 i c) where- hmap f (M1 x) = M1 (f x)+ hmap f (M1 x) = M1 (f x) instance HFunctor Void2 where- hmap _ x = coerce x+ hmap _ x = coerce x instance HFunctor (EnvT e) where- hmap f (EnvT e x) = EnvT e (f x)+ hmap f (EnvT e x) = EnvT e (f x) instance HFunctor Rec where- hmap f x = rmap f x+ hmap f x = rmap f x instance HFunctor CoRec where- hmap f (CoRec x) = CoRec (f x)+ hmap f (CoRec x) = CoRec (f x) -- | @since 0.3.0.0 instance HFunctor SOP.NP where- hmap f = SOP.cata_NP SOP.Nil ((SOP.:*) . f)+ hmap f = SOP.cata_NP SOP.Nil ((SOP.:*) . f) -- | @since 0.3.0.0 instance HFunctor SOP.NS where- hmap f = SOP.cata_NS (SOP.Z . f) SOP.S+ hmap f = SOP.cata_NS (SOP.Z . f) SOP.S instance HFunctor (Joker f) where- hmap _ x = coerce x+ hmap _ x = coerce x instance HFunctor (Void3 f) where- hmap _ = \case {}+ hmap _ = \case {} instance HFunctor (Comp f) where- hmap f (x :>>= h) = x :>>= (f . h)+ hmap f (x :>>= h) = x :>>= (f . h) instance HBifunctor (:*:) where- hleft f (x :*: y) = f x :*: y- hright g (x :*: y) = x :*: g y- hbimap f g (x :*: y) = f x :*: g y+ hleft f (x :*: y) = f x :*: y+ hright g (x :*: y) = x :*: g y+ hbimap f g (x :*: y) = f x :*: g y instance HBifunctor Product where- hleft f (Pair x y) = Pair (f x) y- hright g (Pair x y) = Pair x (g y)- hbimap f g (Pair x y) = Pair (f x) (g y)+ hleft f (Pair x y) = Pair (f x) y+ hright g (Pair x y) = Pair x (g y)+ hbimap f g (Pair x y) = Pair (f x) (g y) instance HBifunctor Day where- hleft f x = D.trans1 f x- hright f x = D.trans2 f x- hbimap f g (Day x y z) = Day (f x) (g y) z+ hleft f x = D.trans1 f x+ hright f x = D.trans2 f x+ hbimap f g (Day x y z) = Day (f x) (g y) z -- | @since 0.3.0.0 instance HBifunctor CD.Day where- hleft f x = CD.trans1 f x- hright f x = CD.trans2 f x- hbimap f g (CD.Day x y z) = CD.Day (f x) (g y) z+ hleft f x = CD.trans1 f x+ hright f x = CD.trans2 f x+ hbimap f g (CD.Day x y z) = CD.Day (f x) (g y) z -- | @since 0.3.4.0 instance HBifunctor ID.Day where- hbimap f g (ID.Day x y h j) = ID.Day (f x) (g y) h j+ hbimap f g (ID.Day x y h j) = ID.Day (f x) (g y) h j instance HBifunctor IN.Night where- hbimap f g (IN.Night x y h j k) = IN.Night (f x) (g y) h j k+ hbimap f g (IN.Night x y h j k) = IN.Night (f x) (g y) h j k -- | @since 0.3.0.0 instance HBifunctor Night where- hleft f x = N.trans1 f x- hright f x = N.trans2 f x- hbimap f g (Night x y z) = Night (f x) (g y) z+ hleft f x = N.trans1 f x+ hright f x = N.trans2 f x+ hbimap f g (Night x y z) = Night (f x) (g y) z instance HBifunctor (:+:) where- hleft f = \case- L1 x -> L1 (f x)- R1 y -> R1 y+ hleft f = \case+ L1 x -> L1 (f x)+ R1 y -> R1 y - hright g = \case- L1 x -> L1 x- R1 y -> R1 (g y)+ hright g = \case+ L1 x -> L1 x+ R1 y -> R1 (g y) - hbimap f g = \case- L1 x -> L1 (f x)- R1 y -> R1 (g y)+ hbimap f g = \case+ L1 x -> L1 (f x)+ R1 y -> R1 (g y) instance HBifunctor Sum where- hleft f = \case- InL x -> InL (f x)- InR y -> InR y+ hleft f = \case+ InL x -> InL (f x)+ InR y -> InR y - hright g = \case- InL x -> InL x- InR y -> InR (g y)+ hright g = \case+ InL x -> InL x+ InR y -> InR (g y) - hbimap f g = \case- InL x -> InL (f x)- InR y -> InR (g y)+ hbimap f g = \case+ InL x -> InL (f x)+ InR y -> InR (g y) instance HBifunctor These1 where- hbimap f g = \case- This1 x -> This1 (f x)- That1 y -> That1 (g y)- These1 x y -> These1 (f x) (g y)+ hbimap f g = \case+ This1 x -> This1 (f x)+ That1 y -> That1 (g y)+ These1 x y -> These1 (f x) (g y) instance HBifunctor Joker where- hleft f (Joker x) = Joker (f x)- hright _ = coerce- hbimap f _ (Joker x) = Joker (f x)+ hleft f (Joker x) = Joker (f x)+ hright _ = coerce+ hbimap f _ (Joker x) = Joker (f x) instance HBifunctor Void3 where- hleft _ = coerce- hright _ = coerce- hbimap _ _ = coerce+ hleft _ = coerce+ hright _ = coerce+ hbimap _ _ = coerce instance HBifunctor Comp where- hleft f (x :>>= h) = f x :>>= h- hright g (x :>>= h) = x :>>= (g . h)- hbimap f g (x :>>= h) = f x :>>= (g . h)+ hleft f (x :>>= h) = f x :>>= h+ hright g (x :>>= h) = x :>>= (g . h)+ hbimap f g (x :>>= h) = f x :>>= (g . h) instance HBifunctor t => HFunctor (WrappedHBifunctor t f) where- hmap f = WrapHBifunctor . hright f . unwrapHBifunctor+ hmap f = WrapHBifunctor . hright f . unwrapHBifunctor -deriving via (WrappedHBifunctor Day f) instance HFunctor (Day f)-deriving via (WrappedHBifunctor ID.Day f) instance HFunctor (ID.Day f)+deriving via (WrappedHBifunctor Day f) instance HFunctor (Day f)+deriving via (WrappedHBifunctor ID.Day f) instance HFunctor (ID.Day f) deriving via (WrappedHBifunctor IN.Night f) instance HFunctor (IN.Night f)-deriving via (WrappedHBifunctor (:*:) f) instance HFunctor ((:*:) f)-deriving via (WrappedHBifunctor (:+:) f) instance HFunctor ((:+:) f)-deriving via (WrappedHBifunctor Product f) instance HFunctor (Product f)-deriving via (WrappedHBifunctor Sum f) instance HFunctor (Sum f)-deriving via (WrappedHBifunctor These1 f) instance HFunctor (These1 f)+deriving via (WrappedHBifunctor (:*:) f) instance HFunctor ((:*:) f)+deriving via (WrappedHBifunctor (:+:) f) instance HFunctor ((:+:) f)+deriving via (WrappedHBifunctor Product f) instance HFunctor (Product f)+deriving via (WrappedHBifunctor Sum f) instance HFunctor (Sum f)+deriving via (WrappedHBifunctor These1 f) instance HFunctor (These1 f)
src/Data/HFunctor/Interpret.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.HFunctor.Interpret--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -41,62 +41,65 @@ -- See "Data.Functor.Tensor" for binary functor combinators that mix -- together two or more different functors. module Data.HFunctor.Interpret (- Interpret(..), forI+ Interpret (..),+ forI,+ -- * Utilities- , iget- , icollect- , icollect1- , itraverse- , iapply- , ifanout- , ifanout1- , getI, collectI- , AltConst(..)- , AndC- , WrapHF(..)- ) where+ iget,+ icollect,+ icollect1,+ itraverse,+ iapply,+ ifanout,+ ifanout1,+ getI,+ collectI,+ AltConst (..),+ AndC,+ WrapHF (..),+) where -import Control.Applicative-import Control.Applicative.Backwards-import Control.Applicative.Lift-import Control.Applicative.ListF-import Control.Applicative.Step-import Control.Comonad.Trans.Env (EnvT(..))-import Control.Monad.Freer.Church-import Control.Monad.Reader-import Control.Monad.Trans.Compose-import Control.Monad.Trans.Identity-import Control.Natural-import Data.Coerce-import Data.Data-import Data.Functor.Bind-import Data.Functor.Classes-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Coyoneda-import Data.Functor.Invariant-import Data.Functor.Plus-import Data.Functor.Product-import Data.Functor.Reverse-import Data.Functor.Sum-import Data.Functor.These-import Data.HFunctor-import Data.HFunctor.Internal-import Data.List.NonEmpty (NonEmpty(..))-import Data.Maybe-import Data.Pointed-import Data.Semigroup (Endo(..))-import Data.Semigroup.Foldable-import GHC.Generics-import qualified Control.Alternative.Free as Alt-import qualified Control.Applicative.Free as Ap-import qualified Control.Applicative.Free.Fast as FAF-import qualified Control.Applicative.Free.Final as FA-import qualified Data.Functor.Contravariant.Coyoneda as CCY-import qualified Data.Map.NonEmpty as NEM+import qualified Control.Alternative.Free as Alt+import Control.Applicative+import Control.Applicative.Backwards+import qualified Control.Applicative.Free as Ap+import qualified Control.Applicative.Free.Fast as FAF+import qualified Control.Applicative.Free.Final as FA+import Control.Applicative.Lift+import Control.Applicative.ListF+import Control.Applicative.Step+import Control.Comonad.Trans.Env (EnvT (..))+import Control.Monad.Freer.Church+import Control.Monad.Reader+import Control.Monad.Trans.Compose+import Control.Monad.Trans.Identity+import Control.Natural+import Data.Coerce+import Data.Data+import Data.Functor.Bind+import Data.Functor.Classes+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import qualified Data.Functor.Contravariant.Coyoneda as CCY+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Coyoneda+import Data.Functor.Invariant+import Data.Functor.Plus+import Data.Functor.Product+import Data.Functor.Reverse+import Data.Functor.Sum+import Data.Functor.These+import Data.HFunctor+import Data.HFunctor.Internal+import Data.List.NonEmpty (NonEmpty (..))+import qualified Data.Map.NonEmpty as NEM+import Data.Maybe+import Data.Pointed+import Data.Semigroup (Endo (..))+import Data.Semigroup.Foldable+import GHC.Generics -- | An 'Interpret' lets us move in and out of the "enhanced" 'Functor' (@t -- f@) and the functor it enhances (@f@). An instance @'Interpret' t f@@@ -143,26 +146,25 @@ -- -- This will prevent problems with overloaded instances. class Inject t => Interpret t f where-- -- | Remove the @f@ out of the enhanced @t f@ structure, provided that- -- @f@ satisfies the necessary constraints. If it doesn't, it needs to- -- be properly 'interpret'ed out.- retract :: t f ~> f- retract = interpret id+ -- | Remove the @f@ out of the enhanced @t f@ structure, provided that+ -- @f@ satisfies the necessary constraints. If it doesn't, it needs to+ -- be properly 'interpret'ed out.+ retract :: t f ~> f+ retract = interpret id - -- | Given an "interpeting function" from @f@ to @g@, interpret the @f@- -- out of the @t f@ into a final context @g@.- interpret :: (g ~> f) -> t g ~> f- interpret f = retract . hmap f+ -- | Given an "interpeting function" from @f@ to @g@, interpret the @f@+ -- out of the @t f@ into a final context @g@.+ interpret :: (g ~> f) -> t g ~> f+ interpret f = retract . hmap f - {-# MINIMAL retract | interpret #-}+ {-# MINIMAL retract | interpret #-} -- | A convenient flipped version of 'interpret'.-forI- :: Interpret t f- => t g a- -> (g ~> f)- -> f a+forI ::+ Interpret t f =>+ t g a ->+ (g ~> f) ->+ f a forI x f = interpret f x -- | Useful wrapper over 'interpret' to allow you to directly extract@@ -189,11 +191,11 @@ -- 'Data.HFunctor.HTraversable.hfoldMap1'. -- -- @since 0.3.1.0-iget- :: Interpret t (AltConst b)- => (forall x. f x -> b)- -> t f a- -> b+iget ::+ Interpret t (AltConst b) =>+ (forall x. f x -> b) ->+ t f a ->+ b iget f = getAltConst . interpret (AltConst . f) -- | (Deprecated) Old name for 'getI'; will be removed in a future@@ -222,11 +224,11 @@ -- 'Data.HFunctor.HTraversable.htoList'. -- -- @since 0.3.1.0-icollect- :: (forall m. Monoid m => Interpret t (AltConst m))- => (forall x. f x -> b)- -> t f a- -> [b]+icollect ::+ (forall m. Monoid m => Interpret t (AltConst m)) =>+ (forall x. f x -> b) ->+ t f a ->+ [b] icollect f = flip appEndo [] . iget (Endo . (:) . f) -- | (Deprecated) Old name for 'icollect'; will be removed in a future@@ -254,11 +256,11 @@ -- 'Data.HFunctor.HTraversable.htoNonEmpty'. -- -- @since 0.3.1.0-icollect1- :: (forall m. Semigroup m => Interpret t (AltConst m))- => (forall x. f x -> b)- -> t f a- -> NonEmpty b+icollect1 ::+ (forall m. Semigroup m => Interpret t (AltConst m)) =>+ (forall x. f x -> b) ->+ t f a ->+ NonEmpty b icollect1 f = fromNDL . iget (ndlSingleton . f) -- | Useful wrapper over 'interpret' to allow you to do an "effectful"@@ -269,11 +271,11 @@ -- which is a more principled system for effectful hmapping. -- -- @since 0.3.6.0-itraverse- :: (Functor h, Interpret t (Comp h (t g)))- => (forall x. f x -> h (g x))- -> t f a- -> h (t g a)+itraverse ::+ (Functor h, Interpret t (Comp h (t g))) =>+ (forall x. f x -> h (g x)) ->+ t f a ->+ h (t g a) itraverse f = unComp . interpret (\x -> f x :>>= inject) -- | Useful wrapper over 'interpret' to allow you to directly consume@@ -296,12 +298,12 @@ -- For any 'Functor' or 'Invariant' constraint, this is not usable. -- -- @since 0.3.2.0-iapply- :: Interpret t (Op b)- => (forall x. f x -> x -> b)- -> t f a- -> a- -> b+iapply ::+ Interpret t (Op b) =>+ (forall x. f x -> x -> b) ->+ t f a ->+ a ->+ b iapply f = getOp . interpret (Op . f) -- | Useful wrapper over 'interpret' to allow you to directly consume@@ -323,12 +325,12 @@ -- always just give you a singleton list, so you might as well use -- 'iapply'. This is really only here for completion alongside 'icollect', -- or if you define your own custom functor combinators.-ifanout- :: (forall m. Monoid m => Interpret t (Op m))- => (forall x. f x -> x -> b)- -> t f a- -> a- -> [b]+ifanout ::+ (forall m. Monoid m => Interpret t (Op m)) =>+ (forall x. f x -> x -> b) ->+ t f a ->+ a ->+ [b] ifanout f t = flip appEndo [] . iapply (\x y -> Endo (f x y :)) t -- | Useful wrapper over 'interpret' to allow you to directly consume@@ -349,16 +351,14 @@ -- always just give you a singleton list, so you might as well use -- 'iapply'. This is really only here for completion alongside -- 'icollect1', or if you define your own custom functor combinators.-ifanout1- :: (forall m. Semigroup m => Interpret t (Op m))- => (forall x. f x -> x -> b)- -> t f a- -> a- -> NonEmpty b+ifanout1 ::+ (forall m. Semigroup m => Interpret t (Op m)) =>+ (forall x. f x -> x -> b) ->+ t f a ->+ a ->+ NonEmpty b ifanout1 f t = fromNDL . iapply (\x -> ndlSingleton . f x) t -- -- | A version of 'Const' that supports 'Alt', 'Plus', 'Decide', and -- 'Conclude' instances. It does this -- by avoiding having an 'Alternative' or 'Decidable' instance, which@@ -367,77 +367,81 @@ -- 'Decidable'/'Data.Functor.Contravariant.Divisible.Divisible'. -- -- @since 0.3.1.0-newtype AltConst w a = AltConst { getAltConst :: w }+newtype AltConst w a = AltConst {getAltConst :: w} deriving (Show, Eq, Ord, Generic, Functor, Foldable, Traversable, Data) instance Show w => Show1 (AltConst w) where- liftShowsPrec _ _ d (AltConst x) = showsUnaryWith showsPrec "AltConst" d x+ liftShowsPrec _ _ d (AltConst x) = showsUnaryWith showsPrec "AltConst" d x instance Eq w => Eq1 (AltConst w) where- liftEq _ (AltConst x) (AltConst y) = x == y+ liftEq _ (AltConst x) (AltConst y) = x == y instance Ord w => Ord1 (AltConst w) where- liftCompare _ (AltConst x) (AltConst y) = compare x y+ liftCompare _ (AltConst x) (AltConst y) = compare x y instance Contravariant (AltConst w) where- contramap _ = coerce+ contramap _ = coerce instance Invariant (AltConst w) where- invmap _ _ = coerce+ invmap _ _ = coerce instance Semigroup w => Apply (AltConst w) where- AltConst x <.> AltConst y = AltConst (x <> y)+ AltConst x <.> AltConst y = AltConst (x <> y) instance Monoid w => Applicative (AltConst w) where- (<*>) = (<.>)- pure _ = AltConst mempty+ (<*>) = (<.>)+ pure _ = AltConst mempty+ -- | Unlike for 'Const', this is possible because there is no 'Alternative' -- instance to complicate things. instance Semigroup w => Alt (AltConst w) where- AltConst x <!> AltConst y = AltConst (x <> y)+ AltConst x <!> AltConst y = AltConst (x <> y)+ -- | Unlike for 'Const', this is possible because there is no 'Alternative' -- instance to complicate things. instance Monoid w => Plus (AltConst w) where- zero = AltConst mempty+ zero = AltConst mempty instance Semigroup w => Divise (AltConst w) where- divise _ (AltConst x) (AltConst y) = AltConst (x <> y)+ divise _ (AltConst x) (AltConst y) = AltConst (x <> y) instance Monoid w => Divisible (AltConst w) where- divide = divise- conquer = AltConst mempty+ divide = divise+ conquer = AltConst mempty+ -- | Unlike for 'Const', this is possible because there is no 'Decidable' -- instance to complicate things. instance Semigroup w => Decide (AltConst w) where- decide _ (AltConst x) (AltConst y) = AltConst (x <> y)+ decide _ (AltConst x) (AltConst y) = AltConst (x <> y)+ -- | Unlike for 'Const', this is possible because there is no 'Decidable' -- instance to complicate things. instance Monoid w => Conclude (AltConst w) where- conclude _ = AltConst mempty+ conclude _ = AltConst mempty -- | A free 'Functor' instance Functor f => Interpret Coyoneda f where- retract = lowerCoyoneda- interpret f (Coyoneda g x) = g <$> f x+ retract = lowerCoyoneda+ interpret f (Coyoneda g x) = g <$> f x -- | A free 'Contravariant' -- -- @since 0.3.0.0 instance Contravariant f => Interpret CCY.Coyoneda f where- retract = CCY.lowerCoyoneda- interpret f (CCY.Coyoneda g x) = contramap g (f x)+ retract = CCY.lowerCoyoneda+ interpret f (CCY.Coyoneda g x) = contramap g (f x) -- | A free 'Applicative' instance Applicative f => Interpret Ap.Ap f where- retract = \case- Ap.Pure x -> pure x- Ap.Ap x xs -> x <**> retract xs- interpret f x = Ap.runAp f x+ retract = \case+ Ap.Pure x -> pure x+ Ap.Ap x xs -> x <**> retract xs+ interpret f x = Ap.runAp f x -- | A free 'Plus' instance Plus f => Interpret ListF f where- retract = foldr (<!>) zero . runListF- interpret f = foldr ((<!>) . f) zero . runListF+ retract = foldr (<!>) zero . runListF+ interpret f = foldr ((<!>) . f) zero . runListF -- | A free 'Alt' instance Alt f => Interpret NonEmptyF f where- retract = asum1 . runNonEmptyF- interpret f = asum1 . fmap f . runNonEmptyF+ retract = asum1 . runNonEmptyF+ interpret f = asum1 . fmap f . runNonEmptyF -- | Technically, @f@ is over-constrained: we only need @'zero' :: f a@, -- but we don't really have that typeclass in any standard hierarchies. We@@ -446,32 +450,32 @@ -- instances of 'Control.Monad.Fail.MonadFail' without -- 'Control.Monad.MonadPlus'. instance Plus f => Interpret MaybeF f where- retract = fromMaybe zero . runMaybeF- interpret f = maybe zero f . runMaybeF+ retract = fromMaybe zero . runMaybeF+ interpret f = maybe zero f . runMaybeF instance (Monoid k, Plus f) => Interpret (MapF k) f where- retract = foldr (<!>) zero . runMapF- interpret f = foldr ((<!>) . f) zero . runMapF+ retract = foldr (<!>) zero . runMapF+ interpret f = foldr ((<!>) . f) zero . runMapF instance (Monoid k, Alt f) => Interpret (NEMapF k) f where- retract = asum1 . runNEMapF- interpret f = asum1 . fmap f . runNEMapF+ retract = asum1 . runNEMapF+ interpret f = asum1 . fmap f . runNEMapF -- | Equivalent to instance for @'EnvT' ('Data.Semigroup.Sum' -- 'Numeric.Natural.Natural')@. instance Interpret Step f where- retract = stepVal- interpret f = f . stepVal+ retract = stepVal+ interpret f = f . stepVal instance Alt f => Interpret Steps f where- retract = asum1 . getSteps- interpret f = asum1 . NEM.map f . getSteps+ retract = asum1 . getSteps+ interpret f = asum1 . NEM.map f . getSteps -- | Equivalent to instance for @'EnvT' 'Data.Semigroup.Any'@ and @'HLift' -- 'IdentityT'@. instance Interpret Flagged f where- retract = flaggedVal- interpret f = f . flaggedVal+ retract = flaggedVal+ interpret f = f . flaggedVal -- | Technically, @f@ is over-constrained: we only need @'zero' :: f a@, -- but we don't really have that typeclass in any standard hierarchies. We@@ -480,24 +484,24 @@ -- instances of 'Control.Monad.Fail.MonadFail' without -- 'Control.Monad.MonadPlus'. instance Plus f => Interpret (These1 g) f where- retract = \case- This1 _ -> zero- That1 y -> y- These1 _ y -> y- interpret f = \case- This1 _ -> zero- That1 y -> f y- These1 _ y -> f y+ retract = \case+ This1 _ -> zero+ That1 y -> y+ These1 _ y -> y+ interpret f = \case+ This1 _ -> zero+ That1 y -> f y+ These1 _ y -> f y -- | A free 'Alternative' instance Alternative f => Interpret Alt.Alt f where- interpret f x = Alt.runAlt f x+ interpret f x = Alt.runAlt f x instance Plus g => Interpret ((:*:) g) f where- retract (_ :*: y) = y+ retract (_ :*: y) = y instance Plus g => Interpret (Product g) f where- retract (Pair _ y) = y+ retract (Pair _ y) = y -- | Technically, @f@ is over-constrained: we only need @'zero' :: f a@, -- but we don't really have that typeclass in any standard hierarchies. We@@ -506,9 +510,9 @@ -- instances of 'Control.Monad.Fail.MonadFail' without -- 'Control.Monad.MonadPlus'. instance Plus f => Interpret ((:+:) g) f where- retract = \case- L1 _ -> zero- R1 y -> y+ retract = \case+ L1 _ -> zero+ R1 y -> y -- | Technically, @f@ is over-constrained: we only need @'zero' :: f a@, -- but we don't really have that typeclass in any standard hierarchies. We@@ -517,69 +521,69 @@ -- instances of 'Control.Monad.Fail.MonadFail' without -- 'Control.Monad.MonadPlus'. instance Plus f => Interpret (Sum g) f where- retract = \case- InL _ -> zero- InR y -> y+ retract = \case+ InL _ -> zero+ InR y -> y instance Interpret (M1 i c) f where- retract (M1 x) = x- interpret f (M1 x) = f x+ retract (M1 x) = x+ interpret f (M1 x) = f x -- | A free 'Monad' instance Monad f => Interpret Free f where- retract = retractFree- interpret f x = interpretFree f x+ retract = retractFree+ interpret f x = interpretFree f x -- | A free 'Bind' instance Bind f => Interpret Free1 f where- retract = retractFree1- interpret f x = interpretFree1 f x+ retract = retractFree1+ interpret f x = interpretFree1 f x -- | A free 'Applicative' instance Applicative f => Interpret FA.Ap f where- retract = FA.retractAp- interpret f x = FA.runAp f x+ retract = FA.retractAp+ interpret f x = FA.runAp f x -- | A free 'Applicative' instance Applicative f => Interpret FAF.Ap f where- retract = FAF.retractAp- interpret f x = FAF.runAp f x+ retract = FAF.retractAp+ interpret f x = FAF.runAp f x instance Interpret IdentityT f where- retract = coerce- interpret f = f . runIdentityT+ retract = coerce+ interpret f = f . runIdentityT -- | A free 'Pointed' instance Pointed f => Interpret Lift f where- retract = elimLift point id- interpret f x = elimLift point f x+ retract = elimLift point id+ interpret f x = elimLift point f x -- | A free 'Pointed' instance Pointed f => Interpret MaybeApply f where- retract = either id point . runMaybeApply- interpret f = either f point . runMaybeApply+ retract = either id point . runMaybeApply+ interpret f = either f point . runMaybeApply instance Interpret Backwards f where- retract = forwards- interpret f = f . forwards+ retract = forwards+ interpret f = f . forwards instance Interpret WrappedApplicative f where- retract = unwrapApplicative- interpret f = f . unwrapApplicative+ retract = unwrapApplicative+ interpret f = f . unwrapApplicative -- | A free 'MonadReader', but only when applied to a 'Monad'. instance MonadReader r f => Interpret (ReaderT r) f where- retract x = runReaderT x =<< ask- interpret f x = f . runReaderT x =<< ask+ retract x = runReaderT x =<< ask+ interpret f x = f . runReaderT x =<< ask -- | This ignores the environment, so @'interpret' /= 'hbind'@ instance Monoid e => Interpret (EnvT e) f where- retract (EnvT _ x) = x- interpret f (EnvT _ x) = f x+ retract (EnvT _ x) = x+ interpret f (EnvT _ x) = f x instance Interpret Reverse f where- retract = getReverse- interpret f = f . getReverse+ retract = getReverse+ interpret f = f . getReverse -- -- | The only way for this to obey @'retract' . 'inject' == 'id'@ is to -- -- have it impossible to retract out of.@@ -597,26 +601,27 @@ -- | A constraint on @a@ for both @c a@ and @d a@. Requiring @'AndC' -- 'Show' 'Eq' a@ is the same as requiring @('Show' a, 'Eq' a)@. class (c a, d a) => AndC c d a+ instance (c a, d a) => AndC c d a instance (Interpret s f, Interpret t f) => Interpret (ComposeT s t) f where- retract = interpret retract . getComposeT- interpret f = interpret (interpret f) . getComposeT+ retract = interpret retract . getComposeT+ interpret f = interpret (interpret f) . getComposeT -- | Never uses 'inject' instance Interpret t f => Interpret (HLift t) f where- retract = \case- HPure x -> x- HOther x -> retract x- interpret f = \case- HPure x -> f x- HOther x -> interpret f x+ retract = \case+ HPure x -> x+ HOther x -> retract x+ interpret f = \case+ HPure x -> f x+ HOther x -> interpret f x -- | Never uses 'inject' instance Interpret t f => Interpret (HFree t) f where- retract = \case- HReturn x -> x- HJoin x -> interpret retract x+ retract = \case+ HReturn x -> x+ HJoin x -> interpret retract x -- | A newtype wrapper meant to be used to define polymorphic 'Interpret' -- instances. See documentation for 'Interpret' for more information.@@ -629,25 +634,24 @@ -- @ -- -- As that would globally ruin everything using 'WrapHF'.-newtype WrapHF t f a = WrapHF { unwrapHF :: t f a }+newtype WrapHF t f a = WrapHF {unwrapHF :: t f a} deriving (Show, Read, Eq, Ord, Functor, Foldable, Traversable, Typeable, Generic, Data) instance Show1 (t f) => Show1 (WrapHF t f) where- liftShowsPrec sp sl d (WrapHF x) = showsUnaryWith (liftShowsPrec sp sl) "WrapHF" d x+ liftShowsPrec sp sl d (WrapHF x) = showsUnaryWith (liftShowsPrec sp sl) "WrapHF" d x instance Eq1 (t f) => Eq1 (WrapHF t f) where- liftEq eq (WrapHF x) (WrapHF y) = liftEq eq x y+ liftEq eq (WrapHF x) (WrapHF y) = liftEq eq x y instance Ord1 (t f) => Ord1 (WrapHF t f) where- liftCompare c (WrapHF x) (WrapHF y) = liftCompare c x y+ liftCompare c (WrapHF x) (WrapHF y) = liftCompare c x y instance HFunctor t => HFunctor (WrapHF t) where- hmap f (WrapHF x) = WrapHF (hmap f x)+ hmap f (WrapHF x) = WrapHF (hmap f x) instance Inject t => Inject (WrapHF t) where- inject = WrapHF . inject+ inject = WrapHF . inject instance HBind t => HBind (WrapHF t) where- hbind f (WrapHF x) = WrapHF (hbind (unwrapHF . f) x)- hjoin (WrapHF x) = WrapHF (hbind unwrapHF x)-+ hbind f (WrapHF x) = WrapHF (hbind (unwrapHF . f) x)+ hjoin (WrapHF x) = WrapHF (hbind unwrapHF x)
src/Data/HFunctor/Route.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Data.HFunctor.Route--- Copyright : (c) Justin Le 2019+-- Copyright : (c) Justin Le 2025 -- License : BSD3 -- -- Maintainer : justin@jle.im@@ -18,41 +18,60 @@ -- @since 0.3.4.0 module Data.HFunctor.Route ( -- * Routing Combinators+ -- ** Contravariant- Pre(..)- , interpretPre, getPre, retractPre- , injectPre, mapPre- , preDivisible, preDivise, preContravariant+ Pre (..),+ interpretPre,+ getPre,+ retractPre,+ injectPre,+ mapPre,+ preDivisible,+ preDivise,+ preContravariant,+ -- ** Covariant- , Post(..)- , interpretPost, getPost, retractPost- , injectPost, mapPost- , postPlus, postAlt, postFunctor+ Post (..),+ interpretPost,+ getPost,+ retractPost,+ injectPost,+ mapPost,+ postPlus,+ postAlt,+ postFunctor,+ -- * Wrapped Invariant+ -- ** Contravariant- , PreT(..)- , preDivisibleT, preDiviseT, preContravariantT+ PreT (..),+ preDivisibleT,+ preDiviseT,+ preContravariantT,+ -- ** Covariant- , PostT(..)- , postPlusT, postAltT, postFunctorT- ) where+ PostT (..),+ postPlusT,+ postAltT,+ postFunctorT,+) where -import Control.Natural-import Data.Functor.Invariant.Inplicative-import Data.Functor.Invariant.Internative-import Data.Functor.Bind-import Data.Functor.Contravariant-import Data.Functor.Contravariant.Conclude-import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible-import Data.Functor.Invariant-import Data.Functor.Plus-import Data.HFunctor-import Data.HFunctor.HTraversable-import Data.HFunctor.Interpret-import Data.Profunctor-import Data.Void+import Control.Natural+import Data.Functor.Bind+import Data.Functor.Contravariant+import Data.Functor.Contravariant.Conclude+import Data.Functor.Contravariant.Decide+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible+import Data.Functor.Invariant+import Data.Functor.Invariant.Inplicative+import Data.Functor.Invariant.Internative+import Data.Functor.Plus+import Data.HFunctor+import Data.HFunctor.HTraversable+import Data.HFunctor.Interpret+import Data.Profunctor+import Data.Void -- | A useful helper type to use with a covariant functor combinator that -- allows you to tag along contravariant access to all @f@s inside the@@ -93,9 +112,8 @@ -- An example of a usage of this in the real world is the /unjson/ -- library's record type constructor, to implement bidrectional -- serializers for product types.-data Pre a f b = (a -> b) :>$<: f b- deriving Functor-+data Pre a f b = (a -> b) :>$<: f b+ deriving (Functor) -- | A useful helper type to use with a contravariant functor combinator that -- allows you to tag along covariant access to all @f@s inside the@@ -140,7 +158,7 @@ data Post a f b = (b -> a) :<$>: f b instance Contravariant f => Contravariant (Post a f) where- contramap f (g :<$>: x) = g . f :<$>: contramap f x+ contramap f (g :<$>: x) = g . f :<$>: contramap f x infixl 4 :>$<: infixl 4 :<$>:@@ -172,25 +190,26 @@ -- @ -- -- See 'Pre' for more information.-newtype PreT t f a = PreT { unPreT :: t (Pre a f) a }+newtype PreT t f a = PreT {unPreT :: t (Pre a f) a} instance (HFunctor t, forall x. Functor (t (Pre x f))) => Invariant (PreT t f) where- invmap f g = PreT- . hmap (mapPre g)- . fmap f- . unPreT+ invmap f g =+ PreT+ . hmap (mapPre g)+ . fmap f+ . unPreT instance HFunctor t => HFunctor (PreT t) where- hmap f = PreT . hmap (hmap f) . unPreT+ hmap f = PreT . hmap (hmap f) . unPreT instance Inject t => Inject (PreT t) where- inject = PreT . inject . (id :>$<:)+ inject = PreT . inject . (id :>$<:) instance HTraversable t => HTraversable (PreT t) where- htraverse f = fmap PreT . htraverse (htraverse f) . unPreT+ htraverse f = fmap PreT . htraverse (htraverse f) . unPreT instance Interpret t f => Interpret (PreT t) f where- interpret f = interpret f . hmap getPre . unPreT+ interpret f = interpret f . hmap getPre . unPreT -- | Turn the contravariant functor combinator @t@ into an 'Invariant' -- functor combinator; if @t f a@ "consumes" @a@s, then @'PostT' t f a@ will@@ -212,28 +231,29 @@ -- @ -- -- See 'Post' for more information.-newtype PostT t f a = PostT { unPostT :: t (Post a f) a }+newtype PostT t f a = PostT {unPostT :: t (Post a f) a} instance (HFunctor t, forall x. Contravariant (t (Post x f))) => Invariant (PostT t f) where- invmap f g = PostT- . hmap (mapPost f)- . contramap g- . unPostT+ invmap f g =+ PostT+ . hmap (mapPost f)+ . contramap g+ . unPostT -- | @since 0.3.4.2 instance HFunctor t => HFunctor (PostT t) where- hmap f = PostT . hmap (hmap f) . unPostT+ hmap f = PostT . hmap (hmap f) . unPostT -- | @since 0.3.4.2 instance Inject t => Inject (PostT t) where- inject = PostT . inject . (id :<$>:)+ inject = PostT . inject . (id :<$>:) instance HTraversable t => HTraversable (PostT t) where- htraverse f = fmap PostT . htraverse (htraverse f) . unPostT+ htraverse f = fmap PostT . htraverse (htraverse f) . unPostT -- | @since 0.3.4.2 instance Interpret t f => Interpret (PostT t) f where- interpret f = interpret f . hmap getPost . unPostT+ interpret f = interpret f . hmap getPost . unPostT -- | Run a @'PreT' t@ into a contravariant 'Divisible' context. To run it -- in @t@s normal covariant context, use 'interpret'.@@ -245,10 +265,10 @@ -- preDivisibleT :: Divisible g => (f ~> g) -> PreT 'Ap' f ~> g -- preDivisibleT :: Divisible g => (f ~> g) -> PreT 'ListF' f ~> g -- @-preDivisibleT- :: (forall m. Monoid m => Interpret t (AltConst m), Divisible g)- => (f ~> g)- -> PreT t f ~> g+preDivisibleT ::+ (forall m. Monoid m => Interpret t (AltConst m), Divisible g) =>+ (f ~> g) ->+ PreT t f ~> g preDivisibleT f = preDivisible f . unPreT -- | Run a @'PreT' t@ into a contravariant 'Divise' context. To run it in@@ -261,10 +281,10 @@ -- preDiviseT :: Divise g => (f ~> g) -> PreT 'Ap1' f ~> g -- preDiviseT :: Divise g => (f ~> g) -> PreT 'NonEmptyF' f ~> g -- @-preDiviseT- :: (forall m. Semigroup m => Interpret t (AltConst m), Divise g)- => (f ~> g)- -> PreT t f ~> g+preDiviseT ::+ (forall m. Semigroup m => Interpret t (AltConst m), Divise g) =>+ (f ~> g) ->+ PreT t f ~> g preDiviseT f = preDivise f . unPreT -- | Run a @'PreT' t@ into a 'Contravariant'. To run it in@@ -276,10 +296,10 @@ -- preContravariantT :: Contravariant g => (f ~> g) -> PreT 'Step' f ~> g -- preContravariantT :: Contravariant g => (f ~> g) -> PreT 'Coyoneda' f ~> g -- @-preContravariantT- :: (forall m. Interpret t (AltConst m), Contravariant g)- => (f ~> g)- -> PreT t f ~> g+preContravariantT ::+ (forall m. Interpret t (AltConst m), Contravariant g) =>+ (f ~> g) ->+ PreT t f ~> g preContravariantT f = preContravariant f . unPreT -- | Run a "pre-routed" @t@ into a contravariant 'Divisible' context. To@@ -292,13 +312,14 @@ -- preDivisible :: Divisible g => (f ~> g) -> 'Ap' ('Pre' a f) b -> g a -- preDivisible :: Divisible g => (f ~> g) -> 'ListF' ('Pre' a f) b -> g a -- @-preDivisible- :: (forall m. Monoid m => Interpret t (AltConst m), Divisible g)- => (f ~> g)- -> t (Pre a f) b- -> g a-preDivisible f = foldr (divide (\x -> (x,x))) conquer- . icollect (interpretPre f)+preDivisible ::+ (forall m. Monoid m => Interpret t (AltConst m), Divisible g) =>+ (f ~> g) ->+ t (Pre a f) b ->+ g a+preDivisible f =+ foldr (divide (\x -> (x, x))) conquer+ . icollect (interpretPre f) -- | Run a "pre-routed" @t@ into a contravariant 'Divise' context. To -- run it in @t@s normal covariant context, use 'interpret' with 'getPre'.@@ -310,11 +331,11 @@ -- preDivise :: Divise g => (f ~> g) -> 'Ap1' ('Pre' a f) b -> g a -- preDivise :: Divise g => (f ~> g) -> 'NonEmptyF' ('Pre' a f) b -> g a -- @-preDivise- :: (forall m. Semigroup m => Interpret t (AltConst m), Divise g)- => (f ~> g)- -> t (Pre a f) b- -> g a+preDivise ::+ (forall m. Semigroup m => Interpret t (AltConst m), Divise g) =>+ (f ~> g) ->+ t (Pre a f) b ->+ g a preDivise f = foldr1 (<:>) . icollect1 (interpretPre f) -- | Run a "pre-routed" @t@ into a 'Contravariant'. To run it in @t@s@@ -326,11 +347,11 @@ -- preContravariant :: Contravariant g => (f ~> g) -> 'Step' ('Pre' a f) b -> g a -- preContravariant :: Contravariant g => (f ~> g) -> 'Coyoneda' ('Pre' a f) b -> g a -- @-preContravariant- :: (forall m. Interpret t (AltConst m), Contravariant g)- => (f ~> g)- -> t (Pre a f) b- -> g a+preContravariant ::+ (forall m. Interpret t (AltConst m), Contravariant g) =>+ (f ~> g) ->+ t (Pre a f) b ->+ g a preContravariant f = iget (interpretPre f) -- | Run a @'PostT' t@ into a covariant 'Plus' context. To run it@@ -343,10 +364,10 @@ -- postPlusT :: Plus g => (f ~> g) -> PreT 'Dec' f ~> g -- postPlusT :: Plus g => (f ~> g) -> PreT 'Div' f ~> g -- @-postPlusT- :: (forall m. Monoid m => Interpret t (AltConst m), Plus g)- => (f ~> g)- -> PostT t f ~> g+postPlusT ::+ (forall m. Monoid m => Interpret t (AltConst m), Plus g) =>+ (f ~> g) ->+ PostT t f ~> g postPlusT f = postPlus f . unPostT -- | Run a @'PostT' t@ into a covariant 'Alt' context. To run it@@ -359,10 +380,10 @@ -- postAltT :: Alt g => (f ~> g) -> PreT 'Dec1' f ~> g -- postAltT :: Alt g => (f ~> g) -> PreT 'Div1' f ~> g -- @-postAltT- :: (forall m. Semigroup m => Interpret t (AltConst m), Alt g)- => (f ~> g)- -> PostT t f ~> g+postAltT ::+ (forall m. Semigroup m => Interpret t (AltConst m), Alt g) =>+ (f ~> g) ->+ PostT t f ~> g postAltT f = postAlt f . unPostT -- | Run a @'PostT' t@ into a covariant 'Functor' context. To run it@@ -374,10 +395,10 @@ -- postFunctorT :: Functor g => (f ~> g) -> PreT 'Step' f ~> g -- postFunctorT :: Functor g => (f ~> g) -> PreT 'CCY.Coyoneda' f ~> g -- @-postFunctorT- :: (forall m. Interpret t (AltConst m), Functor g)- => (f ~> g)- -> PostT t f ~> g+postFunctorT ::+ (forall m. Interpret t (AltConst m), Functor g) =>+ (f ~> g) ->+ PostT t f ~> g postFunctorT f = postFunctor f . unPostT -- | Run a "post-routed" @t@ into a covariant 'Plus' context. To run it@@ -390,11 +411,11 @@ -- postPlus :: Plus g => (f ~> g) -> 'Dec' (Post a f) b -> g a -- postPlus :: Plus g => (f ~> g) -> 'Div' (Post a f) b -> g a -- @-postPlus- :: (forall m. Monoid m => Interpret t (AltConst m), Plus g)- => (f ~> g)- -> t (Post a f) b- -> g a+postPlus ::+ (forall m. Monoid m => Interpret t (AltConst m), Plus g) =>+ (f ~> g) ->+ t (Post a f) b ->+ g a postPlus f = foldr (<!>) zero . icollect (interpretPost f) -- | Run a "post-routed" @t@ into a covariant 'Alt' context. To run it@@ -407,11 +428,11 @@ -- postAlt :: Alt g => (f ~> g) -> 'Dec1' (Post a f) b -> g a -- postAlt :: Alt g => (f ~> g) -> 'Div1' (Post a f) b -> g a -- @-postAlt- :: (forall m. Semigroup m => Interpret t (AltConst m), Alt g)- => (f ~> g)- -> t (Post a f) b- -> g a+postAlt ::+ (forall m. Semigroup m => Interpret t (AltConst m), Alt g) =>+ (f ~> g) ->+ t (Post a f) b ->+ g a postAlt f = foldr1 (<!>) . icollect1 (interpretPost f) -- | Run a "post-routed" @t@ into a covariant 'Functor' context. To run it@@ -423,11 +444,11 @@ -- postFunctor :: Functor g => (f ~> g) -> 'Step' (Post a f) b -> g a -- postFunctor :: Functor g => (f ~> g) -> 'CCY.Coyoneda' (Post a f) b -> g a -- @-postFunctor- :: (forall m. Interpret t (AltConst m), Functor g)- => (f ~> g)- -> t (Post a f) b- -> g a+postFunctor ::+ (forall m. Interpret t (AltConst m), Functor g) =>+ (f ~> g) ->+ t (Post a f) b ->+ g a postFunctor f = iget (interpretPost f) -- | Contravariantly retract the @f@ out of a 'Pre', applying the@@ -472,131 +493,155 @@ -- | Post-compose on the post-routing function. mapPost :: (a -> c) -> Post a f b -> Post c f b-mapPost f (g :<$>: x) = f . g :<$>: x+mapPost f (g :<$>: x) = f . g :<$>: x -- | Like 'inject', but allowing you to provide a post-routing function. injectPost :: Inject t => (b -> a) -> f b -> t (Post a f) b injectPost f x = inject (f :<$>: x) instance Functor f => Invariant (Post a f) where- invmap f g (h :<$>: x) = h . g :<$>: fmap f x+ invmap f g (h :<$>: x) = h . g :<$>: fmap f x instance Contravariant f => Invariant (Pre a f) where- invmap f g (h :>$<: x) = f . h :>$<: contramap g x+ invmap f g (h :>$<: x) = f . h :>$<: contramap g x instance HFunctor (Post a) where- hmap g (f :<$>: x) = f :<$>: g x+ hmap g (f :<$>: x) = f :<$>: g x instance HFunctor (Pre a) where- hmap g (f :>$<: x) = f :>$<: g x+ hmap g (f :>$<: x) = f :>$<: g x instance HTraversable (Post a) where- htraverse g (f :<$>: x) = (f :<$>:) <$> g x+ htraverse g (f :<$>: x) = (f :<$>:) <$> g x instance HTraversable (Pre a) where- htraverse g (f :>$<: x) = (f :>$<:) <$> g x+ htraverse g (f :>$<: x) = (f :>$<:) <$> g x instance Monoid a => Inject (Post a) where- inject x = const mempty :<$>: x+ inject x = const mempty :<$>: x instance Monoid a => HBind (Post a) where- hjoin (f :<$>: (g :<$>: x)) = (f <> g) :<$>: x+ hjoin (f :<$>: (g :<$>: x)) = (f <> g) :<$>: x instance Monoid a => Interpret (Post a) f where- retract (_ :<$>: x) = x+ retract (_ :<$>: x) = x -- | This instance is over-contrained (@a@ only needs to be uninhabited), -- but there is no commonly used "uninhabited" typeclass-instance (a ~ Void) => Inject (Pre a) where- inject x = absurd :>$<: x+instance a ~ Void => Inject (Pre a) where+ inject x = absurd :>$<: x -- | This instance is over-contrained (@a@ only needs to be uninhabited), -- but there is no commonly used "uninhabited" typeclass-instance (a ~ Void) => HBind (Pre a) where- hjoin (_ :>$<: (_ :>$<: x)) = absurd :>$<: x+instance a ~ Void => HBind (Pre a) where+ hjoin (_ :>$<: (_ :>$<: x)) = absurd :>$<: x -instance (a ~ Void) => Interpret (Pre a) f where- retract (_ :>$<: x) = x+instance a ~ Void => Interpret (Pre a) f where+ retract (_ :>$<: x) = x -- | If @t@ is a covariant functor combinator, then you applying it to -- @'Pre' a f@ gives you a profunctor.-newtype ProPre t f a b = ProPre { unProPre :: t (Pre a f) b }+newtype ProPre t f a b = ProPre {unProPre :: t (Pre a f) b} instance (HFunctor t, forall x. Functor (t (Pre x f))) => Profunctor (ProPre t f) where- dimap f g = ProPre- . hmap (mapPre f)- . fmap g- . unProPre-+ dimap f g =+ ProPre+ . hmap (mapPre f)+ . fmap g+ . unProPre -- | @since 0.3.4.1 deriving instance Functor (t (Pre a f)) => Functor (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Apply (t (Pre a f)) => Apply (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Applicative (t (Pre a f)) => Applicative (ProPre t f a)+ -- | @since 0.3.4.1 instance Bind (t (Pre a f)) => Bind (ProPre t f a) where- ProPre x >>- f = ProPre $ x >>- (unProPre . f)+ ProPre x >>- f = ProPre $ x >>- (unProPre . f)+ -- | @since 0.3.4.1 deriving instance Monad (t (Pre a f)) => Monad (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Contravariant (t (Pre a f)) => Contravariant (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Divisible (t (Pre a f)) => Divisible (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Divise (t (Pre a f)) => Divise (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Decide (t (Pre a f)) => Decide (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Conclude (t (Pre a f)) => Conclude (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Decidable (t (Pre a f)) => Decidable (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Plus (t (Pre a f)) => Plus (ProPre t f a)+ -- | @since 0.3.4.1 instance Alt (t (Pre a f)) => Alt (ProPre t f a) where- ProPre x <!> ProPre y = ProPre (x <!> y)+ ProPre x <!> ProPre y = ProPre (x <!> y)+ -- | @since 0.3.4.1 deriving instance Invariant (t (Pre a f)) => Invariant (ProPre t f a)+ -- | @since 0.4.0.0.0 deriving instance Inply (t (Pre a f)) => Inply (ProPre t f a)+ -- | @since 0.4.0.0.0 deriving instance Inplicative (t (Pre a f)) => Inplicative (ProPre t f a)+ -- | @since 0.4.0.0.0 deriving instance Inalt (t (Pre a f)) => Inalt (ProPre t f a)+ -- | @since 0.4.0.0.0 deriving instance Inplus (t (Pre a f)) => Inplus (ProPre t f a)+ -- | @since 0.4.0.0.0 deriving instance Internative (t (Pre a f)) => Internative (ProPre t f a)+ -- | @since 0.3.4.1 deriving instance Semigroup (t (Pre a f) b) => Semigroup (ProPre t f a b)+ -- | @since 0.3.4.1 deriving instance Monoid (t (Pre a f) b) => Monoid (ProPre t f a b)+ -- | @since 0.3.4.1 deriving instance Show (t (Pre a f) b) => Show (ProPre t f a b)+ -- | @since 0.3.4.1 deriving instance Eq (t (Pre a f) b) => Eq (ProPre t f a b)+ -- | @since 0.3.4.1 deriving instance Ord (t (Pre a f) b) => Ord (ProPre t f a b) -- -- | If @t@ is a contravariant functor combinator, then you applying it to -- @'Post' a f@ gives you a profunctor.-newtype ProPost t f a b = ProPost { unProPost :: t (Post b f) a }+newtype ProPost t f a b = ProPost {unProPost :: t (Post b f) a} instance (HFunctor t, forall x. Contravariant (t (Post x f))) => Profunctor (ProPost t f) where- dimap f g = ProPost- . hmap (mapPost g)- . contramap f- . unProPost+ dimap f g =+ ProPost+ . hmap (mapPost g)+ . contramap f+ . unProPost -- | @since 0.3.4.1 instance (HFunctor t, Contravariant (t (Post a f))) => Functor (ProPost t f a) where- fmap f = ProPost- . hmap (mapPost f)- . unProPost+ fmap f =+ ProPost+ . hmap (mapPost f)+ . unProPost+ -- | @since 0.3.4.1 instance (HFunctor t, Contravariant (t (Post a f))) => Invariant (ProPost t f a) where- invmap f _ = fmap f+ invmap f _ = fmap f
test/Spec.hs view
@@ -1,10 +1,12 @@-import Test.Tasty-import Tests.HBifunctor-import Tests.HFunctor+import Test.Tasty+import Tests.HBifunctor+import Tests.HFunctor main :: IO ()-main = defaultMain $- testGroup "Tests" [ hfunctorTests- , hbifunctorTests- ]-+main =+ defaultMain $+ testGroup+ "Tests"+ [ hfunctorTests+ , hbifunctorTests+ ]
test/Tests/HBifunctor.hs view
@@ -1,484 +1,582 @@ module Tests.HBifunctor (- hbifunctorTests- ) where+ hbifunctorTests,+) where -import Control.Applicative-import Control.Monad.Freer.Church-import Control.Natural.IsoF-import Data.Bifunctor-import Data.Bifunctor.Joker-import Data.Functor-import Data.Functor.Combinator-import Data.Functor.Identity-import Data.Functor.Product-import Data.Functor.Sum-import Data.HBifunctor.Associative-import Data.HBifunctor.Tensor-import Data.HFunctor.Chain-import Data.Maybe-import Data.Proxy-import Hedgehog-import Test.Tasty-import Test.Tasty.Hedgehog-import Tests.Util-import qualified Data.Semigroup as S-import qualified Hedgehog.Gen as Gen-import qualified Hedgehog.Range as Range+import Control.Applicative+import Control.Monad.Freer.Church+import Control.Natural.IsoF+import Data.Bifunctor+import Data.Bifunctor.Joker+import Data.Functor+import Data.Functor.Combinator+import Data.Functor.Identity+import Data.Functor.Product+import Data.Functor.Sum+import Data.HBifunctor.Associative+import Data.HBifunctor.Tensor+import Data.HFunctor.Chain+import Data.Maybe+import Data.Proxy+import qualified Data.Semigroup as S+import Hedgehog+import qualified Hedgehog.Gen as Gen+import qualified Hedgehog.Range as Range+import Test.Tasty+import Test.Tasty.Hedgehog+import Tests.Util -hbimapProp- :: forall t f g m a.- ( HBifunctor t- , Monad m- , Show (t f g a), Eq (t f g a)- )- => Gen (t f g a)- -> PropertyT m ()+hbimapProp ::+ forall t f g m a.+ ( HBifunctor t+ , Monad m+ , Show (t f g a)+ , Eq (t f g a)+ ) =>+ Gen (t f g a) ->+ PropertyT m () hbimapProp gx = do- x <- forAll gx- hbimap id id x === x+ x <- forAll gx+ hbimap id id x === x -associatingProp- :: forall t f g h m a.- ( Associative t- , FunctorBy t f- , FunctorBy t g- , FunctorBy t h- , Monad m- , Show (t f (t g h) a)- , Show (t (t f g) h a)- , Eq (t f (t g h) a)- , Eq (t (t f g) h a)- )- => Gen (t f (t g h) a)- -> Gen (t (t f g) h a)- -> PropertyT m ()+associatingProp ::+ forall t f g h m a.+ ( Associative t+ , FunctorBy t f+ , FunctorBy t g+ , FunctorBy t h+ , Monad m+ , Show (t f (t g h) a)+ , Show (t (t f g) h a)+ , Eq (t f (t g h) a)+ , Eq (t (t f g) h a)+ ) =>+ Gen (t f (t g h) a) ->+ Gen (t (t f g) h a) ->+ PropertyT m () associatingProp = isoProp (associating @t) -matchingNEProp- :: forall t f m a.- ( Associative t- , FunctorBy t f- , Monad m- , Show (f a), Eq (f a)- , Show (NonEmptyBy t f a), Eq (NonEmptyBy t f a)- , Show (t f (NonEmptyBy t f) a), Eq (t f (NonEmptyBy t f) a)- )- => Gen (NonEmptyBy t f a)- -> Gen (f a)- -> Gen (t f (NonEmptyBy t f) a)- -> PropertyT m ()+matchingNEProp ::+ forall t f m a.+ ( Associative t+ , FunctorBy t f+ , Monad m+ , Show (f a)+ , Eq (f a)+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ , Show (t f (NonEmptyBy t f) a)+ , Eq (t f (NonEmptyBy t f) a)+ ) =>+ Gen (NonEmptyBy t f a) ->+ Gen (f a) ->+ Gen (t f (NonEmptyBy t f) a) ->+ PropertyT m () matchingNEProp gx gy gz = isoProp (matchingNE @t) gx (sumGen gy gz) -unrollingNEProp- :: forall t f m a.- ( SemigroupIn t f- , Monad m- , Show (NonEmptyBy t f a), Eq (NonEmptyBy t f a)- , Show (f a), Eq (f a)- , Show (t f (Chain1 t f) a), Eq (t f (Chain1 t f) a)- )- => Gen (NonEmptyBy t f a)- -> Gen (Chain1 t f a)- -> PropertyT m ()+unrollingNEProp ::+ forall t f m a.+ ( SemigroupIn t f+ , Monad m+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ , Show (f a)+ , Eq (f a)+ , Show (t f (Chain1 t f) a)+ , Eq (t f (Chain1 t f) a)+ ) =>+ Gen (NonEmptyBy t f a) ->+ Gen (Chain1 t f a) ->+ PropertyT m () unrollingNEProp = isoProp (unrollingNE @t) -consNEProp- :: forall t f m a.- ( Associative t- , Monad m- , Show (t f (NonEmptyBy t f) a)- , Show (NonEmptyBy t f a), Eq (NonEmptyBy t f a)- )- => Gen (t f (NonEmptyBy t f) a)- -> PropertyT m ()+consNEProp ::+ forall t f m a.+ ( Associative t+ , Monad m+ , Show (t f (NonEmptyBy t f) a)+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ ) =>+ Gen (t f (NonEmptyBy t f) a) ->+ PropertyT m () consNEProp gx = do- x <- forAll gx- appendNE (hleft inject x) === consNE x+ x <- forAll gx+ appendNE (hleft inject x) === consNE x -toNonEmptyByProp- :: forall t f m a.- ( Associative t- , Monad m- , Show (t f f a)- , Show (NonEmptyBy t f a), Eq (NonEmptyBy t f a)- )- => Gen (t f f a)- -> PropertyT m ()+toNonEmptyByProp ::+ forall t f m a.+ ( Associative t+ , Monad m+ , Show (t f f a)+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ ) =>+ Gen (t f f a) ->+ PropertyT m () toNonEmptyByProp gx = do- x <- forAll gx- appendNE (hbimap inject inject x) === toNonEmptyBy x+ x <- forAll gx+ appendNE (hbimap inject inject x) === toNonEmptyBy x -biretractProp- :: forall t f m a.- ( SemigroupIn t f- , Interpret (NonEmptyBy t) f- , Monad m- , Show (t f f a)- , Show (f a), Eq (f a)- )- => Gen (t f f a)- -> PropertyT m ()+biretractProp ::+ forall t f m a.+ ( SemigroupIn t f+ , Interpret (NonEmptyBy t) f+ , Monad m+ , Show (t f f a)+ , Show (f a)+ , Eq (f a)+ ) =>+ Gen (t f f a) ->+ PropertyT m () biretractProp gx = do- x <- forAll gx- retract (appendNE (hbimap inject inject x)) === biretract x+ x <- forAll gx+ retract (appendNE (hbimap inject inject x)) === biretract x -binterpretProp- :: forall t f m a.- ( SemigroupIn t f- , Monad m- , Show (t f f a)- , Show (f a), Eq (f a)- )- => Gen (t f f a)- -> PropertyT m ()+binterpretProp ::+ forall t f m a.+ ( SemigroupIn t f+ , Monad m+ , Show (t f f a)+ , Show (f a)+ , Eq (f a)+ ) =>+ Gen (t f f a) ->+ PropertyT m () binterpretProp gx = do- x <- forAll gx- biretract x === binterpret id id x+ x <- forAll gx+ biretract x === binterpret id id x -rightIdentityProp- :: forall t i f m a.- ( Tensor t i- , FunctorBy t f- , Monad m- , Show (f a), Eq (f a)- , Show (t f i a), Eq (t f i a)- )- => Gen (f a)- -> Gen (t f i a)- -> PropertyT m ()+rightIdentityProp ::+ forall t i f m a.+ ( Tensor t i+ , FunctorBy t f+ , Monad m+ , Show (f a)+ , Eq (f a)+ , Show (t f i a)+ , Eq (t f i a)+ ) =>+ Gen (f a) ->+ Gen (t f i a) ->+ PropertyT m () rightIdentityProp = isoProp (rightIdentity @t) -leftIdentityProp- :: forall t i g m a.- ( Tensor t i- , FunctorBy t g- , Monad m- , Show (g a), Eq (g a)- , Show (t i g a), Eq (t i g a)- )- => Gen (g a)- -> Gen (t i g a)- -> PropertyT m ()+leftIdentityProp ::+ forall t i g m a.+ ( Tensor t i+ , FunctorBy t g+ , Monad m+ , Show (g a)+ , Eq (g a)+ , Show (t i g a)+ , Eq (t i g a)+ ) =>+ Gen (g a) ->+ Gen (t i g a) ->+ PropertyT m () leftIdentityProp = isoProp (leftIdentity @t) -splittingLBProp- :: forall t i f m a.- ( Tensor t i- , Monad m- , Show (i a), Eq (i a)- , Show (ListBy t f a), Eq (ListBy t f a)- , Show (t f (ListBy t f) a), Eq (t f (ListBy t f) a)- )- => Gen (ListBy t f a)- -> Gen ((i :+: t f (ListBy t f)) a)- -> PropertyT m ()+splittingLBProp ::+ forall t i f m a.+ ( Tensor t i+ , Monad m+ , Show (i a)+ , Eq (i a)+ , Show (ListBy t f a)+ , Eq (ListBy t f a)+ , Show (t f (ListBy t f) a)+ , Eq (t f (ListBy t f) a)+ ) =>+ Gen (ListBy t f a) ->+ Gen ((i :+: t f (ListBy t f)) a) ->+ PropertyT m () splittingLBProp = isoProp (splittingLB @t) -unrollingProp- :: forall t i f m a.- ( MonoidIn t i f- , Monad m- , Show (ListBy t f a), Eq (ListBy t f a)- , Show (i a), Eq (i a)- , Show (t f (Chain t i f) a), Eq (t f (Chain t i f) a)- )- => Gen (ListBy t f a)- -> Gen (Chain t i f a)- -> PropertyT m ()+unrollingProp ::+ forall t i f m a.+ ( MonoidIn t i f+ , Monad m+ , Show (ListBy t f a)+ , Eq (ListBy t f a)+ , Show (i a)+ , Eq (i a)+ , Show (t f (Chain t i f) a)+ , Eq (t f (Chain t i f) a)+ ) =>+ Gen (ListBy t f a) ->+ Gen (Chain t i f a) ->+ PropertyT m () unrollingProp = isoProp (unrolling @t) -toListByProp- :: forall t i f m a.- ( Tensor t i- , Monad m- , Show (t f f a)- , Show (ListBy t f a), Eq (ListBy t f a)- )- => Gen (t f f a)- -> PropertyT m ()+toListByProp ::+ forall t i f m a.+ ( Tensor t i+ , Monad m+ , Show (t f f a)+ , Show (ListBy t f a)+ , Eq (ListBy t f a)+ ) =>+ Gen (t f f a) ->+ PropertyT m () toListByProp gx = do- x <- forAll gx- reviewF (splittingLB @t) (R1 (hright (inject @(ListBy t)) x)) === toListBy @t x+ x <- forAll gx+ reviewF (splittingLB @t) (R1 (hright (inject @(ListBy t)) x)) === toListBy @t x -fromNEProp- :: forall t i f m a.- ( Tensor t i- , Monad m- , Show (NonEmptyBy t f a)- , Show (ListBy t f a), Eq (ListBy t f a)- )- => Gen (NonEmptyBy t f a)- -> PropertyT m ()+fromNEProp ::+ forall t i f m a.+ ( Tensor t i+ , Monad m+ , Show (NonEmptyBy t f a)+ , Show (ListBy t f a)+ , Eq (ListBy t f a)+ ) =>+ Gen (NonEmptyBy t f a) ->+ PropertyT m () fromNEProp gx = do- x <- forAll gx- reviewF (splittingLB @t) (R1 (splitNE @t x)) === fromNE @t x+ x <- forAll gx+ reviewF (splittingLB @t) (R1 (splitNE @t x)) === fromNE @t x -pureTProp- :: forall t i f m a.- ( MonoidIn t i f- , Interpret (ListBy t) f- , Monad m- , Show (i a)- , Show (f a), Eq (f a)- )- => Gen (i a)- -> PropertyT m ()+pureTProp ::+ forall t i f m a.+ ( MonoidIn t i f+ , Interpret (ListBy t) f+ , Monad m+ , Show (i a)+ , Show (f a)+ , Eq (f a)+ ) =>+ Gen (i a) ->+ PropertyT m () pureTProp gx = do- x <- forAll gx- retract (reviewF (splittingLB @t) (L1 x)) === pureT @t @_ @f x+ x <- forAll gx+ retract (reviewF (splittingLB @t) (L1 x)) === pureT @t @_ @f x -splittingNEProp- :: forall t i f m a.- ( Matchable t i- , FunctorBy t f- , Monad m- , Show (NonEmptyBy t f a), Eq (NonEmptyBy t f a)- , Show (t f (ListBy t f) a), Eq (t f (ListBy t f) a)- )- => Gen (NonEmptyBy t f a)- -> Gen (t f (ListBy t f) a)- -> PropertyT m ()+splittingNEProp ::+ forall t i f m a.+ ( Matchable t i+ , FunctorBy t f+ , Monad m+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ , Show (t f (ListBy t f) a)+ , Eq (t f (ListBy t f) a)+ ) =>+ Gen (NonEmptyBy t f a) ->+ Gen (t f (ListBy t f) a) ->+ PropertyT m () splittingNEProp = isoProp (splittingNE @t) -matchingLBProp- :: forall t i f m a.- ( Matchable t i- , FunctorBy t f- , Monad m- , Show (i a), Eq (i a)- , Show (ListBy t f a), Eq (ListBy t f a)- , Show (NonEmptyBy t f a), Eq (NonEmptyBy t f a)- )- => Gen (ListBy t f a)- -> Gen ((i :+: NonEmptyBy t f) a)- -> PropertyT m ()+matchingLBProp ::+ forall t i f m a.+ ( Matchable t i+ , FunctorBy t f+ , Monad m+ , Show (i a)+ , Eq (i a)+ , Show (ListBy t f a)+ , Eq (ListBy t f a)+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ ) =>+ Gen (ListBy t f a) ->+ Gen ((i :+: NonEmptyBy t f) a) ->+ PropertyT m () matchingLBProp = isoProp (matchingLB @t) -matchingChainProp- :: forall t i f m a.- ( Matchable t i- , FunctorBy t f- , Monad m- , Show (f a), Eq (f a)- , Show (i a), Eq (i a)- , Show (t f (Chain1 t f) a), Eq (t f (Chain1 t f) a)- , Show (t f (Chain t i f) a), Eq (t f (Chain t i f) a)- )- => Gen (Chain t i f a)- -> Gen ((i :+: Chain1 t f) a)- -> PropertyT m ()+matchingChainProp ::+ forall t i f m a.+ ( Matchable t i+ , FunctorBy t f+ , Monad m+ , Show (f a)+ , Eq (f a)+ , Show (i a)+ , Eq (i a)+ , Show (t f (Chain1 t f) a)+ , Eq (t f (Chain1 t f) a)+ , Show (t f (Chain t i f) a)+ , Eq (t f (Chain t i f) a)+ ) =>+ Gen (Chain t i f a) ->+ Gen ((i :+: Chain1 t f) a) ->+ PropertyT m () matchingChainProp = isoProp (matchingChain @t) -genChain- :: forall t i f m a. (MonadGen m, TestHBifunctor t)- => m (f a)- -> Maybe (m (i a))- -> m (Chain t i f a)+genChain ::+ forall t i f m a.+ (MonadGen m, TestHBifunctor t) =>+ m (f a) ->+ Maybe (m (i a)) ->+ m (Chain t i f a) genChain gx gy = go where go = case gy of- Nothing -> More <$> genHB @t gx go- Just gy' -> Gen.bool >>= \case- False -> Done <$> gy'- True -> More <$> genHB @t gx go+ Nothing -> More <$> genHB @t gx go+ Just gy' ->+ Gen.bool >>= \case+ False -> Done <$> gy'+ True -> More <$> genHB @t gx go -maybeSumGen- :: Maybe (Gen (f a))- -> Gen (g a)- -> Gen ((f :+: g) a)+maybeSumGen ::+ Maybe (Gen (f a)) ->+ Gen (g a) ->+ Gen ((f :+: g) a) maybeSumGen = maybe (fmap R1) sumGen -hbifunctorProps- :: forall t f a.- ( TestHBifunctor t- , Show (t f f a), Eq (t f f a)- )- => Gen (f a)- -> TestTree-hbifunctorProps gx = testGroup "HBifunctor"- . map (uncurry testProperty . second property) $- [ ("hbimap", hbimapProp @t (genHB gx gx))- ]+hbifunctorProps ::+ forall t f a.+ ( TestHBifunctor t+ , Show (t f f a)+ , Eq (t f f a)+ ) =>+ Gen (f a) ->+ TestTree+hbifunctorProps gx =+ testGroup+ "HBifunctor"+ [testProperty "hbimap" . property $ hbimapProp @t (genHB gx gx)] -associativeProps- :: forall t f a.- ( SemigroupIn t f- , Interpret (NonEmptyBy t) f- , TestHBifunctor t- , TestHFunctor (NonEmptyBy t)- , Show (t f (t f f) a) , Eq (t f (t f f) a)- , Show (t (t f f) f a) , Eq (t (t f f) f a)- , Show (t f f a)- , Show (t f (NonEmptyBy t f) a) , Eq (t f (NonEmptyBy t f) a)- , Show (NonEmptyBy t f a) , Eq (NonEmptyBy t f a)- , Show (t f (Chain1 t f) a), Eq (t f (Chain1 t f) a)- , Show (f a) , Eq (f a)- , TestHFunctorBy (NonEmptyBy t) f- )- => Gen (f a)- -> TestTree-associativeProps gx = testGroup "Associative"- . map (uncurry testProperty . second property) $- [ ("associating", associatingProp @t (genHB gx (genHB gx gx)) (genHB (genHB gx gx) gx))- , ("matchingNE" , matchingNEProp @t (genHF gx) gx (genHB gx (genHF gx)))- , ("unrollingNE", unrollingNEProp @t (genHF gx) (genHF gx))- , ("consNE" , consNEProp @t (genHB gx (genHF gx)))- , ("toNonEmptyBy" , toNonEmptyByProp @t (genHB gx gx))- , ("biretract" , biretractProp @t (genHB gx gx))- , ("binterpret" , binterpretProp @t (genHB gx gx))- ]+associativeProps ::+ forall t f a.+ ( SemigroupIn t f+ , Interpret (NonEmptyBy t) f+ , TestHBifunctor t+ , TestHFunctor (NonEmptyBy t)+ , Show (t f (t f f) a)+ , Eq (t f (t f f) a)+ , Show (t (t f f) f a)+ , Eq (t (t f f) f a)+ , Show (t f f a)+ , Show (t f (NonEmptyBy t f) a)+ , Eq (t f (NonEmptyBy t f) a)+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ , Show (t f (Chain1 t f) a)+ , Eq (t f (Chain1 t f) a)+ , Show (f a)+ , Eq (f a)+ , TestHFunctorBy (NonEmptyBy t) f+ ) =>+ Gen (f a) ->+ TestTree+associativeProps gx =+ testGroup "Associative"+ . map (uncurry testProperty . second property)+ $ [ ("associating", associatingProp @t (genHB gx (genHB gx gx)) (genHB (genHB gx gx) gx))+ , ("matchingNE", matchingNEProp @t (genHF gx) gx (genHB gx (genHF gx)))+ , ("unrollingNE", unrollingNEProp @t (genHF gx) (genHF gx))+ , ("consNE", consNEProp @t (genHB gx (genHF gx)))+ , ("toNonEmptyBy", toNonEmptyByProp @t (genHB gx gx))+ , ("biretract", biretractProp @t (genHB gx gx))+ , ("binterpret", binterpretProp @t (genHB gx gx))+ ] -tensorProps- :: forall t i f a.- ( MonoidIn t i f- , Interpret (ListBy t) f- , TestHBifunctor t- , TestHFunctor (ListBy t)- , TestHFunctor (NonEmptyBy t)- , Show (t f i a) , Eq (t f i a)- , Show (t i f a) , Eq (t i f a)- , Show (t f (ListBy t f) a) , Eq (t f (ListBy t f) a)- , Show (t f (Chain t i f) a), Eq (t f (Chain t i f) a)- , Show (t f f a)- , Show (ListBy t f a) , Eq (ListBy t f a)- , Show (NonEmptyBy t f a)- , Show (i a) , Eq (i a)- , Show (f a) , Eq (f a)- , TestHFunctorBy (ListBy t) f- , TestHFunctorBy (NonEmptyBy t) f- )- => Gen (f a)- -> Maybe (Gen (i a))- -> TestTree-tensorProps gx gy = testGroup "Tensor"- . map (uncurry testProperty . second property)- . catMaybes $- [ gy <&> \y -> ("rightIdentity", rightIdentityProp @t gx (genHB gx y))- , gy <&> \y -> ("leftIdentity" , leftIdentityProp @t gx (genHB y gx))- , Just ("splittingLB", splittingLBProp @t (genHF gx) (maybeSumGen gy (genHB gx (genHF gx))))- , Just ("unrolling", unrollingProp @t (genHF gx) (genChain gx gy))- , Just ("toListBy" , toListByProp @t (genHB gx gx))- , Just ("fromNE" , fromNEProp @t (genHF gx))- , gy <&> \y -> ("pureT" , pureTProp @t @_ @f y)- ]+tensorProps ::+ forall t i f a.+ ( MonoidIn t i f+ , Interpret (ListBy t) f+ , TestHBifunctor t+ , TestHFunctor (ListBy t)+ , TestHFunctor (NonEmptyBy t)+ , Show (t f i a)+ , Eq (t f i a)+ , Show (t i f a)+ , Eq (t i f a)+ , Show (t f (ListBy t f) a)+ , Eq (t f (ListBy t f) a)+ , Show (t f (Chain t i f) a)+ , Eq (t f (Chain t i f) a)+ , Show (t f f a)+ , Show (ListBy t f a)+ , Eq (ListBy t f a)+ , Show (NonEmptyBy t f a)+ , Show (i a)+ , Eq (i a)+ , Show (f a)+ , Eq (f a)+ , TestHFunctorBy (ListBy t) f+ , TestHFunctorBy (NonEmptyBy t) f+ ) =>+ Gen (f a) ->+ Maybe (Gen (i a)) ->+ TestTree+tensorProps gx gy =+ testGroup "Tensor"+ . map (uncurry testProperty . second property)+ . catMaybes+ $ [ gy <&> \y -> ("rightIdentity", rightIdentityProp @t gx (genHB gx y))+ , gy <&> \y -> ("leftIdentity", leftIdentityProp @t gx (genHB y gx))+ , Just ("splittingLB", splittingLBProp @t (genHF gx) (maybeSumGen gy (genHB gx (genHF gx))))+ , Just ("unrolling", unrollingProp @t (genHF gx) (genChain gx gy))+ , Just ("toListBy", toListByProp @t (genHB gx gx))+ , Just ("fromNE", fromNEProp @t (genHF gx))+ , gy <&> \y -> ("pureT", pureTProp @t @_ @f y)+ ] -matchableProps- :: forall t i f a.- ( Matchable t i- , FunctorBy t f- , TestHBifunctor t- , TestHFunctor (ListBy t)- , TestHFunctor (NonEmptyBy t)- , Show (t f (ListBy t f) a) , Eq (t f (ListBy t f) a)- , Show (t f (Chain t i f) a), Eq (t f (Chain t i f) a)- , Show (t f (Chain1 t f) a) , Eq (t f (Chain1 t f) a)- , Show (ListBy t f a) , Eq (ListBy t f a)- , Show (NonEmptyBy t f a) , Eq (NonEmptyBy t f a)- , Show (i a) , Eq (i a)- , Show (f a) , Eq (f a)- , TestHFunctorBy (ListBy t) f- , TestHFunctorBy (NonEmptyBy t) f- )- => Gen (f a)- -> Maybe (Gen (i a))- -> TestTree-matchableProps gx gy = testGroup "Matchable"- . map (uncurry testProperty . second property) $- [ ("splittingNE" , splittingNEProp @t (genHF gx) (genHB gx (genHF gx)))- , ("matchingLB" , matchingLBProp @t (genHF gx) (maybeSumGen gy (genHF gx)))- , ("matchingChain", matchingChainProp @t (genChain gx gy) (maybeSumGen gy (genHF gx)))- ]+matchableProps ::+ forall t i f a.+ ( Matchable t i+ , FunctorBy t f+ , TestHBifunctor t+ , TestHFunctor (ListBy t)+ , TestHFunctor (NonEmptyBy t)+ , Show (t f (ListBy t f) a)+ , Eq (t f (ListBy t f) a)+ , Show (t f (Chain t i f) a)+ , Eq (t f (Chain t i f) a)+ , Show (t f (Chain1 t f) a)+ , Eq (t f (Chain1 t f) a)+ , Show (ListBy t f a)+ , Eq (ListBy t f a)+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ , Show (i a)+ , Eq (i a)+ , Show (f a)+ , Eq (f a)+ , TestHFunctorBy (ListBy t) f+ , TestHFunctorBy (NonEmptyBy t) f+ ) =>+ Gen (f a) ->+ Maybe (Gen (i a)) ->+ TestTree+matchableProps gx gy =+ testGroup "Matchable"+ . map (uncurry testProperty . second property)+ $ [ ("splittingNE", splittingNEProp @t (genHF gx) (genHB gx (genHF gx)))+ , ("matchingLB", matchingLBProp @t (genHF gx) (maybeSumGen gy (genHF gx)))+ , ("matchingChain", matchingChainProp @t (genChain gx gy) (maybeSumGen gy (genHF gx)))+ ] -associativeProps_- :: forall t f a.- ( SemigroupIn t f- , Interpret (NonEmptyBy t) f- , TestHBifunctor t- , TestHFunctor (NonEmptyBy t)- , Show (t f (t f f) a) , Eq (t f (t f f) a)- , Show (t (t f f) f a) , Eq (t (t f f) f a)- , Show (t f f a) , Eq (t f f a)- , Show (t f (NonEmptyBy t f) a) , Eq (t f (NonEmptyBy t f) a)- , Show (NonEmptyBy t f a) , Eq (NonEmptyBy t f a)- , Show (t f (Chain1 t f) a), Eq (t f (Chain1 t f) a)- , Show (f a) , Eq (f a)- , TestHFunctorBy (NonEmptyBy t) f- )- => Gen (f a)- -> [TestTree]-associativeProps_ gx = [ hbifunctorProps @t gx, associativeProps @t gx ]+associativeProps_ ::+ forall t f a.+ ( SemigroupIn t f+ , Interpret (NonEmptyBy t) f+ , TestHBifunctor t+ , TestHFunctor (NonEmptyBy t)+ , Show (t f (t f f) a)+ , Eq (t f (t f f) a)+ , Show (t (t f f) f a)+ , Eq (t (t f f) f a)+ , Show (t f f a)+ , Eq (t f f a)+ , Show (t f (NonEmptyBy t f) a)+ , Eq (t f (NonEmptyBy t f) a)+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ , Show (t f (Chain1 t f) a)+ , Eq (t f (Chain1 t f) a)+ , Show (f a)+ , Eq (f a)+ , TestHFunctorBy (NonEmptyBy t) f+ ) =>+ Gen (f a) ->+ [TestTree]+associativeProps_ gx = [hbifunctorProps @t gx, associativeProps @t gx] -tensorProps_- :: forall t i f a.- ( MonoidIn t i f- , Interpret (NonEmptyBy t) f- , Interpret (ListBy t) f- , TestHBifunctor t- , TestHFunctor (ListBy t)- , TestHFunctor (NonEmptyBy t)- , Show (t f (t f f) a) , Eq (t f (t f f) a)- , Show (t (t f f) f a) , Eq (t (t f f) f a)- , Show (t f i a) , Eq (t f i a)- , Show (t i f a) , Eq (t i f a)- , Show (t f (ListBy t f) a) , Eq (t f (ListBy t f) a)- , Show (t f (NonEmptyBy t f) a) , Eq (t f (NonEmptyBy t f) a)- , Show (t f (Chain t i f) a), Eq (t f (Chain t i f) a)- , Show (t f (Chain1 t f) a) , Eq (t f (Chain1 t f) a)- , Show (t f f a) , Eq (t f f a)- , Show (ListBy t f a) , Eq (ListBy t f a)- , Show (NonEmptyBy t f a) , Eq (NonEmptyBy t f a)- , Show (i a) , Eq (i a)- , Show (f a) , Eq (f a)- , TestHFunctorBy (NonEmptyBy t) f- , TestHFunctorBy (ListBy t) f- )- => Gen (f a)- -> Maybe (Gen (i a))- -> [TestTree]-tensorProps_ gx gy = associativeProps_ @t gx ++ [ tensorProps @t gx gy ]+tensorProps_ ::+ forall t i f a.+ ( MonoidIn t i f+ , Interpret (NonEmptyBy t) f+ , Interpret (ListBy t) f+ , TestHBifunctor t+ , TestHFunctor (ListBy t)+ , TestHFunctor (NonEmptyBy t)+ , Show (t f (t f f) a)+ , Eq (t f (t f f) a)+ , Show (t (t f f) f a)+ , Eq (t (t f f) f a)+ , Show (t f i a)+ , Eq (t f i a)+ , Show (t i f a)+ , Eq (t i f a)+ , Show (t f (ListBy t f) a)+ , Eq (t f (ListBy t f) a)+ , Show (t f (NonEmptyBy t f) a)+ , Eq (t f (NonEmptyBy t f) a)+ , Show (t f (Chain t i f) a)+ , Eq (t f (Chain t i f) a)+ , Show (t f (Chain1 t f) a)+ , Eq (t f (Chain1 t f) a)+ , Show (t f f a)+ , Eq (t f f a)+ , Show (ListBy t f a)+ , Eq (ListBy t f a)+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ , Show (i a)+ , Eq (i a)+ , Show (f a)+ , Eq (f a)+ , TestHFunctorBy (NonEmptyBy t) f+ , TestHFunctorBy (ListBy t) f+ ) =>+ Gen (f a) ->+ Maybe (Gen (i a)) ->+ [TestTree]+tensorProps_ gx gy = associativeProps_ @t gx ++ [tensorProps @t gx gy] -matchableProps_- :: forall t i f a.- ( Matchable t i- , Interpret (NonEmptyBy t) f- , Interpret (ListBy t) f- , MonoidIn t i f- , TestHBifunctor t- , TestHFunctor (ListBy t)- , TestHFunctor (NonEmptyBy t)- , Show (t f (t f f) a) , Eq (t f (t f f) a)- , Show (t (t f f) f a) , Eq (t (t f f) f a)- , Show (t f i a) , Eq (t f i a)- , Show (t i f a) , Eq (t i f a)- , Show (t f (ListBy t f) a) , Eq (t f (ListBy t f) a)- , Show (t f (NonEmptyBy t f) a) , Eq (t f (NonEmptyBy t f) a)- , Show (t f (Chain t i f) a), Eq (t f (Chain t i f) a)- , Show (t f (Chain1 t f) a) , Eq (t f (Chain1 t f) a)- , Show (t f f a) , Eq (t f f a)- , Show (ListBy t f a) , Eq (ListBy t f a)- , Show (NonEmptyBy t f a) , Eq (NonEmptyBy t f a)- , Show (i a) , Eq (i a)- , Show (f a) , Eq (f a)- , TestHFunctorBy (ListBy t) f- , TestHFunctorBy (NonEmptyBy t) f- )- => Gen (f a)- -> Maybe (Gen (i a))- -> [TestTree]-matchableProps_ gx gy = tensorProps_ @t gx gy ++ [ matchableProps @t gx gy ]+matchableProps_ ::+ forall t i f a.+ ( Matchable t i+ , Interpret (NonEmptyBy t) f+ , Interpret (ListBy t) f+ , MonoidIn t i f+ , TestHBifunctor t+ , TestHFunctor (ListBy t)+ , TestHFunctor (NonEmptyBy t)+ , Show (t f (t f f) a)+ , Eq (t f (t f f) a)+ , Show (t (t f f) f a)+ , Eq (t (t f f) f a)+ , Show (t f i a)+ , Eq (t f i a)+ , Show (t i f a)+ , Eq (t i f a)+ , Show (t f (ListBy t f) a)+ , Eq (t f (ListBy t f) a)+ , Show (t f (NonEmptyBy t f) a)+ , Eq (t f (NonEmptyBy t f) a)+ , Show (t f (Chain t i f) a)+ , Eq (t f (Chain t i f) a)+ , Show (t f (Chain1 t f) a)+ , Eq (t f (Chain1 t f) a)+ , Show (t f f a)+ , Eq (t f f a)+ , Show (ListBy t f a)+ , Eq (ListBy t f a)+ , Show (NonEmptyBy t f a)+ , Eq (NonEmptyBy t f a)+ , Show (i a)+ , Eq (i a)+ , Show (f a)+ , Eq (f a)+ , TestHFunctorBy (ListBy t) f+ , TestHFunctorBy (NonEmptyBy t) f+ ) =>+ Gen (f a) ->+ Maybe (Gen (i a)) ->+ [TestTree]+matchableProps_ gx gy = tensorProps_ @t gx gy ++ [matchableProps @t gx gy] hbifunctorTests :: TestTree-hbifunctorTests = testGroup "HBifunctors"- [ testGroup "Sum" $ matchableProps_ @(:+:) listGen Nothing- , testGroup "Sum'" $ matchableProps_ @Sum listGen Nothing- , testGroup "Product" $ matchableProps_ @(:*:) listGen (Just (pure Proxy))- , testGroup "Product'" $ matchableProps_ @Product listGen (Just (pure Proxy))- , testGroup "These1" $ tensorProps_ @These1 listGen Nothing- , testGroup "LeftF" $ associativeProps_ @LeftF listGen- , testGroup "Joker" $ associativeProps_ @Joker listGen- , testGroup "RightF" $ associativeProps_ @RightF listGen- , testGroup "Day" $ matchableProps_ @Day (Const . S.Sum <$> intGen)- (Just (Identity <$> intGen))- , testGroup "Comp" $ tensorProps_ @Comp (Gen.list (Range.linear 0 3) intGen)- (Just (Identity <$> intGen))+hbifunctorTests =+ testGroup+ "HBifunctors"+ [ testGroup "Sum" $ matchableProps_ @(:+:) listGen Nothing+ , testGroup "Sum'" $ matchableProps_ @Sum listGen Nothing+ , testGroup "Product" $ matchableProps_ @(:*:) listGen (Just (pure Proxy))+ , testGroup "Product'" $ matchableProps_ @Product listGen (Just (pure Proxy))+ , testGroup "These1" $ tensorProps_ @These1 listGen Nothing+ , testGroup "LeftF" $ associativeProps_ @LeftF listGen+ , testGroup "Joker" $ associativeProps_ @Joker listGen+ , testGroup "RightF" $ associativeProps_ @RightF listGen+ , testGroup "Day" $+ matchableProps_ @Day+ (Const . S.Sum <$> intGen)+ (Just (Identity <$> intGen))+ , testGroup "Comp" $+ tensorProps_ @Comp+ (Gen.list (Range.linear 0 3) intGen)+ (Just (Identity <$> intGen)) ]
test/Tests/HFunctor.hs view
@@ -1,240 +1,259 @@ module Tests.HFunctor (- hfunctorTests- ) where+ hfunctorTests,+) where -import Control.Applicative-import Control.Applicative.Backwards-import Data.Bifunctor-import Data.Functor.Bind-import Data.Functor.Combinator-import Data.Functor.Product-import Data.Functor.Reverse-import Data.Functor.Sum-import Data.HFunctor-import GHC.Generics (M1(..), Meta(..))-import Hedgehog-import Test.Tasty-import Test.Tasty.Hedgehog-import Tests.Util-import qualified Control.Applicative.Free.Fast as FAF+import Control.Applicative+import Control.Applicative.Backwards+import qualified Control.Applicative.Free.Fast as FAF import qualified Control.Applicative.Free.Final as FA-import qualified Data.Semigroup as S-import qualified Hedgehog.Gen as Gen-import qualified Hedgehog.Range as Range+import Data.Bifunctor+import Data.Functor.Bind+import Data.Functor.Combinator+import Data.Functor.Product+import Data.Functor.Reverse+import Data.Functor.Sum+import Data.HFunctor+import qualified Data.Semigroup as S+import Data.Void+import GHC.Generics (M1 (..), Meta (..))+import Hedgehog+import qualified Hedgehog.Gen as Gen+import qualified Hedgehog.Range as Range+import Test.Tasty+import Test.Tasty.Hedgehog+import Tests.Util -hmapProp- :: forall t f m a.- ( HFunctor t- , Monad m- , Show (t f a), Eq (t f a)- )- => Gen (t f a)- -> PropertyT m ()+hmapProp ::+ forall t f m a.+ ( HFunctor t+ , Monad m+ , Show (t f a)+ , Eq (t f a)+ ) =>+ Gen (t f a) ->+ PropertyT m () hmapProp gx = do- x <- forAll gx- hmap id x === x+ x <- forAll gx+ hmap id x === x -retractingProp- :: forall t f m a.- ( Interpret t f- , Monad m- , Show (f a)- , Show (t f a)- , Eq (f a)- )- => Gen (f a)- -> PropertyT m ()+retractingProp ::+ forall t f m a.+ ( Interpret t f+ , Monad m+ , Show (f a)+ , Show (t f a)+ , Eq (f a)+ ) =>+ Gen (f a) ->+ PropertyT m () retractingProp gx = do- x <- forAll gx- tripping x (inject @t) (Just . retract)+ x <- forAll gx+ tripping x (inject @t) (Just . retract) -interpretProp- :: forall t f m a.- ( Interpret t f- , Monad m- , Show (f a)- , Show (t f a)- , Eq (f a)- )- => Gen (t f a)- -> PropertyT m ()+interpretProp ::+ forall t f m a.+ ( Interpret t f+ , Monad m+ , Show (f a)+ , Show (t f a)+ , Eq (f a)+ ) =>+ Gen (t f a) ->+ PropertyT m () interpretProp gx = do- x <- forAll gx- retract x === interpret id x+ x <- forAll gx+ retract x === interpret id x -hbindInjectProp- :: forall t f m a.- ( HBind t- , Monad m- , Show (t f a), Eq (t f a)- )- => Gen (t f a)- -> PropertyT m ()+hbindInjectProp ::+ forall t f m a.+ ( HBind t+ , Monad m+ , Show (t f a)+ , Eq (t f a)+ ) =>+ Gen (t f a) ->+ PropertyT m () hbindInjectProp gx = do- x <- forAll gx- hbind inject x === x+ x <- forAll gx+ hbind inject x === x -hbindhjoinProp- :: forall t f m a.- ( HBind t- , Monad m- , Show (t (t f) a)- , Show (t f a), Eq (t f a)- )- => Gen (t (t f) a)- -> PropertyT m ()+hbindhjoinProp ::+ forall t f m a.+ ( HBind t+ , Monad m+ , Show (t (t f) a)+ , Show (t f a)+ , Eq (t f a)+ ) =>+ Gen (t (t f) a) ->+ PropertyT m () hbindhjoinProp gx = do- x <- forAll gx- hbind id x === hjoin x+ x <- forAll gx+ hbind id x === hjoin x -hjoinAssocProp- :: forall t f m a.- ( HBind t- , Monad m- , Show (t (t (t f)) a)- , Show (t f a), Eq (t f a)- )- => Gen (t (t (t f)) a)- -> PropertyT m ()+hjoinAssocProp ::+ forall t f m a.+ ( HBind t+ , Monad m+ , Show (t (t (t f)) a)+ , Show (t f a)+ , Eq (t f a)+ ) =>+ Gen (t (t (t f)) a) ->+ PropertyT m () hjoinAssocProp gx = do- x <- forAll gx- hjoin (hjoin x) === hjoin (hmap hjoin x)--hfunctorProps- :: forall t f a.- ( TestHFunctor t- , Show (t f a), Eq (t f a)- , TestHFunctorBy t f- )- => Gen (f a)- -> TestTree-hfunctorProps gx = testGroup "HFunctor"- . map (uncurry testProperty . second property) $- [ ("hmap", hmapProp @t (genHF gx))- ]+ x <- forAll gx+ hjoin (hjoin x) === hjoin (hmap hjoin x) -hbindProps- :: forall t f a.- ( HBind t- , TestHFunctor t- , Show (t f a) , Eq (t f a)- , Show (t (t f) a)- , Show (t (t (t f)) a)- , TestHFunctorBy t (t (t f))- , TestHFunctorBy t (t f)- , TestHFunctorBy t f- )- => Gen (f a)- -> TestTree-hbindProps gx = testGroup "HBind"- . map (uncurry testProperty . second property) $- [ ("hbindInject", hbindInjectProp @t (genHF gx))- , ("hbindhjoin" , hbindhjoinProp @t (genHF (genHF gx)))- , ("hjoinAssoc" , hjoinAssocProp @t (genHF (genHF (genHF gx))))- ]+hfunctorProps ::+ forall t f a.+ ( TestHFunctor t+ , Show (t f a)+ , Eq (t f a)+ , TestHFunctorBy t f+ ) =>+ Gen (f a) ->+ TestTree+hfunctorProps gx =+ testGroup+ "HFunctor"+ [testProperty "hmap" . property $ hmapProp @t (genHF gx)] -interpretProps- :: forall t f a.- ( Interpret t f- , TestHFunctor t- , Show (f a) , Eq (f a)- , Show (t f a)- , TestHFunctorBy t f- )- => Gen (f a)- -> TestTree-interpretProps gx = testGroup "Interpret"- . map (uncurry testProperty . second property) $- [ ("retracting", retractingProp @t gx)- , ("interpret" , interpretProp @t (genHF gx))- ]+hbindProps ::+ forall t f a.+ ( HBind t+ , TestHFunctor t+ , Show (t f a)+ , Eq (t f a)+ , Show (t (t f) a)+ , Show (t (t (t f)) a)+ , TestHFunctorBy t (t (t f))+ , TestHFunctorBy t (t f)+ , TestHFunctorBy t f+ ) =>+ Gen (f a) ->+ TestTree+hbindProps gx =+ testGroup "HBind"+ . map (uncurry testProperty . second property)+ $ [ ("hbindInject", hbindInjectProp @t (genHF gx))+ , ("hbindhjoin", hbindhjoinProp @t (genHF (genHF gx)))+ , ("hjoinAssoc", hjoinAssocProp @t (genHF (genHF (genHF gx))))+ ] -hbindProps_- :: forall t f a.- ( HBind t- , TestHFunctor t- , Show (t f a) , Eq (t f a)- , Show (t (t f) a)- , Show (t (t (t f)) a)- , TestHFunctorBy t f- , TestHFunctorBy t (t f)- , TestHFunctorBy t (t (t f))- )- => Gen (f a)- -> [TestTree]-hbindProps_ gx = [ hfunctorProps @t gx- , hbindProps @t gx- ]+interpretProps ::+ forall t f a.+ ( Interpret t f+ , TestHFunctor t+ , Show (f a)+ , Eq (f a)+ , Show (t f a)+ , TestHFunctorBy t f+ ) =>+ Gen (f a) ->+ TestTree+interpretProps gx =+ testGroup "Interpret"+ . map (uncurry testProperty . second property)+ $ [ ("retracting", retractingProp @t gx)+ , ("interpret", interpretProp @t (genHF gx))+ ] -interpretProps_- :: forall t f a.- ( Interpret t f- , TestHFunctor t- , Show (f a) , Eq (f a)- , Show (t f a) , Eq (t f a)- , TestHFunctorBy t f- )- => Gen (f a)- -> [TestTree]-interpretProps_ gx = [ hfunctorProps @t gx- , interpretProps @t gx- ]+hbindProps_ ::+ forall t f a.+ ( HBind t+ , TestHFunctor t+ , Show (t f a)+ , Eq (t f a)+ , Show (t (t f) a)+ , Show (t (t (t f)) a)+ , TestHFunctorBy t f+ , TestHFunctorBy t (t f)+ , TestHFunctorBy t (t (t f))+ ) =>+ Gen (f a) ->+ [TestTree]+hbindProps_ gx =+ [ hfunctorProps @t gx+ , hbindProps @t gx+ ] +interpretProps_ ::+ forall t f a.+ ( Interpret t f+ , TestHFunctor t+ , Show (f a)+ , Eq (f a)+ , Show (t f a)+ , Eq (t f a)+ , TestHFunctorBy t f+ ) =>+ Gen (f a) ->+ [TestTree]+interpretProps_ gx =+ [ hfunctorProps @t gx+ , interpretProps @t gx+ ] -bindInterpProps_- :: forall t f a.- ( HBind t- , Interpret t f- , TestHFunctor t- , Show (f a) , Eq (f a)- , Show (t f a) , Eq (t f a)- , Show (t (t f) a)- , Show (t (t (t f)) a)- , TestHFunctorBy t (t (t f))- , TestHFunctorBy t (t f)- , TestHFunctorBy t f- )- => Gen (f a)- -> [TestTree]-bindInterpProps_ gx = [ hfunctorProps @t gx- , hbindProps @t gx- , interpretProps @t gx- ]+bindInterpProps_ ::+ forall t f a.+ ( HBind t+ , Interpret t f+ , TestHFunctor t+ , Show (f a)+ , Eq (f a)+ , Show (t f a)+ , Eq (t f a)+ , Show (t (t f) a)+ , Show (t (t (t f)) a)+ , TestHFunctorBy t (t (t f))+ , TestHFunctorBy t (t f)+ , TestHFunctorBy t f+ ) =>+ Gen (f a) ->+ [TestTree]+bindInterpProps_ gx =+ [ hfunctorProps @t gx+ , hbindProps @t gx+ , interpretProps @t gx+ ] hfunctorTests :: TestTree-hfunctorTests = testGroup "HFunctors"- [ testGroup "Ap" $ bindInterpProps_ @Ap (Const . S.Sum <$> intGen)- , testGroup "Ap'" $ bindInterpProps_ @FA.Ap (Const . S.Sum <$> intGen)+hfunctorTests =+ testGroup+ "HFunctors"+ [ testGroup "Ap" $ bindInterpProps_ @Ap @_ @Void (Const . S.Sum <$> intGen)+ , testGroup "Ap'" $ bindInterpProps_ @FA.Ap (Const . S.Sum <$> intGen) , testGroup "Ap''" $ bindInterpProps_ @FAF.Ap (Const . S.Sum <$> intGen)- -- , testGroup "Alt" $ bindInterpProps_ @Alt (Const . S.Sum <$> intGen) -- TODO- , testGroup "Coyoneda" $ bindInterpProps_ @Coyoneda listGen+ , -- , testGroup "Alt" $ bindInterpProps_ @Alt (Const . S.Sum <$> intGen) -- TODO+ testGroup "Coyoneda" $ bindInterpProps_ @Coyoneda listGen , testGroup "WrappedApplicative" $ bindInterpProps_ @WrappedApplicative listGen , testGroup "MaybeApply" $ bindInterpProps_ @MaybeApply listGen- , testGroup "Lift" $ bindInterpProps_ @Lift listGen- , testGroup "ListF" $ bindInterpProps_ @ListF (Gen.list (Range.linear 0 3) intGen)- , testGroup "NonEmptyF" $ bindInterpProps_ @NonEmptyF (Gen.list (Range.linear 0 3) intGen)- , testGroup "MaybeF" $ bindInterpProps_ @MaybeF listGen- , testGroup "MapF" $ interpretProps_ @(MapF Ordering) (Gen.list (Range.linear 0 3) intGen)- , testGroup "NEMapF" $ interpretProps_ @(NEMapF Ordering) (Gen.list (Range.linear 0 3) intGen)- , testGroup "Free1" $ bindInterpProps_ @Free1 (Gen.list (Range.linear 0 3) intGen)- , testGroup "Free" $ bindInterpProps_ @Free (Gen.list (Range.linear 0 3) intGen)- , testGroup "Ap1" $ bindInterpProps_ @Ap1 (Const . S.Sum <$> intGen)- , testGroup "EnvT" $ bindInterpProps_ @(EnvT Ordering) listGen- , testGroup "IdentityT" $ bindInterpProps_ @IdentityT listGen- -- , testGroup "ReaderT" [ hfunctorProps @(ReaderT Int) listGen ] -- no Show- , testGroup "These1" $ bindInterpProps_ @(These1 []) listGen- , testGroup "Reverse" $ bindInterpProps_ @Reverse listGen- , testGroup "Backwards" $ bindInterpProps_ @Backwards listGen- , testGroup "Comp" [ hfunctorProps @(Comp []) (Gen.list (Range.linear 0 3) intGen) ]- , testGroup "Comp'" [ hfunctorProps @((:*:) []) (Gen.list (Range.linear 0 3) intGen) ]- , testGroup "Step" $ bindInterpProps_ @Step listGen- , testGroup "Steps" $ interpretProps_ @Steps listGen- , testGroup "Flagged" $ bindInterpProps_ @Flagged listGen- , testGroup "M1" $ bindInterpProps_ @(M1 () ('MetaData "" "" "" 'True)) listGen- , testGroup "Product" $ bindInterpProps_ @((:*:) []) listGen- , testGroup "Product'" $ bindInterpProps_ @(Product []) listGen- , testGroup "Sum" $ bindInterpProps_ @((:+:) []) listGen- , testGroup "Sum'" $ bindInterpProps_ @(Sum []) listGen- , testGroup "ProxyF" $ hbindProps_ @ProxyF listGen- , testGroup "RightF" $ hbindProps_ @(RightF []) listGen+ , testGroup "Lift" $ bindInterpProps_ @Lift listGen+ , testGroup "ListF" $ bindInterpProps_ @ListF (Gen.list (Range.linear 0 3) intGen)+ , testGroup "NonEmptyF" $ bindInterpProps_ @NonEmptyF (Gen.list (Range.linear 0 3) intGen)+ , testGroup "MaybeF" $ bindInterpProps_ @MaybeF listGen+ , testGroup "MapF" $ interpretProps_ @(MapF Ordering) (Gen.list (Range.linear 0 3) intGen)+ , testGroup "NEMapF" $ interpretProps_ @(NEMapF Ordering) (Gen.list (Range.linear 0 3) intGen)+ , testGroup "Free1" $ bindInterpProps_ @Free1 (Gen.list (Range.linear 0 3) intGen)+ , testGroup "Free" $ bindInterpProps_ @Free (Gen.list (Range.linear 0 3) intGen)+ , testGroup "Ap1" $ bindInterpProps_ @Ap1 (Const . S.Sum <$> intGen)+ , testGroup "EnvT" $ bindInterpProps_ @(EnvT Ordering) listGen+ , testGroup "IdentityT" $ bindInterpProps_ @IdentityT listGen+ , -- , testGroup "ReaderT" [ hfunctorProps @(ReaderT Int) listGen ] -- no Show+ testGroup "These1" $ bindInterpProps_ @(These1 []) listGen+ , testGroup "Reverse" $ bindInterpProps_ @Reverse listGen+ , testGroup "Backwards" $ bindInterpProps_ @Backwards listGen+ , testGroup "Comp" [hfunctorProps @(Comp []) (Gen.list (Range.linear 0 3) intGen)]+ , testGroup "Comp'" [hfunctorProps @((:*:) []) (Gen.list (Range.linear 0 3) intGen)]+ , testGroup "Step" $ bindInterpProps_ @Step listGen+ , testGroup "Steps" $ interpretProps_ @Steps listGen+ , testGroup "Flagged" $ bindInterpProps_ @Flagged listGen+ , testGroup "M1" $ bindInterpProps_ @(M1 () ('MetaData "" "" "" 'True)) listGen+ , testGroup "Product" $ bindInterpProps_ @((:*:) []) listGen+ , testGroup "Product'" $ bindInterpProps_ @(Product []) listGen+ , testGroup "Sum" $ bindInterpProps_ @((:+:) []) listGen+ , testGroup "Sum'" $ bindInterpProps_ @(Sum []) listGen+ , testGroup "ProxyF" $ hbindProps_ @ProxyF listGen+ , testGroup "RightF" $ hbindProps_ @(RightF []) listGen ]
test/Tests/Util.hs view
@@ -1,65 +1,66 @@-{-# OPTIONS_GHC -Wno-orphans #-}+{-# LANGUAGE CPP #-}+{-# OPTIONS_GHC -Wno-orphans #-} module Tests.Util (- isoProp- , sumGen- , intGen- , listGen- , TestHFunctor(..)- , TestHBifunctor(..)- ) where+ isoProp,+ sumGen,+ intGen,+ listGen,+ TestHFunctor (..),+ TestHBifunctor (..),+) where -import Control.Applicative-import Control.Applicative.Backwards-import Control.Applicative.Lift-import Control.Monad.Freer.Church-import Control.Natural.IsoF-import Data.Bifunctor.Joker-import Data.Constraint.Trivial-import Data.Function-import Data.Functor-import Data.Functor.Bind-import Data.Functor.Classes-import Data.Functor.Combinator-import Data.Functor.Identity-import Data.Functor.Plus-import Data.Functor.Product-import Data.Functor.Reverse-import Data.Functor.Sum-import Data.GADT.Show-import Data.HBifunctor.Tensor-import Data.HFunctor.Chain-import Data.HFunctor.Interpret-import Data.Kind-import Data.Semigroup (Any(..))-import Data.Semigroup.Traversable-import GHC.Generics (M1(..))-import Hedgehog hiding (HTraversable(..))-import qualified Control.Applicative.Free as Ap-import qualified Control.Applicative.Free.Fast as FAF+import Control.Applicative+import Control.Applicative.Backwards+import qualified Control.Applicative.Free as Ap+import qualified Control.Applicative.Free.Fast as FAF import qualified Control.Applicative.Free.Final as FA-import qualified Data.List.NonEmpty as NE-import qualified Data.Map.NonEmpty as NEM-import qualified Hedgehog.Gen as Gen-import qualified Hedgehog.Range as Range-+import Control.Applicative.Lift+import Control.Monad.Freer.Church+import Control.Natural.IsoF+import Data.Bifunctor.Joker+import Data.Constraint.Trivial+import Data.Function+import Data.Functor+import Data.Functor.Bind+import Data.Functor.Classes+import Data.Functor.Combinator+import Data.Functor.Identity+import Data.Functor.Plus+import Data.Functor.Product+import Data.Functor.Reverse+import Data.Functor.Sum+import Data.GADT.Show+import Data.HBifunctor.Tensor+import Data.HFunctor.Chain+import Data.HFunctor.Interpret+import Data.Kind+import qualified Data.List.NonEmpty as NE+import qualified Data.Map.NonEmpty as NEM+import Data.Semigroup (Any (..))+import Data.Semigroup.Traversable+import GHC.Generics (M1 (..))+import Hedgehog hiding (HTraversable (..))+import qualified Hedgehog.Gen as Gen+import qualified Hedgehog.Range as Range -isoProp- :: (Show (f a), Show (g a), Eq (f a), Eq (g a), Monad m)- => (f <~> g)- -> Gen (f a)- -> Gen (g a)- -> PropertyT m ()+isoProp ::+ (Show (f a), Show (g a), Eq (f a), Eq (g a), Monad m) =>+ (f <~> g) ->+ Gen (f a) ->+ Gen (g a) ->+ PropertyT m () isoProp i gx gy = do- x <- forAll gx- tripping x (viewF i) (Just . reviewF i)- y <- forAll gy- tripping y (reviewF i) (Just . viewF i)+ x <- forAll gx+ tripping x (viewF i) (Just . reviewF i)+ y <- forAll gy+ tripping y (reviewF i) (Just . viewF i) sumGen :: MonadGen m => m (f a) -> m (g a) -> m ((f :+: g) a)-sumGen gx gy = Gen.bool >>= \case+sumGen gx gy =+ Gen.bool >>= \case False -> L1 <$> gx- True -> R1 <$> gy+ True -> R1 <$> gy intGen :: MonadGen m => m Int intGen = Gen.integral (Range.linear 0 100)@@ -68,248 +69,268 @@ listGen = Gen.list (Range.linear 0 100) intGen instance (GShow f, GShow g) => Eq (Day f g a) where- (==) = (==) `on` show+ (==) = (==) `on` show instance Show c => GShow (Const c) where- gshowsPrec = showsPrec+ gshowsPrec = showsPrec instance (GShow f, GShow g) => GShow (Day f g) where- gshowsPrec d (Day x y _) =- showsBinaryWith gshowsPrec gshowsPrec "Day" d x y+ gshowsPrec d (Day x y _) =+ showsBinaryWith gshowsPrec gshowsPrec "Day" d x y instance (GShow f, GShow (t f (Chain1 t f))) => GShow (Chain1 t f) where- gshowsPrec d = \case- Done1 x -> gshowsPrec d x- More1 xs -> gshowsPrec d xs+ gshowsPrec d = \case+ Done1 x -> gshowsPrec d x+ More1 xs -> gshowsPrec d xs instance GShow Identity where- gshowsPrec _ _ = showString "<Identity>"+ gshowsPrec _ _ = showString "<Identity>" instance (GShow i, GShow (t f (Chain t i f))) => GShow (Chain t i f) where- gshowsPrec d = \case- Done x -> gshowsPrec d x- More xs -> gshowsPrec d xs+ gshowsPrec d = \case+ Done x -> gshowsPrec d x+ More xs -> gshowsPrec d xs instance (GShow f, GShow g) => Show (Day f g a) where- showsPrec = gshowsPrec+ showsPrec = gshowsPrec instance (GShow f, Functor f) => GShow (Ap1 f) where- gshowsPrec d (Ap1 x y) = case matchLB @Day y of- L1 _ -> showsUnaryWith gshowsPrec "inject" d x- R1 ys -> showsBinaryWith gshowsPrec gshowsPrec "Ap1" d x ys+ gshowsPrec d (Ap1 x y) = case matchLB @Day y of+ L1 _ -> showsUnaryWith gshowsPrec "inject" d x+ R1 ys -> showsBinaryWith gshowsPrec gshowsPrec "Ap1" d x ys instance (GShow f, Functor f) => Eq (Ap1 f a) where- (==) = (==) `on` show+ (==) = (==) `on` show instance (GShow f, Functor f) => Show (Ap1 f a) where- showsPrec = gshowsPrec+ showsPrec = gshowsPrec instance GShow f => GShow (Ap f) where- gshowsPrec d = \case- Ap.Pure _ -> showString "<pure>"- Ap.Ap x xs -> showsBinaryWith gshowsPrec gshowsPrec "Ap" d x xs+ gshowsPrec d = \case+ Ap.Pure _ -> showString "<pure>"+ Ap.Ap x xs -> showsBinaryWith gshowsPrec gshowsPrec "Ap" d x xs instance GShow f => GShow (FA.Ap f) where- gshowsPrec d = gshowsPrec d . FA.runAp Ap.liftAp+ gshowsPrec d = gshowsPrec d . FA.runAp Ap.liftAp instance GShow f => GShow (FAF.Ap f) where- gshowsPrec d = gshowsPrec d . FAF.runAp Ap.liftAp+ gshowsPrec d = gshowsPrec d . FAF.runAp Ap.liftAp instance GShow f => Show (Ap f a) where- showsPrec = gshowsPrec+ showsPrec = gshowsPrec instance GShow f => Show (FA.Ap f a) where- showsPrec = gshowsPrec+ showsPrec = gshowsPrec instance GShow f => Show (FAF.Ap f a) where- showsPrec = gshowsPrec+ showsPrec = gshowsPrec +#if !MIN_VERSION_free(5,2,0) instance GShow f => Eq (Ap f a) where (==) = (==) `on` show+#endif instance GShow f => Eq (FA.Ap f a) where- (==) = (==) `on` show+ (==) = (==) `on` show instance GShow f => Eq (FAF.Ap f a) where- (==) = (==) `on` show+ (==) = (==) `on` show deriving instance (Show e, Show (f a)) => Show (EnvT e f a) deriving instance (Eq e, Eq (f a)) => Eq (EnvT e f a) instance (Show e, Show1 f) => Show1 (EnvT e f) where- liftShowsPrec sp sl d (EnvT e x) =- showsBinaryWith showsPrec (liftShowsPrec sp sl) "EnvT" d e x+ liftShowsPrec sp sl d (EnvT e x) =+ showsBinaryWith showsPrec (liftShowsPrec sp sl) "EnvT" d e x instance (Eq e, Eq1 f) => Eq1 (EnvT e f) where- liftEq eq (EnvT e x) (EnvT d y) = e == d && liftEq eq x y+ liftEq eq (EnvT e x) (EnvT d y) = e == d && liftEq eq x y instance Show1 (s (t f)) => Show1 (ComposeT s t f) where- liftShowsPrec sp sl d (ComposeT x) =- showsUnaryWith (liftShowsPrec sp sl) "ComposeT" d x+ liftShowsPrec sp sl d (ComposeT x) =+ showsUnaryWith (liftShowsPrec sp sl) "ComposeT" d x instance Eq1 (s (t f)) => Eq1 (ComposeT s t f) where- liftEq eq (ComposeT x) (ComposeT y) = liftEq eq x y+ liftEq eq (ComposeT x) (ComposeT y) = liftEq eq x y instance Enum Any where- toEnum = Any . toEnum- fromEnum = fromEnum . getAny+ toEnum = Any . toEnum+ fromEnum = fromEnum . getAny +#if !MIN_VERSION_base(0,9,2) instance Show1 V1 where liftShowsPrec _ _ _ = \case {} instance Eq1 V1 where liftEq _ = \case {}+#endif class HFunctor t => TestHFunctor t where- type TestHFunctorBy t :: (Type -> Type) -> Constraint- type TestHFunctorBy t = Unconstrained- genHF- :: (MonadGen m, TestHFunctorBy t f)- => m (f a)- -> m (t f a)-- default genHF :: (Inject t, MonadGen m) => m (f a) -> m (t f a)- genHF = fmap inject+ type TestHFunctorBy t :: (Type -> Type) -> Constraint+ type TestHFunctorBy t = Unconstrained+ genHF ::+ (MonadGen m, TestHFunctorBy t f) =>+ m (f a) ->+ m (t f a)+ default genHF :: (Inject t, MonadGen m) => m (f a) -> m (t f a)+ genHF = fmap inject instance TestHFunctor Step where- genHF gx = Step <$> Gen.integral (Range.linear 0 25) <*> gx+ genHF gx = Step <$> Gen.integral (Range.linear 0 25) <*> gx instance TestHFunctor ListF where- genHF gx = ListF <$> Gen.list (Range.linear 0 25) gx+ genHF gx = ListF <$> Gen.list (Range.linear 0 25) gx instance TestHFunctor NonEmptyF where- genHF gx = NonEmptyF <$> Gen.nonEmpty (Range.linear 1 25) gx+ genHF gx = NonEmptyF <$> Gen.nonEmpty (Range.linear 1 25) gx instance (Enum k, Bounded k, Ord k) => TestHFunctor (MapF k) where- genHF gx = MapF <$> Gen.map (Range.linear 0 10) kv- where- kv = (,) <$> Gen.enumBounded- <*> gx+ genHF gx = MapF <$> Gen.map (Range.linear 0 10) kv+ where+ kv =+ (,)+ <$> Gen.enumBounded+ <*> gx instance (Enum k, Bounded k, Ord k) => TestHFunctor (NEMapF k) where- genHF gx = do- mp <- Gen.map (Range.linear 0 10) kv- (k, v) <- kv- pure . NEMapF $ NEM.insertMap k v mp- where- kv = (,) <$> Gen.enumBounded- <*> gx+ genHF gx = do+ mp <- Gen.map (Range.linear 0 10) kv+ (k, v) <- kv+ pure . NEMapF $ NEM.insertMap k v mp+ where+ kv =+ (,)+ <$> Gen.enumBounded+ <*> gx instance TestHFunctor Steps where- genHF gx = do- mp <- Gen.map (Range.linear 0 10) kv- (k, v) <- kv- pure . Steps $ NEM.insertMap k v mp- where- kv = (,) <$> Gen.integral (Range.linear 0 25)- <*> gx+ genHF gx = do+ mp <- Gen.map (Range.linear 0 10) kv+ (k, v) <- kv+ pure . Steps $ NEM.insertMap k v mp+ where+ kv =+ (,)+ <$> Gen.integral (Range.linear 0 25)+ <*> gx instance TestHFunctor Ap where- genHF gx = fmap NE.last- . sequence1- . fmap inject- <$> Gen.nonEmpty (Range.linear 0 3) gx+ genHF gx =+ fmap NE.last+ . sequence1+ . fmap inject+ <$> Gen.nonEmpty (Range.linear 0 3) gx instance TestHFunctor FA.Ap where- genHF gx = fmap NE.last- . sequence1- . fmap inject- <$> Gen.nonEmpty (Range.linear 0 3) gx+ genHF gx =+ fmap NE.last+ . sequence1+ . fmap inject+ <$> Gen.nonEmpty (Range.linear 0 3) gx instance TestHFunctor FAF.Ap where- genHF gx = fmap NE.last- . sequence1- . fmap inject- <$> Gen.nonEmpty (Range.linear 0 3) gx+ genHF gx =+ fmap NE.last+ . sequence1+ . fmap inject+ <$> Gen.nonEmpty (Range.linear 0 3) gx instance TestHFunctor Ap1 where- genHF gx = fmap NE.last- . sequence1- . fmap inject- <$> Gen.nonEmpty (Range.linear 1 3) gx+ genHF gx =+ fmap NE.last+ . sequence1+ . fmap inject+ <$> Gen.nonEmpty (Range.linear 1 3) gx instance TestHFunctor Free where- genHF gx = fmap NE.last- . sequence- . fmap inject- <$> Gen.nonEmpty (Range.linear 0 3) gx+ genHF gx =+ fmap NE.last+ . traverse inject+ <$> Gen.nonEmpty (Range.linear 0 3) gx instance TestHFunctor Free1 where- genHF gx = fmap NE.last- . sequence1- . fmap inject- <$> Gen.nonEmpty (Range.linear 1 3) gx+ genHF gx =+ fmap NE.last+ . sequence1+ . fmap inject+ <$> Gen.nonEmpty (Range.linear 1 3) gx instance TestHFunctor t => TestHFunctor (HLift t) where- type TestHFunctorBy (HLift t) = TestHFunctorBy t- genHF gx = Gen.bool >>= \case- False -> HPure <$> gx- True -> HOther <$> genHF gx+ type TestHFunctorBy (HLift t) = TestHFunctorBy t+ genHF gx =+ Gen.bool >>= \case+ False -> HPure <$> gx+ True -> HOther <$> genHF gx instance (Enum e, Bounded e) => TestHFunctor (EnvT e) where- genHF gx = EnvT <$> Gen.enumBounded <*> gx+ genHF gx = EnvT <$> Gen.enumBounded <*> gx instance (TestHFunctor s, HTraversable s, TestHFunctor t) => TestHFunctor (ComposeT s t) where- type TestHFunctorBy (ComposeT s t) = AndC (TestHFunctorBy s) (TestHFunctorBy t)- genHF gx = fmap ComposeT- . htraverse (genHF @t . pure)- =<< genHF @s gx+ type TestHFunctorBy (ComposeT s t) = AndC (TestHFunctorBy s) (TestHFunctorBy t)+ genHF gx =+ fmap ComposeT+ . htraverse (genHF @t . pure)+ =<< genHF @s gx instance TestHFunctor Flagged where- genHF gx = Flagged <$> Gen.bool <*> gx+ genHF gx = Flagged <$> Gen.bool <*> gx class HBifunctor t => TestHBifunctor t where- genHB- :: MonadGen m- => m (f a)- -> m (g a)- -> m (t f g a)+ genHB ::+ MonadGen m =>+ m (f a) ->+ m (g a) ->+ m (t f g a) instance TestHBifunctor (:+:) where- genHB = sumGen+ genHB = sumGen instance TestHBifunctor Sum where- genHB gx gy = sumGen gx gy <&> \case+ genHB gx gy =+ sumGen gx gy <&> \case L1 x -> InL x R1 y -> InR y instance TestHBifunctor (:*:) where- genHB gx gy = (:*:) <$> gx <*> gy+ genHB gx gy = (:*:) <$> gx <*> gy instance TestHBifunctor Product where- genHB gx gy = Pair <$> gx <*> gy+ genHB gx gy = Pair <$> gx <*> gy instance TestHBifunctor Day where- genHB gx gy = do- f <- Gen.bool <&> \case+ genHB gx gy = do+ f <-+ Gen.bool <&> \case False -> const- True -> flip const- Day <$> gx <*> gy <*> pure f+ True -> const id+ Day <$> gx <*> gy <*> pure f instance TestHBifunctor These1 where- genHB gx gy = Gen.enumBounded >>= \case+ genHB gx gy =+ Gen.enumBounded >>= \case LT -> This1 <$> gx EQ -> That1 <$> gy GT -> These1 <$> gx <*> gy instance TestHBifunctor Comp where- genHB gx gy = (:>>=) <$> gx <*> fmap const gy+ genHB gx gy = (:>>=) <$> gx <*> fmap const gy instance TestHBifunctor LeftF where- genHB gx _ = LeftF <$> gx+ genHB gx _ = LeftF <$> gx instance TestHBifunctor Joker where- genHB gx _ = Joker <$> gx+ genHB gx _ = Joker <$> gx instance TestHBifunctor RightF where- genHB _ gy = RightF <$> gy+ genHB _ gy = RightF <$> gy instance TestHBifunctor t => TestHFunctor (Chain1 t) where- genHF x = go- where- go = Gen.bool >>= \case+ genHF x = go+ where+ go =+ Gen.bool >>= \case False -> Done1 <$> x- True -> More1 <$> genHB x go+ True -> More1 <$> genHB x go deriving instance Eq (f a) => Eq (WrappedApplicative f a) deriving instance Show (f a) => Show (WrappedApplicative f a)@@ -327,11 +348,12 @@ instance TestHFunctor (These1 f) instance TestHFunctor MaybeF where- genHF gx = Gen.bool >>= \case+ genHF gx =+ Gen.bool >>= \case False -> pure $ MaybeF Nothing- True -> MaybeF . Just <$> gx+ True -> MaybeF . Just <$> gx -instance TestHFunctor IdentityT where+instance TestHFunctor IdentityT instance TestHFunctor Coyoneda instance TestHFunctor WrappedApplicative instance TestHFunctor Reverse