{-# LANGUAGE CPP #-}

#if !(MIN_VERSION_base(4,16,0)) || !(MIN_VERSION_transformers(0,6,0))
{-# OPTIONS_GHC -fno-warn-deprecations #-}
#endif

#define GHC_GENERICS_OK __GLASGOW_HASKELL__ >= 702

#if GHC_GENERICS_OK
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
#endif

#if __GLASGOW_HASKELL__ >= 706
{-# LANGUAGE PolyKinds #-}
#endif

{-|
Module:      Data.Functor.Invariant
Copyright:   (C) 2012-2017 Nicolas Frisby, (C) 2015-2017 Ryan Scott
License:     BSD-style (see the file LICENSE)
Maintainer:  Ryan Scott
Portability: Portable

Haskell98 invariant functors (also known as exponential functors).

For more information, see Edward Kmett's article \"Rotten Bananas\":

<http://comonad.com/reader/2008/rotten-bananas/>

-}
module Data.Functor.Invariant
  ( -- * @Invariant@
    Invariant(..)
  , invmapFunctor
#if GHC_GENERICS_OK
    -- ** @GHC.Generics@
    -- $ghcgenerics
  , genericInvmap
#endif
  , WrappedFunctor(..)
  , invmapContravariant
  , invmapProfunctor
  , invmapArrow
  , WrappedContravariant(..)
  , InvariantProfunctor(..)
  , InvariantArrow(..)
    -- * @Invariant2@
  , Invariant2(..)
  , invmap2Bifunctor
  , WrappedBifunctor(..)
  , invmap2Profunctor
  , WrappedProfunctor(..)
  ) where

-- base
import           Control.Applicative as App
import qualified Control.Arrow as Arr
import           Control.Arrow hiding (first, second)
import qualified Control.Category as Cat
import           Control.Exception (Handler(..))
import           Control.Monad (MonadPlus(..), liftM)
import qualified Control.Monad.ST as Strict (ST)
import qualified Control.Monad.ST.Lazy as Lazy (ST)
#if MIN_VERSION_base(4,4,0)
import           Data.Complex (Complex(..))
#endif
import qualified Data.Foldable as F (Foldable(..))
import qualified Data.Functor.Compose as Functor (Compose(..))
import           Data.Functor.Identity (Identity)
import           Data.Functor.Product as Functor (Product(..))
import           Data.Functor.Sum as Functor (Sum(..))
#if __GLASGOW_HASKELL__ < 711
import           Data.Ix (Ix)
#endif
import           Data.List.NonEmpty (NonEmpty(..))
import qualified Data.Monoid as Monoid (First(..), Last(..), Product(..), Sum(..))
#if MIN_VERSION_base(4,8,0)
import           Data.Monoid (Alt(..))
#endif
import           Data.Monoid (Dual(..), Endo(..))
import           Data.Proxy (Proxy(..))
import qualified Data.Semigroup as Semigroup (First(..), Last(..))
#if !(MIN_VERSION_base(4,16,0))
import qualified Data.Semigroup as Semigroup (Option(..))
#endif
import           Data.Semigroup (Min(..), Max(..), Arg(..))
import qualified Data.Traversable as T (Traversable(..))
#if GHC_GENERICS_OK
import           GHC.Generics
#endif
import           System.Console.GetOpt as GetOpt
import           Text.ParserCombinators.ReadP (ReadP)
import           Text.ParserCombinators.ReadPrec (ReadPrec)

-- array
import           Data.Array (Array)

-- bifunctors
import           Data.Bifunctor
import           Data.Bifunctor.Biff
import           Data.Bifunctor.Clown
import           Data.Bifunctor.Fix
import           Data.Bifunctor.Flip
import           Data.Bifunctor.Join
import           Data.Bifunctor.Joker
import qualified Data.Bifunctor.Product as Bifunctor
import qualified Data.Bifunctor.Sum as Bifunctor
import           Data.Bifunctor.Tannen
import           Data.Bifunctor.Wrapped

-- comonad
import           Control.Comonad (Cokleisli(..))

-- containers
import           Data.IntMap (IntMap)
import           Data.Map (Map)
import           Data.Sequence (Seq, ViewL, ViewR)
import           Data.Tree (Tree)

-- contravariant
import           Data.Functor.Contravariant
import           Data.Functor.Contravariant.Compose as Contravariant
import           Data.Functor.Contravariant.Divisible

-- profunctors
import           Data.Profunctor as Pro
import           Data.Profunctor.Cayley
import           Data.Profunctor.Choice
import           Data.Profunctor.Closed
import           Data.Profunctor.Composition
import           Data.Profunctor.Mapping
import           Data.Profunctor.Monad
import           Data.Profunctor.Rep
import           Data.Profunctor.Ran
import           Data.Profunctor.Strong
import           Data.Profunctor.Traversing
import           Data.Profunctor.Unsafe
import           Data.Profunctor.Yoneda

-- StateVar
import           Data.StateVar (StateVar(..), SettableStateVar(..))

-- stm
import           Control.Concurrent.STM (STM)

-- tagged
import           Data.Tagged (Tagged(..))

-- transformers
import           Control.Applicative.Backwards (Backwards(..))
import           Control.Applicative.Lift (Lift(..))
import           Control.Monad.Trans.Cont (ContT)
import           Control.Monad.Trans.Except (ExceptT(..), runExceptT)
import           Control.Monad.Trans.Identity (IdentityT, mapIdentityT)
import           Control.Monad.Trans.Maybe (MaybeT, mapMaybeT)
import qualified Control.Monad.Trans.RWS.Lazy as Lazy (RWST(..))
import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST(..))
import           Control.Monad.Trans.Reader (ReaderT, mapReaderT)
import qualified Control.Monad.Trans.State.Lazy as Lazy (StateT(..))
import qualified Control.Monad.Trans.State.Strict as Strict (StateT(..))
import qualified Control.Monad.Trans.Writer.Lazy as Lazy (WriterT, mapWriterT)
import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT, mapWriterT)
#if !(MIN_VERSION_transformers(0,6,0))
import           Control.Monad.Trans.Error (ErrorT(..))
import           Control.Monad.Trans.List (ListT, mapListT)
#endif
import           Data.Functor.Constant (Constant(..))
import           Data.Functor.Reverse (Reverse(..))

-- unordered-containers
import           Data.HashMap.Lazy (HashMap)

-------------------------------------------------------------------------------
-- The Invariant class
-------------------------------------------------------------------------------

-- | Any @* -> *@ type parametric in the argument permits an instance of
-- @Invariant@.
--
-- Instances should satisfy the following laws:
--
-- > invmap id id = id
-- > invmap f2 f2' . invmap f1 f1' = invmap (f2 . f1) (f1' . f2')
class Invariant f where
  invmap :: (a -> b) -> (b -> a) -> f a -> f b
#if GHC_GENERICS_OK
  default invmap :: (Generic1 f, Invariant (Rep1 f)) => (a -> b) -> (b -> a) -> f a -> f b
  invmap = forall (f :: * -> *) a b.
(Generic1 f, Invariant (Rep1 f)) =>
(a -> b) -> (b -> a) -> f a -> f b
genericInvmap
#endif

-- | Every 'Functor' is also an 'Invariant' functor.
invmapFunctor :: Functor f => (a -> b) -> (b -> a) -> f a -> f b
invmapFunctor :: forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> a
const forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

-- | Every 'Contravariant' functor is also an 'Invariant' functor.
invmapContravariant :: Contravariant f => (a -> b) -> (b -> a) -> f a -> f b
invmapContravariant :: forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant = forall a b. a -> b -> a
const forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap

-- | A 'Profunctor' with the same input and output types can be seen as an 'Invariant' functor.
invmapProfunctor :: Profunctor p => (a -> b) -> (b -> a) -> p a a -> p b b
invmapProfunctor :: forall (p :: * -> * -> *) a b.
Profunctor p =>
(a -> b) -> (b -> a) -> p a a -> p b b
invmapProfunctor = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap

-- | An 'Arrow' with the same input and output types can be seen as an 'Invariant' functor.
invmapArrow :: Arrow arr => (a -> b) -> (b -> a) -> arr a a -> arr b b
invmapArrow :: forall (arr :: * -> * -> *) a b.
Arrow arr =>
(a -> b) -> (b -> a) -> arr a a -> arr b b
invmapArrow a -> b
fn1 b -> a
fn2 arr a a
arrow = forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr a -> b
fn1 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. arr a a
arrow forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr b -> a
fn2

-------------------------------------------------------------------------------
-- Invariant instances
-------------------------------------------------------------------------------

instance Invariant Maybe where invmap :: forall a b. (a -> b) -> (b -> a) -> Maybe a -> Maybe b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant [] where invmap :: forall a b. (a -> b) -> (b -> a) -> [a] -> [b]
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant IO where invmap :: forall a b. (a -> b) -> (b -> a) -> IO a -> IO b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant (Strict.ST s) where invmap :: forall a b. (a -> b) -> (b -> a) -> ST s a -> ST s b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant (Lazy.ST s) where invmap :: forall a b. (a -> b) -> (b -> a) -> ST s a -> ST s b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ReadP where invmap :: forall a b. (a -> b) -> (b -> a) -> ReadP a -> ReadP b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ReadPrec where invmap :: forall a b. (a -> b) -> (b -> a) -> ReadPrec a -> ReadPrec b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ((->) a) where invmap :: forall a b. (a -> b) -> (b -> a) -> (a -> a) -> a -> b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant (Either a) where invmap :: forall a b. (a -> b) -> (b -> a) -> Either a a -> Either a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ((,) a) where invmap :: forall a b. (a -> b) -> (b -> a) -> (a, a) -> (a, b)
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ((,,) a b) where invmap :: forall a b. (a -> b) -> (b -> a) -> (a, b, a) -> (a, b, b)
invmap a -> b
f b -> a
_ ~(a
a, b
b, a
x) = (a
a, b
b, a -> b
f a
x)
instance Invariant ((,,,) a b c) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> (a, b, c, a) -> (a, b, c, b)
invmap a -> b
f b -> a
_ ~(a
a, b
b, c
c, a
x) = (a
a, b
b, c
c, a -> b
f a
x)
instance Invariant ((,,,,) a b c d) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> (a, b, c, d, a) -> (a, b, c, d, b)
invmap a -> b
f b -> a
_ ~(a
a, b
b, c
c, d
d, a
x) = (a
a, b
b, c
c, d
d, a -> b
f a
x)

-- | from "Control.Applicative"
instance Invariant (Const a) where invmap :: forall a b. (a -> b) -> (b -> a) -> Const a a -> Const a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Control.Applicative"
instance Invariant ZipList where invmap :: forall a b. (a -> b) -> (b -> a) -> ZipList a -> ZipList b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Control.Applicative"
instance Monad m => Invariant (WrappedMonad m) where invmap :: forall a b.
(a -> b) -> (b -> a) -> WrappedMonad m a -> WrappedMonad m b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Control.Applicative"
instance Arrow arr => Invariant (App.WrappedArrow arr a) where
  invmap :: forall a b.
(a -> b)
-> (b -> a) -> WrappedArrow arr a a -> WrappedArrow arr a b
invmap a -> b
f b -> a
_ (App.WrapArrow arr a a
x) = forall (a :: * -> * -> *) b c. a b c -> WrappedArrow a b c
App.WrapArrow forall a b. (a -> b) -> a -> b
$ ((forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr a -> b
f) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. arr a a
x)

-- | from "Control.Arrow"
instance
#if MIN_VERSION_base(4,4,0)
  Arrow a
#else
  ArrowApply a
#endif
  => Invariant (ArrowMonad a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> ArrowMonad a a -> ArrowMonad a b
invmap a -> b
f b -> a
_ (ArrowMonad a () a
m) = forall (a :: * -> * -> *) b. a () b -> ArrowMonad a b
ArrowMonad (a () a
m forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr a -> b
f)
-- | from "Control.Arrow"
instance Invariant m => Invariant (Kleisli m a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Kleisli m a a -> Kleisli m a b
invmap a -> b
f b -> a
g (Kleisli a -> m a
m) = forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Kleisli (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m a
m)

-- | from "Control.Exception"
instance Invariant Handler where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Handler a -> Handler b
invmap a -> b
f b -> a
_ (Handler e -> IO a
h) = forall a e. Exception e => (e -> IO a) -> Handler a
Handler (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> IO a
h)

#if MIN_VERSION_base(4,4,0)
-- | from "Data.Complex"
instance Invariant Complex where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Complex a -> Complex b
invmap a -> b
f b -> a
_ (a
r :+ a
i) = a -> b
f a
r forall a. a -> a -> Complex a
:+ a -> b
f a
i
#endif

-- | from "Data.Functor.Compose"
instance (Invariant f, Invariant g) => Invariant (Functor.Compose f g) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Compose f g a -> Compose f g b
invmap a -> b
f b -> a
g (Functor.Compose f (g a)
x) =
    forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Functor.Compose (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) f (g a)
x)

-- | from "Data.Functor.Identity"
instance Invariant Identity where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Identity a -> Identity b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from "Data.Functor.Product"
instance (Invariant f, Invariant g) => Invariant (Functor.Product f g) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Product f g a -> Product f g b
invmap a -> b
f b -> a
g (Functor.Pair f a
x g a
y) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Functor.Pair (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
x) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g g a
y)

-- | from "Data.Functor.Sum"
instance (Invariant f, Invariant g) => Invariant (Functor.Sum f g) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Sum f g a -> Sum f g b
invmap a -> b
f b -> a
g (InL f a
x) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
x)
  invmap a -> b
f b -> a
g (InR g a
y) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g g a
y)

-- | from "Data.List.NonEmpty"
instance Invariant NonEmpty where
  invmap :: forall a b. (a -> b) -> (b -> a) -> NonEmpty a -> NonEmpty b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from "Data.Monoid"
instance Invariant Dual where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Dual a -> Dual b
invmap a -> b
f b -> a
_ (Dual a
x) = forall a. a -> Dual a
Dual (a -> b
f a
x)
-- | from "Data.Monoid"
instance Invariant Endo where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Endo a -> Endo b
invmap a -> b
f b -> a
g (Endo a -> a
x) = forall a. (a -> a) -> Endo a
Endo (a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a
g)
-- | from "Data.Monoid"
instance Invariant Monoid.First where
  invmap :: forall a b. (a -> b) -> (b -> a) -> First a -> First b
invmap a -> b
f b -> a
g (Monoid.First Maybe a
x) = forall a. Maybe a -> First a
Monoid.First (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g Maybe a
x)
-- | from "Data.Monoid"
instance Invariant Monoid.Last where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Last a -> Last b
invmap a -> b
f b -> a
g (Monoid.Last Maybe a
x) = forall a. Maybe a -> Last a
Monoid.Last (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g Maybe a
x)
-- | from "Data.Monoid"
instance Invariant Monoid.Product where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Product a -> Product b
invmap a -> b
f b -> a
_ (Monoid.Product a
x) = forall a. a -> Product a
Monoid.Product (a -> b
f a
x)
-- | from "Data.Monoid"
instance Invariant Monoid.Sum where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Sum a -> Sum b
invmap a -> b
f b -> a
_ (Monoid.Sum a
x) = forall a. a -> Sum a
Monoid.Sum (a -> b
f a
x)
#if MIN_VERSION_base(4,8,0)
-- | from "Data.Monoid"
instance Invariant f => Invariant (Alt f) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Alt f a -> Alt f b
invmap a -> b
f b -> a
g (Alt f a
x) = forall {k} (f :: k -> *) (a :: k). f a -> Alt f a
Alt (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
x)
#endif

-- | from "Data.Proxy"
instance Invariant Proxy where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Proxy a -> Proxy b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from "Data.Semigroup"
instance Invariant Min where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Min a -> Min b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Data.Semigroup"
instance Invariant Max where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Max a -> Max b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Data.Semigroup"
instance Invariant Semigroup.First where
  invmap :: forall a b. (a -> b) -> (b -> a) -> First a -> First b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Data.Semigroup"
instance Invariant Semigroup.Last where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Last a -> Last b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Data.Semigroup"
instance Invariant (Arg a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Arg a a -> Arg a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
#if !(MIN_VERSION_base(4,16,0))
-- | from "Data.Semigroup"
instance Invariant Semigroup.Option where
  invmap = invmapFunctor
#endif

-- | from "System.Console.GetOpt"
instance Invariant ArgDescr where
  invmap :: forall a b. (a -> b) -> (b -> a) -> ArgDescr a -> ArgDescr b
invmap a -> b
f b -> a
_ (NoArg a
a)    = forall a. a -> ArgDescr a
NoArg (a -> b
f a
a)
  invmap a -> b
f b -> a
_ (ReqArg String -> a
g String
s) = forall a. (String -> a) -> String -> ArgDescr a
ReqArg (a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> a
g) String
s
  invmap a -> b
f b -> a
_ (OptArg Maybe String -> a
g String
s) = forall a. (Maybe String -> a) -> String -> ArgDescr a
OptArg (a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe String -> a
g) String
s
-- | from "System.Console.GetOpt"
instance Invariant ArgOrder where
  invmap :: forall a b. (a -> b) -> (b -> a) -> ArgOrder a -> ArgOrder b
invmap a -> b
_ b -> a
_ ArgOrder a
RequireOrder      = forall a. ArgOrder a
RequireOrder
  invmap a -> b
_ b -> a
_ ArgOrder a
Permute           = forall a. ArgOrder a
Permute
  invmap a -> b
f b -> a
_ (ReturnInOrder String -> a
g) = forall a. (String -> a) -> ArgOrder a
ReturnInOrder (a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> a
g)
-- | from "System.Console.GetOpt"
instance Invariant OptDescr where
  invmap :: forall a b. (a -> b) -> (b -> a) -> OptDescr a -> OptDescr b
invmap a -> b
f b -> a
g (GetOpt.Option String
a [String]
b ArgDescr a
argDescr String
c) = forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
GetOpt.Option String
a [String]
b (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g ArgDescr a
argDescr) String
c

-- | from the @array@ package
instance
#if __GLASGOW_HASKELL__ < 711
  Ix i =>
#endif
    Invariant (Array i) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Array i a -> Array i b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from the @bifunctors@ package
instance (Invariant2 p, Invariant g) => Invariant (Biff p f g a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> Biff p f g a a -> Biff p f g a b
invmap a -> b
f b -> a
g = forall {k} {k1} {k2} {k3} (p :: k -> k1 -> *) (f :: k2 -> k)
       (g :: k3 -> k1) (a :: k2) (b :: k3).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} {k3} {k4} (p :: k1 -> k2 -> *) (f :: k3 -> k1)
       (g :: k4 -> k2) (a :: k3) (b :: k4).
Biff p f g a b -> p (f a) (g b)
runBiff
-- | from the @bifunctors@ package
instance Invariant (Clown f a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Clown f a a -> Clown f a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @bifunctors@ package
instance Invariant2 p => Invariant (Fix p) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Fix p a -> Fix p b
invmap a -> b
f b -> a
g = forall {k} (p :: * -> k -> *) (a :: k). p (Fix p a) a -> Fix p a
In forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) a -> b
f b -> a
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (p :: * -> k -> *) (a :: k). Fix p a -> p (Fix p a) a
out
-- | from the @bifunctors@ package
instance Invariant2 p => Invariant (Flip p a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Flip p a a -> Flip p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @bifunctors@ package
instance Invariant2 p => Invariant (Join p) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Join p a -> Join p b
invmap a -> b
f b -> a
g = forall {k} (p :: k -> k -> *) (a :: k). p a a -> Join p a
Join forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 a -> b
f b -> a
g a -> b
f b -> a
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (p :: k -> k -> *) (a :: k). Join p a -> p a a
runJoin
-- | from the @bifunctors@ package
instance Invariant g => Invariant (Joker g a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Joker g a a -> Joker g a b
invmap a -> b
f b -> a
g = forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (g :: k1 -> *) (a :: k2) (b :: k1).
Joker g a b -> g b
runJoker
-- | from the @bifunctors@ package
instance (Invariant f, Invariant2 p) => Invariant (Tannen f p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> Tannen f p a a -> Tannen f p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @bifunctors@ package
instance Bifunctor p => Invariant (WrappedBifunctor p a) where
  invmap :: forall a b.
(a -> b)
-> (b -> a) -> WrappedBifunctor p a a -> WrappedBifunctor p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id

-- | from the @comonad@ package
instance Invariant (Cokleisli w a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> Cokleisli w a a -> Cokleisli w a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from the @containers@ package
instance Invariant IntMap where
  invmap :: forall a b. (a -> b) -> (b -> a) -> IntMap a -> IntMap b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @containers@ package
instance Invariant (Map k) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Map k a -> Map k b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @containers@ package
instance Invariant Seq where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Seq a -> Seq b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @containers@ package
instance Invariant ViewL where
  invmap :: forall a b. (a -> b) -> (b -> a) -> ViewL a -> ViewL b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @containers@ package
instance Invariant ViewR where
  invmap :: forall a b. (a -> b) -> (b -> a) -> ViewR a -> ViewR b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @containers@ package
instance Invariant Tree where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Tree a -> Tree b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from the @contravariant@ package
instance Invariant Predicate where invmap :: forall a b. (a -> b) -> (b -> a) -> Predicate a -> Predicate b
invmap = forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant
-- | from the @contravariant@ package
instance Invariant Comparison where invmap :: forall a b. (a -> b) -> (b -> a) -> Comparison a -> Comparison b
invmap = forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant
-- | from the @contravariant@ package
instance Invariant Equivalence where invmap :: forall a b. (a -> b) -> (b -> a) -> Equivalence a -> Equivalence b
invmap = forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant
-- | from the @contravariant@ package
instance Invariant (Op a) where invmap :: forall a b. (a -> b) -> (b -> a) -> Op a a -> Op a b
invmap = forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant
-- | from the @contravariant@ package
instance (Invariant f, Invariant g) => Invariant (Contravariant.Compose f g) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Compose f g a -> Compose f g b
invmap a -> b
f b -> a
g (Contravariant.Compose f (g a)
x) =
    forall (f :: * -> *) (g :: * -> *) a. f (g a) -> Compose f g a
Contravariant.Compose forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) f (g a)
x
-- | from the @contravariant@ package
instance (Invariant f, Invariant g) => Invariant (ComposeCF f g) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> ComposeCF f g a -> ComposeCF f g b
invmap a -> b
f b -> a
g (ComposeCF f (g a)
x) = forall (f :: * -> *) (g :: * -> *) a. f (g a) -> ComposeCF f g a
ComposeCF forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) f (g a)
x
-- | from the @contravariant@ package
instance (Invariant f, Invariant g) => Invariant (ComposeFC f g) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> ComposeFC f g a -> ComposeFC f g b
invmap a -> b
f b -> a
g (ComposeFC f (g a)
x) = forall (f :: * -> *) (g :: * -> *) a. f (g a) -> ComposeFC f g a
ComposeFC forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) f (g a)
x

-- | from the @profunctors@ package
instance Invariant f => Invariant (Star f a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Star f a a -> Star f a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (Costar f a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Costar f a a -> Costar f a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @profunctors@ package
instance Arrow arr => Invariant (Pro.WrappedArrow arr a) where
  invmap :: forall a b.
(a -> b)
-> (b -> a) -> WrappedArrow arr a a -> WrappedArrow arr a b
invmap a -> b
f b -> a
_ (Pro.WrapArrow arr a a
x) = forall {k} {k1} (p :: k -> k1 -> *) (a :: k) (b :: k1).
p a b -> WrappedArrow p a b
Pro.WrapArrow forall a b. (a -> b) -> a -> b
$ ((forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr a -> b
f) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. arr a a
x)
-- | from the @profunctors@ package
instance Invariant (Forget r a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Forget r a a -> Forget r a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Closure p a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Closure p a a -> Closure p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (Environment p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> Environment p a a -> Environment p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Codensity p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> Codensity p a a -> Codensity p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Coprep p) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Coprep p a -> Coprep p b
invmap a -> b
f b -> a
g (Coprep forall r. p a r -> r
h) = forall {k} (p :: k -> * -> *) (a :: k).
(forall r. p a r -> r) -> Coprep p a
Coprep (forall r. p a r -> r
h forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 b -> a
g a -> b
f forall a. a -> a
id forall a. a -> a
id)
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Prep p) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Prep p a -> Prep p b
invmap a -> b
f b -> a
g (Prep x
x p x a
p) = forall {k} x (p :: * -> k -> *) (a :: k). x -> p x a -> Prep p a
Prep x
x (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id a -> b
f b -> a
g p x a
p)
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Procompose p q a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> Procompose p q a a -> Procompose p q a b
invmap a -> b
k b -> a
k' (Procompose p x a
f q a x
g) = forall {k} {k1} {k2} (p :: k -> k1 -> *) (x :: k) (c :: k1)
       (q :: k2 -> k -> *) (d :: k2).
p x c -> q d x -> Procompose p q d c
Procompose (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id a -> b
k b -> a
k' p x a
f) q a x
g
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Rift p q a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Rift p q a a -> Rift p q a b
invmap a -> b
bd b -> a
db (Rift forall x. p a x -> q a x
f) = forall {k} {k1} {k2} (p :: k -> k1 -> *) (q :: k2 -> k1 -> *)
       (a :: k2) (b :: k).
(forall (x :: k1). p b x -> q a x) -> Rift p q a b
Rift (forall x. p a x -> q a x
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 b -> a
db a -> b
bd forall a. a -> a
id forall a. a -> a
id)
-- | from the @profunctors@ package
instance Invariant2 q => Invariant (Ran p q a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Ran p q a a -> Ran p q a b
invmap a -> b
bd b -> a
db (Ran forall x. p x a -> q x a
f) = forall {k} {k1} {k2} (p :: k -> k1 -> *) (q :: k -> k2 -> *)
       (a :: k1) (b :: k2).
(forall (x :: k). p x a -> q x b) -> Ran p q a b
Ran (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id a -> b
bd b -> a
db forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. p x a -> q x a
f)
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Tambara p a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Tambara p a a -> Tambara p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (PastroSum p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> PastroSum p a a -> PastroSum p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (FreeMapping p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> FreeMapping p a a -> FreeMapping p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (FreeTraversing p a) where
  invmap :: forall a b.
(a -> b)
-> (b -> a) -> FreeTraversing p a a -> FreeTraversing p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (Pastro p a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Pastro p a a -> Pastro p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (Cotambara p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> Cotambara p a a -> Cotambara p a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @profunctors@ package
instance Invariant (Copastro p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> Copastro p a a -> Copastro p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (CopastroSum p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> CopastroSum p a a -> CopastroSum p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (CotambaraSum p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> CotambaraSum p a a -> CotambaraSum p a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (TambaraSum p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> TambaraSum p a a -> TambaraSum p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (Yoneda p a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Yoneda p a a -> Yoneda p a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @profunctors@ package
instance Invariant (Coyoneda p a) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> Coyoneda p a a -> Coyoneda p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id

-- | from the @StateVar@ package
instance Invariant StateVar where
  invmap :: forall a b. (a -> b) -> (b -> a) -> StateVar a -> StateVar b
invmap a -> b
f b -> a
g (StateVar IO a
ga a -> IO ()
sa) = forall a. IO a -> (a -> IO ()) -> StateVar a
StateVar (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f IO a
ga) (forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap b -> a
g a -> IO ()
sa)
-- | from the @StateVar@ package
instance Invariant SettableStateVar where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> SettableStateVar a -> SettableStateVar b
invmap = forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant

-- | from the @stm@ package
instance Invariant STM where
  invmap :: forall a b. (a -> b) -> (b -> a) -> STM a -> STM b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from the @tagged@ package
instance Invariant (Tagged s) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Tagged s a -> Tagged s b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from the @transformers@ package
instance Invariant f => Invariant (Backwards f) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Backwards f a -> Backwards f b
invmap a -> b
f b -> a
g (Backwards f a
a) = forall {k} (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
a)
-- | from the @transformers@ package
instance Invariant f => Invariant (Lift f) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Lift f a -> Lift f b
invmap a -> b
f b -> a
_ (Pure a
x)  = forall (f :: * -> *) a. a -> Lift f a
Pure (a -> b
f a
x)
  invmap a -> b
f b -> a
g (Other f a
y) = forall (f :: * -> *) a. f a -> Lift f a
Other (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
y)
-- | from the @transformers@ package
instance Invariant (ContT r m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> ContT r m a -> ContT r m b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @transformers@ package
instance Invariant m => Invariant (ExceptT e m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> ExceptT e m a -> ExceptT e m b
invmap a -> b
f b -> a
g = forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT
-- | from the @transformers@ package
instance Invariant m => Invariant (IdentityT m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> IdentityT m a -> IdentityT m b
invmap a -> b
f b -> a
g = forall {k1} {k2} (m :: k1 -> *) (a :: k1) (n :: k2 -> *) (b :: k2).
(m a -> n b) -> IdentityT m a -> IdentityT n b
mapIdentityT (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g)
-- | from the @transformers@ package
instance Invariant m => Invariant (MaybeT m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> MaybeT m a -> MaybeT m b
invmap a -> b
f b -> a
g = forall (m :: * -> *) a (n :: * -> *) b.
(m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b
mapMaybeT forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f)
-- | from the @transformers@ package
instance Invariant m => Invariant (Lazy.RWST r w s m) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> RWST r w s m a -> RWST r w s m b
invmap a -> b
f b -> a
g RWST r w s m a
m = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Lazy.RWST forall a b. (a -> b) -> a -> b
$ \r
r s
s ->
    forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple a -> b
f) (forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple b -> a
g) forall a b. (a -> b) -> a -> b
$ forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
Lazy.runRWST RWST r w s m a
m r
r s
s
      where mapFstTriple :: (a -> b) -> (a, c, d) -> (b, c, d)
            mapFstTriple :: forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple a -> b
h ~(a
a, c
s, d
w) = (a -> b
h a
a, c
s, d
w)
-- | from the @transformers@ package
instance Invariant m => Invariant (Strict.RWST r w s m) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> RWST r w s m a -> RWST r w s m b
invmap a -> b
f b -> a
g RWST r w s m a
m = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST forall a b. (a -> b) -> a -> b
$ \r
r s
s ->
    forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple a -> b
f) (forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple b -> a
g) forall a b. (a -> b) -> a -> b
$ forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
Strict.runRWST RWST r w s m a
m r
r s
s
      where mapFstTriple :: (a -> b) -> (a, c, d) -> (b, c, d)
            mapFstTriple :: forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple a -> b
h (a
a, c
s, d
w) = (a -> b
h a
a, c
s, d
w)
-- | from the @transformers@ package
instance Invariant m => Invariant (ReaderT r m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> ReaderT r m a -> ReaderT r m b
invmap a -> b
f b -> a
g = forall (m :: * -> *) a (n :: * -> *) b r.
(m a -> n b) -> ReaderT r m a -> ReaderT r n b
mapReaderT (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g)
-- | from the @transformers@ package
instance Invariant m => Invariant (Lazy.StateT s m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> StateT s m a -> StateT s m b
invmap a -> b
f b -> a
g StateT s m a
m = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Lazy.StateT forall a b. (a -> b) -> a -> b
$ \s
s ->
    forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
f) (forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair b -> a
g) forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
Lazy.runStateT StateT s m a
m s
s
      where mapFstPair :: (a -> b) -> (a, c) -> (b, c)
            mapFstPair :: forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
h ~(a
a, c
s) = (a -> b
h a
a, c
s)
-- | from the @transformers@ package
instance Invariant m => Invariant (Strict.StateT s m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> StateT s m a -> StateT s m b
invmap a -> b
f b -> a
g StateT s m a
m = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Strict.StateT forall a b. (a -> b) -> a -> b
$ \s
s ->
    forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
f) (forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair b -> a
g) forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
Strict.runStateT StateT s m a
m s
s
      where mapFstPair :: (a -> b) -> (a, c) -> (b, c)
            mapFstPair :: forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
h (a
a, c
s) = (a -> b
h a
a, c
s)
-- | from the @transformers@ package
instance Invariant m => Invariant (Lazy.WriterT w m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> WriterT w m a -> WriterT w m b
invmap a -> b
f b -> a
g = forall (m :: * -> *) a w (n :: * -> *) b w'.
(m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
Lazy.mapWriterT forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
f) (forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair b -> a
g)
    where mapFstPair :: (a -> b) -> (a, c) -> (b, c)
          mapFstPair :: forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
h ~(a
a, c
w) = (a -> b
h a
a, c
w)
-- | from the @transformers@ package
instance Invariant m => Invariant (Strict.WriterT w m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> WriterT w m a -> WriterT w m b
invmap a -> b
f b -> a
g = forall (m :: * -> *) a w (n :: * -> *) b w'.
(m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
Strict.mapWriterT forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
f) (forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair b -> a
g)
    where mapFstPair :: (a -> b) -> (a, c) -> (b, c)
          mapFstPair :: forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
h (a
a, c
w) = (a -> b
h a
a, c
w)
-- | from the @transformers@ package
instance Invariant (Constant a) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Constant a a -> Constant a b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @transformers@ package
instance Invariant f => Invariant (Reverse f) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> Reverse f a -> Reverse f b
invmap a -> b
f b -> a
g (Reverse f a
a) = forall {k} (f :: k -> *) (a :: k). f a -> Reverse f a
Reverse (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
a)
#if !(MIN_VERSION_transformers(0,6,0))
-- | from the @transformers@ package
instance Invariant m => Invariant (ErrorT e m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> ErrorT e m a -> ErrorT e m b
invmap a -> b
f b -> a
g = forall e (m :: * -> *) a. m (Either e a) -> ErrorT e m a
ErrorT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (m :: * -> *) a. ErrorT e m a -> m (Either e a)
runErrorT
-- | from the @transformers@ package
instance Invariant m => Invariant (ListT m) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> ListT m a -> ListT m b
invmap a -> b
f b -> a
g = forall (m :: * -> *) a (n :: * -> *) b.
(m [a] -> n [b]) -> ListT m a -> ListT n b
mapListT forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f)
#endif

-- | from the @unordered-containers@ package
instance Invariant (HashMap k) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> HashMap k a -> HashMap k b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-------------------------------------------------------------------------------
-- WrappedFunctor
-------------------------------------------------------------------------------

-- | Wrap a 'Functor' to be used as a member of 'Invariant'.
newtype WrappedFunctor f a = WrapFunctor { forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor :: f a }
  deriving (WrappedFunctor f a -> WrappedFunctor f a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (f :: k -> *) (a :: k).
Eq (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Bool
/= :: WrappedFunctor f a -> WrappedFunctor f a -> Bool
$c/= :: forall k (f :: k -> *) (a :: k).
Eq (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Bool
== :: WrappedFunctor f a -> WrappedFunctor f a -> Bool
$c== :: forall k (f :: k -> *) (a :: k).
Eq (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Bool
Eq, WrappedFunctor f a -> WrappedFunctor f a -> Bool
WrappedFunctor f a -> WrappedFunctor f a -> Ordering
WrappedFunctor f a -> WrappedFunctor f a -> WrappedFunctor f a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {k} {f :: k -> *} {a :: k}.
Ord (f a) =>
Eq (WrappedFunctor f a)
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Bool
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Ordering
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> WrappedFunctor f a
min :: WrappedFunctor f a -> WrappedFunctor f a -> WrappedFunctor f a
$cmin :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> WrappedFunctor f a
max :: WrappedFunctor f a -> WrappedFunctor f a -> WrappedFunctor f a
$cmax :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> WrappedFunctor f a
>= :: WrappedFunctor f a -> WrappedFunctor f a -> Bool
$c>= :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Bool
> :: WrappedFunctor f a -> WrappedFunctor f a -> Bool
$c> :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Bool
<= :: WrappedFunctor f a -> WrappedFunctor f a -> Bool
$c<= :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Bool
< :: WrappedFunctor f a -> WrappedFunctor f a -> Bool
$c< :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Bool
compare :: WrappedFunctor f a -> WrappedFunctor f a -> Ordering
$ccompare :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedFunctor f a -> WrappedFunctor f a -> Ordering
Ord, ReadPrec [WrappedFunctor f a]
ReadPrec (WrappedFunctor f a)
ReadS [WrappedFunctor f a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec [WrappedFunctor f a]
forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec (WrappedFunctor f a)
forall k (f :: k -> *) (a :: k).
Read (f a) =>
Int -> ReadS (WrappedFunctor f a)
forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadS [WrappedFunctor f a]
readListPrec :: ReadPrec [WrappedFunctor f a]
$creadListPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec [WrappedFunctor f a]
readPrec :: ReadPrec (WrappedFunctor f a)
$creadPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec (WrappedFunctor f a)
readList :: ReadS [WrappedFunctor f a]
$creadList :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadS [WrappedFunctor f a]
readsPrec :: Int -> ReadS (WrappedFunctor f a)
$creadsPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
Int -> ReadS (WrappedFunctor f a)
Read, Int -> WrappedFunctor f a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (f :: k -> *) (a :: k).
Show (f a) =>
Int -> WrappedFunctor f a -> ShowS
forall k (f :: k -> *) (a :: k).
Show (f a) =>
[WrappedFunctor f a] -> ShowS
forall k (f :: k -> *) (a :: k).
Show (f a) =>
WrappedFunctor f a -> String
showList :: [WrappedFunctor f a] -> ShowS
$cshowList :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
[WrappedFunctor f a] -> ShowS
show :: WrappedFunctor f a -> String
$cshow :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
WrappedFunctor f a -> String
showsPrec :: Int -> WrappedFunctor f a -> ShowS
$cshowsPrec :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
Int -> WrappedFunctor f a -> ShowS
Show)

instance Functor f => Invariant (WrappedFunctor f) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> WrappedFunctor f a -> WrappedFunctor f b
invmap = forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

instance Functor f => Functor (WrappedFunctor f) where
  fmap :: forall a b. (a -> b) -> WrappedFunctor f a -> WrappedFunctor f b
fmap a -> b
f = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  a
x <$ :: forall a b. a -> WrappedFunctor f b -> WrappedFunctor f a
<$ WrapFunctor f b
f = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (a
x forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ f b
f)

instance Applicative f => Applicative (WrappedFunctor f) where
  pure :: forall a. a -> WrappedFunctor f a
pure = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure
  WrapFunctor f (a -> b)
f <*> :: forall a b.
WrappedFunctor f (a -> b)
-> WrappedFunctor f a -> WrappedFunctor f b
<*> WrapFunctor f a
x = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (f (a -> b)
f forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f a
x)
  WrapFunctor f a
a *> :: forall a b.
WrappedFunctor f a -> WrappedFunctor f b -> WrappedFunctor f b
*>  WrapFunctor f b
b = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (f a
a forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>  f b
b)
  WrapFunctor f a
a <* :: forall a b.
WrappedFunctor f a -> WrappedFunctor f b -> WrappedFunctor f a
<*  WrapFunctor f b
b = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (f a
a forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*  f b
b)

instance Alternative f => Alternative (WrappedFunctor f) where
  empty :: forall a. WrappedFunctor f a
empty = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall (f :: * -> *) a. Alternative f => f a
empty
  WrapFunctor f a
x <|> :: forall a.
WrappedFunctor f a -> WrappedFunctor f a -> WrappedFunctor f a
<|> WrapFunctor f a
y = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (f a
x forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> f a
y)
  some :: forall a. WrappedFunctor f a -> WrappedFunctor f [a]
some = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Alternative f => f a -> f [a]
some forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  many :: forall a. WrappedFunctor f a -> WrappedFunctor f [a]
many = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor

instance Monad m => Monad (WrappedFunctor m) where
  WrapFunctor m a
x >>= :: forall a b.
WrappedFunctor m a
-> (a -> WrappedFunctor m b) -> WrappedFunctor m b
>>= a -> WrappedFunctor m b
f = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (m a
x forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> WrappedFunctor m b
f)
#if !(MIN_VERSION_base(4,11,0))
  return = WrapFunctor . return
  WrapFunctor a >> WrapFunctor b = WrapFunctor (a >> b)
#endif

instance MonadPlus m => MonadPlus (WrappedFunctor m) where
  mzero :: forall a. WrappedFunctor m a
mzero = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall (m :: * -> *) a. MonadPlus m => m a
mzero
  WrapFunctor m a
x mplus :: forall a.
WrappedFunctor m a -> WrappedFunctor m a -> WrappedFunctor m a
`mplus` WrapFunctor m a
y = forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (m a
x forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` m a
y)

instance F.Foldable f => F.Foldable (WrappedFunctor f) where
  fold :: forall m. Monoid m => WrappedFunctor f m -> m
fold       = forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
F.fold       forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldMap :: forall m a. Monoid m => (a -> m) -> WrappedFunctor f a -> m
foldMap a -> m
f  = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
F.foldMap a -> m
f  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldr :: forall a b. (a -> b -> b) -> b -> WrappedFunctor f a -> b
foldr a -> b -> b
f b
z  = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr a -> b -> b
f b
z  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldl :: forall b a. (b -> a -> b) -> b -> WrappedFunctor f a -> b
foldl b -> a -> b
f b
q  = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl b -> a -> b
f b
q  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldr1 :: forall a. (a -> a -> a) -> WrappedFunctor f a -> a
foldr1 a -> a -> a
f   = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
F.foldr1 a -> a -> a
f   forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldl1 :: forall a. (a -> a -> a) -> WrappedFunctor f a -> a
foldl1 a -> a -> a
f   = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
F.foldl1 a -> a -> a
f   forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
#if MIN_VERSION_base(4,6,0)
  foldr' :: forall a b. (a -> b -> b) -> b -> WrappedFunctor f a -> b
foldr' a -> b -> b
f b
z = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr' a -> b -> b
f b
z forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldl' :: forall b a. (b -> a -> b) -> b -> WrappedFunctor f a -> b
foldl' b -> a -> b
f b
q = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' b -> a -> b
f b
q forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
#endif
#if MIN_VERSION_base(4,8,0)
  toList :: forall a. WrappedFunctor f a -> [a]
toList     = forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList     forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  null :: forall a. WrappedFunctor f a -> Bool
null       = forall (t :: * -> *) a. Foldable t => t a -> Bool
F.null       forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  length :: forall a. WrappedFunctor f a -> Int
length     = forall (t :: * -> *) a. Foldable t => t a -> Int
F.length     forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  elem :: forall a. Eq a => a -> WrappedFunctor f a -> Bool
elem a
x     = forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
F.elem a
x     forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  maximum :: forall a. Ord a => WrappedFunctor f a -> a
maximum    = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
F.maximum    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  minimum :: forall a. Ord a => WrappedFunctor f a -> a
minimum    = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
F.minimum    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  sum :: forall a. Num a => WrappedFunctor f a -> a
sum        = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
F.sum        forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  product :: forall a. Num a => WrappedFunctor f a -> a
product    = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
F.product    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
#endif
#if MIN_VERSION_base(4,13,0)
  foldMap' :: forall m a. Monoid m => (a -> m) -> WrappedFunctor f a -> m
foldMap' a -> m
f = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
F.foldMap' a -> m
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
#endif

instance T.Traversable f => T.Traversable (WrappedFunctor f) where
  traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WrappedFunctor f a -> f (WrappedFunctor f b)
traverse a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap  forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
T.traverse a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  sequenceA :: forall (f :: * -> *) a.
Applicative f =>
WrappedFunctor f (f a) -> f (WrappedFunctor f a)
sequenceA  = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap  forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
T.sequenceA  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WrappedFunctor f a -> m (WrappedFunctor f b)
mapM a -> m b
f     = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
T.mapM a -> m b
f     forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  sequence :: forall (m :: * -> *) a.
Monad m =>
WrappedFunctor f (m a) -> m (WrappedFunctor f a)
sequence   = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall {k} (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
T.sequence   forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor

-------------------------------------------------------------------------------
-- WrappedContravariant
-------------------------------------------------------------------------------

-- | Wrap a 'Contravariant' functor to be used as a member of 'Invariant'.
newtype WrappedContravariant f a = WrapContravariant { forall {k} (f :: k -> *) (a :: k). WrappedContravariant f a -> f a
unwrapContravariant :: f a }
  deriving (WrappedContravariant f a -> WrappedContravariant f a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (f :: k -> *) (a :: k).
Eq (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Bool
/= :: WrappedContravariant f a -> WrappedContravariant f a -> Bool
$c/= :: forall k (f :: k -> *) (a :: k).
Eq (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Bool
== :: WrappedContravariant f a -> WrappedContravariant f a -> Bool
$c== :: forall k (f :: k -> *) (a :: k).
Eq (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Bool
Eq, WrappedContravariant f a -> WrappedContravariant f a -> Bool
WrappedContravariant f a -> WrappedContravariant f a -> Ordering
WrappedContravariant f a
-> WrappedContravariant f a -> WrappedContravariant f a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {k} {f :: k -> *} {a :: k}.
Ord (f a) =>
Eq (WrappedContravariant f a)
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Bool
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Ordering
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a
-> WrappedContravariant f a -> WrappedContravariant f a
min :: WrappedContravariant f a
-> WrappedContravariant f a -> WrappedContravariant f a
$cmin :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a
-> WrappedContravariant f a -> WrappedContravariant f a
max :: WrappedContravariant f a
-> WrappedContravariant f a -> WrappedContravariant f a
$cmax :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a
-> WrappedContravariant f a -> WrappedContravariant f a
>= :: WrappedContravariant f a -> WrappedContravariant f a -> Bool
$c>= :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Bool
> :: WrappedContravariant f a -> WrappedContravariant f a -> Bool
$c> :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Bool
<= :: WrappedContravariant f a -> WrappedContravariant f a -> Bool
$c<= :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Bool
< :: WrappedContravariant f a -> WrappedContravariant f a -> Bool
$c< :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Bool
compare :: WrappedContravariant f a -> WrappedContravariant f a -> Ordering
$ccompare :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
WrappedContravariant f a -> WrappedContravariant f a -> Ordering
Ord, ReadPrec [WrappedContravariant f a]
ReadPrec (WrappedContravariant f a)
ReadS [WrappedContravariant f a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec [WrappedContravariant f a]
forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec (WrappedContravariant f a)
forall k (f :: k -> *) (a :: k).
Read (f a) =>
Int -> ReadS (WrappedContravariant f a)
forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadS [WrappedContravariant f a]
readListPrec :: ReadPrec [WrappedContravariant f a]
$creadListPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec [WrappedContravariant f a]
readPrec :: ReadPrec (WrappedContravariant f a)
$creadPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec (WrappedContravariant f a)
readList :: ReadS [WrappedContravariant f a]
$creadList :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadS [WrappedContravariant f a]
readsPrec :: Int -> ReadS (WrappedContravariant f a)
$creadsPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
Int -> ReadS (WrappedContravariant f a)
Read, Int -> WrappedContravariant f a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (f :: k -> *) (a :: k).
Show (f a) =>
Int -> WrappedContravariant f a -> ShowS
forall k (f :: k -> *) (a :: k).
Show (f a) =>
[WrappedContravariant f a] -> ShowS
forall k (f :: k -> *) (a :: k).
Show (f a) =>
WrappedContravariant f a -> String
showList :: [WrappedContravariant f a] -> ShowS
$cshowList :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
[WrappedContravariant f a] -> ShowS
show :: WrappedContravariant f a -> String
$cshow :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
WrappedContravariant f a -> String
showsPrec :: Int -> WrappedContravariant f a -> ShowS
$cshowsPrec :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
Int -> WrappedContravariant f a -> ShowS
Show)

instance Contravariant f => Invariant (WrappedContravariant f) where
  invmap :: forall a b.
(a -> b)
-> (b -> a) -> WrappedContravariant f a -> WrappedContravariant f b
invmap = forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant

instance Contravariant f => Contravariant (WrappedContravariant f) where
  contramap :: forall a' a.
(a' -> a) -> WrappedContravariant f a -> WrappedContravariant f a'
contramap a' -> a
f = forall {k} (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). WrappedContravariant f a -> f a
unwrapContravariant
  b
x >$ :: forall b a.
b -> WrappedContravariant f b -> WrappedContravariant f a
>$ WrapContravariant f b
f = forall {k} (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant (b
x forall (f :: * -> *) b a. Contravariant f => b -> f b -> f a
>$ f b
f)

instance Divisible f => Divisible (WrappedContravariant f) where
  divide :: forall a b c.
(a -> (b, c))
-> WrappedContravariant f b
-> WrappedContravariant f c
-> WrappedContravariant f a
divide a -> (b, c)
f (WrapContravariant f b
l) (WrapContravariant f c
r) =
    forall {k} (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b c.
Divisible f =>
(a -> (b, c)) -> f b -> f c -> f a
divide a -> (b, c)
f f b
l f c
r
  conquer :: forall a. WrappedContravariant f a
conquer = forall {k} (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant forall (f :: * -> *) a. Divisible f => f a
conquer

instance Decidable f => Decidable (WrappedContravariant f) where
  lose :: forall a. (a -> Void) -> WrappedContravariant f a
lose = forall {k} (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Decidable f => (a -> Void) -> f a
lose
  choose :: forall a b c.
(a -> Either b c)
-> WrappedContravariant f b
-> WrappedContravariant f c
-> WrappedContravariant f a
choose a -> Either b c
f (WrapContravariant f b
l) (WrapContravariant f c
r) =
    forall {k} (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b c.
Decidable f =>
(a -> Either b c) -> f b -> f c -> f a
choose a -> Either b c
f f b
l f c
r

-------------------------------------------------------------------------------
-- The Invariant2 class
-------------------------------------------------------------------------------

-- | Any @* -> * -> *@ type parametric in both arguments permits an instance of
-- @Invariant2@.
--
-- Instances should satisfy the following laws:
--
-- > invmap2 id id id id = id
-- > invmap2 f2 f2' g2 g2' . invmap2 f1 f1' g1 g1' =
-- >   invmap2 (f2 . f1) (f1' . f2') (g2 . g1) (g1' . g2')
class Invariant2 f where
  invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d

-- | Every 'Bifunctor' is also an 'Invariant2' functor.
invmap2Bifunctor :: Bifunctor f
                 => (a -> c) -> (c -> a)
                 -> (b -> d) -> (d -> b)
                 -> f a b    -> f c d
invmap2Bifunctor :: forall (f :: * -> * -> *) a c b d.
Bifunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Bifunctor a -> c
f c -> a
_ b -> d
g d -> b
_ = forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> c
f b -> d
g

-- | Every 'Profunctor' is also an 'Invariant2' functor.
invmap2Profunctor :: Profunctor f
                  => (a -> c) -> (c -> a)
                  -> (b -> d) -> (d -> b)
                  -> f a b    -> f c d
invmap2Profunctor :: forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor a -> c
_ c -> a
f' b -> d
g d -> b
_ = forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap c -> a
f' b -> d
g

-------------------------------------------------------------------------------
-- Invariant2 instances
-------------------------------------------------------------------------------

instance Invariant2 (->) where invmap2 :: forall a c b d.
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> (a -> b) -> c -> d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
instance Invariant2 Either where invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Either a b -> Either c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Bifunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Bifunctor
instance Invariant2 (,) where invmap2 :: forall a c b d.
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> (a, b) -> (c, d)
invmap2 a -> c
f c -> a
_ b -> d
g d -> b
_ ~(a
x, b
y) = (a -> c
f a
x, b -> d
g b
y)
instance Invariant2 ((,,) a) where invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> (a, a, b) -> (a, c, d)
invmap2 a -> c
f c -> a
_ b -> d
g d -> b
_ ~(a
a, a
x, b
y) = (a
a, a -> c
f a
x, b -> d
g b
y)
instance Invariant2 ((,,,) a b) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> (a, b, a, b) -> (a, b, c, d)
invmap2 a -> c
f c -> a
_ b -> d
g d -> b
_ ~(a
a, b
b, a
x, b
y) = (a
a, b
b, a -> c
f a
x, b -> d
g b
y)
instance Invariant2 ((,,,,) a b c) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> (a, b, c, a, b)
-> (a, b, c, c, d)
invmap2 a -> c
f c -> a
_ b -> d
g d -> b
_ ~(a
a, b
b, c
c, a
x, b
y) = (a
a, b
b, c
c, a -> c
f a
x, b -> d
g b
y)

-- | from "Control.Applicative"
instance Invariant2 Const where invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Const a b -> Const c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Bifunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Bifunctor
-- | from "Control.Applicative"
instance Arrow arr => Invariant2 (App.WrappedArrow arr) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> WrappedArrow arr a b
-> WrappedArrow arr c d
invmap2 a -> c
_ c -> a
f' b -> d
g d -> b
_ (App.WrapArrow arr a b
x) = forall (a :: * -> * -> *) b c. a b c -> WrappedArrow a b c
App.WrapArrow forall a b. (a -> b) -> a -> b
$ forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr b -> d
g forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. arr a b
x forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr c -> a
f'

-- | from "Control.Arrow"
instance Invariant m => Invariant2 (Kleisli m) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Kleisli m a b
-> Kleisli m c d
invmap2 a -> c
_ c -> a
f' b -> d
g d -> b
g' (Kleisli a -> m b
m) = forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Kleisli forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> d
g d -> b
g' forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m b
m forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> a
f'

-- | from "Data.Semigroup"
instance Invariant2 Arg where
  invmap2 :: forall a c b d.
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> Arg a b -> Arg c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Bifunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Bifunctor

-- | from the @bifunctors@ package
instance (Invariant2 p, Invariant f, Invariant g) => Invariant2 (Biff p f g) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Biff p f g a b
-> Biff p f g c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' =
    forall {k} {k1} {k2} {k3} (p :: k -> k1 -> *) (f :: k2 -> k)
       (g :: k3 -> k1) (a :: k2) (b :: k3).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> c
f c -> a
f') (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap c -> a
f' a -> c
f) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> d
g d -> b
g') (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap d -> b
g' b -> d
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} {k3} {k4} (p :: k1 -> k2 -> *) (f :: k3 -> k1)
       (g :: k4 -> k2) (a :: k3) (b :: k4).
Biff p f g a b -> p (f a) (g b)
runBiff
-- | from the @bifunctors@ package
instance Invariant f => Invariant2 (Clown f) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Clown f a b -> Clown f c d
invmap2 a -> c
f c -> a
f' b -> d
_ d -> b
_ = forall {k} {k1} (f :: k -> *) (a :: k) (b :: k1).
f a -> Clown f a b
Clown forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> c
f c -> a
f' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (a :: k1) (b :: k2).
Clown f a b -> f a
runClown
-- | from the @bifunctors@ package
instance Invariant2 p => Invariant2 (Flip p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Flip p a b -> Flip p c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' = forall {k} {k1} (p :: k -> k1 -> *) (a :: k1) (b :: k).
p b a -> Flip p a b
Flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 b -> d
g d -> b
g' a -> c
f c -> a
f' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (p :: k1 -> k2 -> *) (a :: k2) (b :: k1).
Flip p a b -> p b a
runFlip
-- | from the @bifunctors@ package
instance Invariant g => Invariant2 (Joker g) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Joker g a b -> Joker g c d
invmap2 a -> c
_ c -> a
_ b -> d
g d -> b
g' = forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> d
g d -> b
g' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (g :: k1 -> *) (a :: k2) (b :: k1).
Joker g a b -> g b
runJoker
-- | from the @bifunctors@ package
instance (Invariant2 f, Invariant2 g) => Invariant2 (Bifunctor.Product f g) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Product f g a b
-> Product f g c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' (Bifunctor.Pair f a b
x g a b
y) =
    forall {k} {k1} (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
       (b :: k1).
f a b -> g a b -> Product f g a b
Bifunctor.Pair (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' f a b
x) (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' g a b
y)
-- | from the @bifunctors@ package
instance (Invariant2 p, Invariant2 q) => Invariant2 (Bifunctor.Sum p q) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Sum p q a b -> Sum p q c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' (Bifunctor.L2 p a b
l) = forall {k} {k1} (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
       (b :: k1).
p a b -> Sum p q a b
Bifunctor.L2 (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' p a b
l)
  invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' (Bifunctor.R2 q a b
r) = forall {k} {k1} (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
       (b :: k1).
q a b -> Sum p q a b
Bifunctor.R2 (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' q a b
r)
-- | from the @bifunctors@ package
instance (Invariant f, Invariant2 p) => Invariant2 (Tannen f p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Tannen f p a b
-> Tannen f p c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' =
    forall {k} {k1} {k2} (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Tannen f p a b
Tannen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g') (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 c -> a
f' a -> c
f d -> b
g' b -> d
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} {k3} (f :: k1 -> *) (p :: k2 -> k3 -> k1)
       (a :: k2) (b :: k3).
Tannen f p a b -> f (p a b)
runTannen
-- | from the @bifunctors@ package
instance Bifunctor p => Invariant2 (WrappedBifunctor p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> WrappedBifunctor p a b
-> WrappedBifunctor p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Bifunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Bifunctor

-- | from the @comonad@ package
instance Invariant w => Invariant2 (Cokleisli w) where
   invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Cokleisli w a b
-> Cokleisli w c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
_ (Cokleisli w a -> b
w) = forall {k} (w :: k -> *) (a :: k) b. (w a -> b) -> Cokleisli w a b
Cokleisli forall a b. (a -> b) -> a -> b
$ b -> d
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. w a -> b
w forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap c -> a
f' a -> c
f
-- | from the @contravariant@ package
instance Invariant2 Op where
  invmap2 :: forall a c b d.
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> Op a b -> Op c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' (Op b -> a
x) = forall a b. (b -> a) -> Op a b
Op forall a b. (a -> b) -> a -> b
$ forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 b -> d
g d -> b
g' a -> c
f c -> a
f' b -> a
x

-- | from the @profunctors@ package
instance Invariant f => Invariant2 (Star f) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Star f a b -> Star f c d
invmap2 a -> c
_ c -> a
ba b -> d
cd d -> b
dc (Star a -> f b
afc) = forall {k} (f :: k -> *) d (c :: k). (d -> f c) -> Star f d c
Star forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> d
cd d -> b
dc forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
afc forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> a
ba
-- | from the @profunctors@ package
instance Invariant f => Invariant2 (Costar f) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Costar f a b -> Costar f c d
invmap2 a -> c
ab c -> a
ba b -> d
cd d -> b
_ (Costar f a -> b
fbc) = forall {k} (f :: k -> *) (d :: k) c. (f d -> c) -> Costar f d c
Costar forall a b. (a -> b) -> a -> b
$ b -> d
cd forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> b
fbc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap c -> a
ba a -> c
ab
-- | from the @profunctors@ package
instance Arrow arr => Invariant2 (Pro.WrappedArrow arr) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> WrappedArrow arr a b
-> WrappedArrow arr c d
invmap2 a -> c
_ c -> a
f' b -> d
g d -> b
_ (Pro.WrapArrow arr a b
x) = forall {k} {k1} (p :: k -> k1 -> *) (a :: k) (b :: k1).
p a b -> WrappedArrow p a b
Pro.WrapArrow forall a b. (a -> b) -> a -> b
$ forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr b -> d
g forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. arr a b
x forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr c -> a
f'
-- | from the @profunctors@ package
instance Invariant2 (Forget r) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Forget r a b -> Forget r c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance (Invariant f, Invariant2 p) => Invariant2 (Cayley f p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Cayley f p a b
-> Cayley f p c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' =
    forall {k} {k1} {k2} (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Cayley f p a b
Cayley forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g') (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 c -> a
f' a -> c
f d -> b
g' b -> d
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} {k3} (f :: k1 -> *) (p :: k2 -> k3 -> k1)
       (a :: k2) (b :: k3).
Cayley f p a b -> f (p a b)
runCayley
-- | from the @profunctors@ package
instance Invariant2 p => Invariant2 (Closure p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Closure p a b
-> Closure p c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' (Closure forall x. p (x -> a) (x -> b)
p) = forall (p :: * -> * -> *) a b.
(forall x. p (x -> a) (x -> b)) -> Closure p a b
Closure forall a b. (a -> b) -> a -> b
$ forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 (a -> c
f forall b c a. (b -> c) -> (a -> b) -> a -> c
.) (c -> a
f' forall b c a. (b -> c) -> (a -> b) -> a -> c
.) (b -> d
g forall b c a. (b -> c) -> (a -> b) -> a -> c
.) (d -> b
g' forall b c a. (b -> c) -> (a -> b) -> a -> c
.) forall x. p (x -> a) (x -> b)
p
-- | from the @profunctors@ package
instance Invariant2 (Environment p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Environment p a b
-> Environment p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 p => Invariant2 (Codensity p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Codensity p a b
-> Codensity p c d
invmap2 a -> c
ac c -> a
ca b -> d
bd d -> b
db (Codensity forall x. p x a -> p x b
f) =
    forall {k} {k1} (p :: k -> k1 -> *) (a :: k1) (b :: k1).
(forall (x :: k). p x a -> p x b) -> Codensity p a b
Codensity (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id b -> d
bd d -> b
db forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. p x a -> p x b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id c -> a
ca a -> c
ac)
-- | from the @profunctors@ package
instance (Invariant2 p, Invariant2 q) => Invariant2 (Procompose p q) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Procompose p q a b
-> Procompose p q c d
invmap2 a -> c
l c -> a
l' b -> d
r d -> b
r' (Procompose p x b
f q a x
g) =
    forall {k} {k1} {k2} (p :: k -> k1 -> *) (x :: k) (c :: k1)
       (q :: k2 -> k -> *) (d :: k2).
p x c -> q d x -> Procompose p q d c
Procompose (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id b -> d
r d -> b
r' p x b
f) (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 a -> c
l c -> a
l' forall a. a -> a
id forall a. a -> a
id q a x
g)
-- | from the @profunctors@ package
instance (Invariant2 p, Invariant2 q) => Invariant2 (Rift p q) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Rift p q a b -> Rift p q c d
invmap2 a -> c
ac c -> a
ca b -> d
bd d -> b
db (Rift forall x. p b x -> q a x
f) = forall {k} {k1} {k2} (p :: k -> k1 -> *) (q :: k2 -> k1 -> *)
       (a :: k2) (b :: k).
(forall (x :: k1). p b x -> q a x) -> Rift p q a b
Rift (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 a -> c
ac c -> a
ca forall a. a -> a
id forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. p b x -> q a x
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 d -> b
db b -> d
bd forall a. a -> a
id forall a. a -> a
id)
-- | from the @profunctors@ package
instance (Invariant2 p, Invariant2 q) => Invariant2 (Ran p q) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Ran p q a b -> Ran p q c d
invmap2 a -> c
ac c -> a
ca b -> d
bd d -> b
db (Ran forall x. p x a -> q x b
f) = forall {k} {k1} {k2} (p :: k -> k1 -> *) (q :: k -> k2 -> *)
       (a :: k1) (b :: k2).
(forall (x :: k). p x a -> q x b) -> Ran p q a b
Ran (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id b -> d
bd d -> b
db forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. p x a -> q x b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id c -> a
ca a -> c
ac)
-- | from the @profunctors@ package
instance Invariant2 p => Invariant2 (Tambara p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Tambara p a b
-> Tambara p c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' (Tambara forall c. p (a, c) (b, c)
p) =
    forall (p :: * -> * -> *) a b.
(forall c. p (a, c) (b, c)) -> Tambara p a b
Tambara forall a b. (a -> b) -> a -> b
$ forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> c
f) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first c -> a
f') (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b -> d
g) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first d -> b
g') forall c. p (a, c) (b, c)
p
-- | from the @profunctors@ package
instance Invariant2 (PastroSum p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> PastroSum p a b
-> PastroSum p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 p => Invariant2 (CofreeMapping p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> CofreeMapping p a b
-> CofreeMapping p c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' (CofreeMapping forall (f :: * -> *). Functor f => p (f a) (f b)
p) =
    forall (p :: * -> * -> *) a b.
(forall (f :: * -> *). Functor f => p (f a) (f b))
-> CofreeMapping p a b
CofreeMapping (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> c
f) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> a
f') (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> d
g) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap d -> b
g') forall (f :: * -> *). Functor f => p (f a) (f b)
p)
-- | from the @profunctors@ package
instance Invariant2 (FreeMapping p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> FreeMapping p a b
-> FreeMapping p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 p => Invariant2 (CofreeTraversing p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> CofreeTraversing p a b
-> CofreeTraversing p c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' (CofreeTraversing forall (f :: * -> *). Traversable f => p (f a) (f b)
p) =
    forall (p :: * -> * -> *) a b.
(forall (f :: * -> *). Traversable f => p (f a) (f b))
-> CofreeTraversing p a b
CofreeTraversing (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> c
f) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> a
f') (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> d
g) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap d -> b
g') forall (f :: * -> *). Traversable f => p (f a) (f b)
p)
-- | from the @profunctors@ package
instance Invariant2 (FreeTraversing p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> FreeTraversing p a b
-> FreeTraversing p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 (Pastro p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Pastro p a b -> Pastro p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 (Cotambara p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Cotambara p a b
-> Cotambara p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 (Copastro p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Copastro p a b
-> Copastro p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 (CopastroSum p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> CopastroSum p a b
-> CopastroSum p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 (CotambaraSum p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> CotambaraSum p a b
-> CotambaraSum p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 p => Invariant2 (TambaraSum p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> TambaraSum p a b
-> TambaraSum p c d
invmap2 a -> c
f c -> a
f' b -> d
g d -> b
g' (TambaraSum forall c. p (Either a c) (Either b c)
p) =
    forall (p :: * -> * -> *) a b.
(forall c. p (Either a c) (Either b c)) -> TambaraSum p a b
TambaraSum (forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> c
f) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first c -> a
f') (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b -> d
g) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first d -> b
g') forall c. p (Either a c) (Either b c)
p)
-- | from the @profunctors@ package
instance Invariant2 (Yoneda p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Yoneda p a b -> Yoneda p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor
-- | from the @profunctors@ package
instance Invariant2 (Coyoneda p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Coyoneda p a b
-> Coyoneda p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor

-- | from the @tagged@ package
instance Invariant2 Tagged where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Tagged a b -> Tagged c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Bifunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Bifunctor

-- | from the @transformers@ package
instance Invariant2 Constant where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Constant a b -> Constant c d
invmap2 a -> c
f c -> a
_ b -> d
_ d -> b
_ (Constant a
x) = forall {k} a (b :: k). a -> Constant a b
Constant (a -> c
f a
x)

-------------------------------------------------------------------------------
-- WrappedProfunctor
-------------------------------------------------------------------------------

-- | Wrap a 'Profunctor' to be used as a member of 'Invariant2'.
newtype WrappedProfunctor p a b = WrapProfunctor { forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor :: p a b }
  deriving (WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Eq (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
/= :: WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
$c/= :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Eq (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
== :: WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
$c== :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Eq (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
Eq, WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Ordering
WrappedProfunctor p a b
-> WrappedProfunctor p a b -> WrappedProfunctor p a b
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {k} {k} {p :: k -> k -> *} {a :: k} {b :: k}.
Ord (p a b) =>
Eq (WrappedProfunctor p a b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Ordering
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b
-> WrappedProfunctor p a b -> WrappedProfunctor p a b
min :: WrappedProfunctor p a b
-> WrappedProfunctor p a b -> WrappedProfunctor p a b
$cmin :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b
-> WrappedProfunctor p a b -> WrappedProfunctor p a b
max :: WrappedProfunctor p a b
-> WrappedProfunctor p a b -> WrappedProfunctor p a b
$cmax :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b
-> WrappedProfunctor p a b -> WrappedProfunctor p a b
>= :: WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
$c>= :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
> :: WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
$c> :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
<= :: WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
$c<= :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
< :: WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
$c< :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
compare :: WrappedProfunctor p a b -> WrappedProfunctor p a b -> Ordering
$ccompare :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedProfunctor p a b -> WrappedProfunctor p a b -> Ordering
Ord, ReadPrec [WrappedProfunctor p a b]
ReadPrec (WrappedProfunctor p a b)
ReadS [WrappedProfunctor p a b]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadPrec [WrappedProfunctor p a b]
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadPrec (WrappedProfunctor p a b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
Int -> ReadS (WrappedProfunctor p a b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadS [WrappedProfunctor p a b]
readListPrec :: ReadPrec [WrappedProfunctor p a b]
$creadListPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadPrec [WrappedProfunctor p a b]
readPrec :: ReadPrec (WrappedProfunctor p a b)
$creadPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadPrec (WrappedProfunctor p a b)
readList :: ReadS [WrappedProfunctor p a b]
$creadList :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadS [WrappedProfunctor p a b]
readsPrec :: Int -> ReadS (WrappedProfunctor p a b)
$creadsPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
Int -> ReadS (WrappedProfunctor p a b)
Read, Int -> WrappedProfunctor p a b -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
Int -> WrappedProfunctor p a b -> ShowS
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
[WrappedProfunctor p a b] -> ShowS
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
WrappedProfunctor p a b -> String
showList :: [WrappedProfunctor p a b] -> ShowS
$cshowList :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
[WrappedProfunctor p a b] -> ShowS
show :: WrappedProfunctor p a b -> String
$cshow :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
WrappedProfunctor p a b -> String
showsPrec :: Int -> WrappedProfunctor p a b -> ShowS
$cshowsPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
Int -> WrappedProfunctor p a b -> ShowS
Show)

instance Profunctor p => Invariant2 (WrappedProfunctor p) where
  invmap2 :: forall a c b d.
(a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> WrappedProfunctor p a b
-> WrappedProfunctor p c d
invmap2 = forall (f :: * -> * -> *) a c b d.
Profunctor f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2Profunctor

instance Profunctor p => Invariant (WrappedProfunctor p a) where
  invmap :: forall a b.
(a -> b)
-> (b -> a) -> WrappedProfunctor p a a -> WrappedProfunctor p a b
invmap = forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 forall a. a -> a
id forall a. a -> a
id

instance Profunctor p => Profunctor (WrappedProfunctor p) where
  dimap :: forall a b c d.
(a -> b)
-> (c -> d) -> WrappedProfunctor p b c -> WrappedProfunctor p a d
dimap a -> b
f c -> d
g = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
f c -> d
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  lmap :: forall a b c.
(a -> b) -> WrappedProfunctor p b c -> WrappedProfunctor p a c
lmap a -> b
f    = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  rmap :: forall b c a.
(b -> c) -> WrappedProfunctor p a b -> WrappedProfunctor p a c
rmap b -> c
g    = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap b -> c
g    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  WrapProfunctor p b c
x .# :: forall a b c (q :: * -> * -> *).
Coercible b a =>
WrappedProfunctor p b c -> q a b -> WrappedProfunctor p a c
.# q a b
f = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
x forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# q a b
f)
  q b c
g #. :: forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> WrappedProfunctor p a b -> WrappedProfunctor p a c
#. WrapProfunctor p a b
x = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (q b c
g forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a b
x)

instance Cat.Category p => Cat.Category (WrappedProfunctor p) where
  id :: forall (a :: k). WrappedProfunctor p a a
id = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
Cat.id
  WrapProfunctor p b c
p1 . :: forall (b :: k) (c :: k) (a :: k).
WrappedProfunctor p b c
-> WrappedProfunctor p a b -> WrappedProfunctor p a c
. WrapProfunctor p a b
p2 = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. p a b
p2)

instance Arrow p => Arrow (WrappedProfunctor p) where
  arr :: forall b c. (b -> c) -> WrappedProfunctor p b c
arr    = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr
  first :: forall b c d.
WrappedProfunctor p b c -> WrappedProfunctor p (b, d) (c, d)
first  = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
Arr.first  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  second :: forall b c d.
WrappedProfunctor p b c -> WrappedProfunctor p (d, b) (d, c)
second = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
Arr.second forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  WrapProfunctor p b c
p1 *** :: forall b c b' c'.
WrappedProfunctor p b c
-> WrappedProfunctor p b' c' -> WrappedProfunctor p (b, b') (c, c')
*** WrapProfunctor p b' c'
p2 = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** p b' c'
p2)
  WrapProfunctor p b c
p1 &&& :: forall b c c'.
WrappedProfunctor p b c
-> WrappedProfunctor p b c' -> WrappedProfunctor p b (c, c')
&&& WrapProfunctor p b c'
p2 = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& p b c'
p2)

instance ArrowZero p => ArrowZero (WrappedProfunctor p) where
  zeroArrow :: forall b c. WrappedProfunctor p b c
zeroArrow = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall (a :: * -> * -> *) b c. ArrowZero a => a b c
zeroArrow

instance ArrowPlus p => ArrowPlus (WrappedProfunctor p) where
  WrapProfunctor p b c
p1 <+> :: forall b c.
WrappedProfunctor p b c
-> WrappedProfunctor p b c -> WrappedProfunctor p b c
<+> WrapProfunctor p b c
p2 = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 forall (a :: * -> * -> *) b c.
ArrowPlus a =>
a b c -> a b c -> a b c
<+> p b c
p2)

instance ArrowChoice p => ArrowChoice (WrappedProfunctor p) where
  left :: forall b c d.
WrappedProfunctor p b c
-> WrappedProfunctor p (Either b d) (Either c d)
left  = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either b d) (Either c d)
left  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  right :: forall b c d.
WrappedProfunctor p b c
-> WrappedProfunctor p (Either d b) (Either d c)
right = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either d b) (Either d c)
right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  WrapProfunctor p b c
p1 +++ :: forall b c b' c'.
WrappedProfunctor p b c
-> WrappedProfunctor p b' c'
-> WrappedProfunctor p (Either b b') (Either c c')
+++ WrapProfunctor p b' c'
p2 = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 forall (a :: * -> * -> *) b c b' c'.
ArrowChoice a =>
a b c -> a b' c' -> a (Either b b') (Either c c')
+++ p b' c'
p2)
  WrapProfunctor p b d
p1 ||| :: forall b d c.
WrappedProfunctor p b d
-> WrappedProfunctor p c d -> WrappedProfunctor p (Either b c) d
||| WrapProfunctor p c d
p2 = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b d
p1 forall (a :: * -> * -> *) b d c.
ArrowChoice a =>
a b d -> a c d -> a (Either b c) d
||| p c d
p2)

instance ArrowLoop p => ArrowLoop (WrappedProfunctor p) where
  loop :: forall b d c.
WrappedProfunctor p (b, d) (c, d) -> WrappedProfunctor p b c
loop = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: * -> * -> *) b d c.
ArrowLoop a =>
a (b, d) (c, d) -> a b c
loop forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance Strong p => Strong (WrappedProfunctor p) where
  first' :: forall a b c.
WrappedProfunctor p a b -> WrappedProfunctor p (a, c) (b, c)
first'  = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (a, c) (b, c)
first'  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  second' :: forall a b c.
WrappedProfunctor p a b -> WrappedProfunctor p (c, a) (c, b)
second' = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (c, a) (c, b)
second' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance Choice p => Choice (WrappedProfunctor p) where
  left' :: forall a b c.
WrappedProfunctor p a b
-> WrappedProfunctor p (Either a c) (Either b c)
left'  = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Choice p =>
p a b -> p (Either a c) (Either b c)
left'  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  right' :: forall a b c.
WrappedProfunctor p a b
-> WrappedProfunctor p (Either c a) (Either c b)
right' = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Choice p =>
p a b -> p (Either c a) (Either c b)
right' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance Costrong p => Costrong (WrappedProfunctor p) where
  unfirst :: forall a d b.
WrappedProfunctor p (a, d) (b, d) -> WrappedProfunctor p a b
unfirst  = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a d b.
Costrong p =>
p (a, d) (b, d) -> p a b
unfirst  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  unsecond :: forall d a b.
WrappedProfunctor p (d, a) (d, b) -> WrappedProfunctor p a b
unsecond = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) d a b.
Costrong p =>
p (d, a) (d, b) -> p a b
unsecond forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance Cochoice p => Cochoice (WrappedProfunctor p) where
  unleft :: forall a d b.
WrappedProfunctor p (Either a d) (Either b d)
-> WrappedProfunctor p a b
unleft  = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a d b.
Cochoice p =>
p (Either a d) (Either b d) -> p a b
unleft  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  unright :: forall d a b.
WrappedProfunctor p (Either d a) (Either d b)
-> WrappedProfunctor p a b
unright = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) d a b.
Cochoice p =>
p (Either d a) (Either d b) -> p a b
unright forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance Closed p => Closed (WrappedProfunctor p) where
  closed :: forall a b x.
WrappedProfunctor p a b -> WrappedProfunctor p (x -> a) (x -> b)
closed = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b x.
Closed p =>
p a b -> p (x -> a) (x -> b)
closed forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance Traversing p => Traversing (WrappedProfunctor p) where
  traverse' :: forall (f :: * -> *) a b.
Traversable f =>
WrappedProfunctor p a b -> WrappedProfunctor p (f a) (f b)
traverse' = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) a b.
(Traversing p, Traversable f) =>
p a b -> p (f a) (f b)
traverse' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  wander :: forall a b s t.
(forall (f :: * -> *). Applicative f => (a -> f b) -> s -> f t)
-> WrappedProfunctor p a b -> WrappedProfunctor p s t
wander forall (f :: * -> *). Applicative f => (a -> f b) -> s -> f t
f  = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b s t.
Traversing p =>
(forall (f :: * -> *). Applicative f => (a -> f b) -> s -> f t)
-> p a b -> p s t
wander forall (f :: * -> *). Applicative f => (a -> f b) -> s -> f t
f  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance Mapping p => Mapping (WrappedProfunctor p) where
  map' :: forall (f :: * -> *) a b.
Functor f =>
WrappedProfunctor p a b -> WrappedProfunctor p (f a) (f b)
map' = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) a b.
(Mapping p, Functor f) =>
p a b -> p (f a) (f b)
map' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance ProfunctorFunctor WrappedProfunctor where
  promap :: forall (p :: * -> * -> *) (q :: * -> * -> *).
Profunctor p =>
(p :-> q) -> WrappedProfunctor p :-> WrappedProfunctor q
promap p :-> q
f = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor forall b c a. (b -> c) -> (a -> b) -> a -> c
. p :-> q
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance ProfunctorMonad WrappedProfunctor where
  proreturn :: forall (p :: * -> * -> *).
Profunctor p =>
p :-> WrappedProfunctor p
proreturn = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor
  projoin :: forall (p :: * -> * -> *).
Profunctor p =>
WrappedProfunctor (WrappedProfunctor p) :-> WrappedProfunctor p
projoin   = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

instance ProfunctorComonad WrappedProfunctor where
  proextract :: forall (p :: * -> * -> *).
Profunctor p =>
WrappedProfunctor p :-> p
proextract   = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  produplicate :: forall (p :: * -> * -> *).
Profunctor p =>
WrappedProfunctor p :-> WrappedProfunctor (WrappedProfunctor p)
produplicate = forall {k} {k} (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor

#if GHC_GENERICS_OK
-------------------------------------------------------------------------------
-- GHC Generics
-------------------------------------------------------------------------------

-- | from "GHC.Generics"
instance Invariant V1 where
  -- NSF 25 July 2015: I'd prefer an -XEmptyCase, but Haskell98.
  invmap :: forall a b. (a -> b) -> (b -> a) -> V1 a -> V1 b
invmap a -> b
_ b -> a
_ V1 a
x = V1 a
x seq :: forall a b. a -> b -> b
`seq` forall a. HasCallStack => String -> a
error String
"Invariant V1"
-- | from "GHC.Generics"
instance Invariant U1 where invmap :: forall a b. (a -> b) -> (b -> a) -> U1 a -> U1 b
invmap a -> b
_ b -> a
_ U1 a
_ = forall k (p :: k). U1 p
U1
-- | from "GHC.Generics"
instance (Invariant l, Invariant r) => Invariant ((:+:) l r) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> (:+:) l r a -> (:+:) l r b
invmap a -> b
f b -> a
g (L1 l a
l) = forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g l a
l
  invmap a -> b
f b -> a
g (R1 r a
r) = forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g r a
r
-- | from "GHC.Generics"
instance (Invariant l, Invariant r) => Invariant ((:*:) l r) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> (:*:) l r a -> (:*:) l r b
invmap a -> b
f b -> a
g ~(l a
l :*: r a
r) = forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g l a
l forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g r a
r
-- | from "GHC.Generics"
instance Invariant (K1 i c) where invmap :: forall a b. (a -> b) -> (b -> a) -> K1 i c a -> K1 i c b
invmap a -> b
_ b -> a
_ (K1 c
c) = forall k i c (p :: k). c -> K1 i c p
K1 c
c
-- | from "GHC.Generics"
instance Invariant2 (K1 i) where invmap2 :: forall a c b d.
(a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> K1 i a b -> K1 i c d
invmap2 a -> c
f c -> a
_ b -> d
_ d -> b
_ (K1 a
c) = forall k i c (p :: k). c -> K1 i c p
K1 forall a b. (a -> b) -> a -> b
$ a -> c
f a
c
-- | from "GHC.Generics"
instance Invariant f => Invariant (M1 i t f) where invmap :: forall a b. (a -> b) -> (b -> a) -> M1 i t f a -> M1 i t f b
invmap a -> b
f b -> a
g (M1 f a
fp) = forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
fp
-- | from "GHC.Generics"
instance Invariant Par1 where invmap :: forall a b. (a -> b) -> (b -> a) -> Par1 a -> Par1 b
invmap a -> b
f b -> a
_ (Par1 a
c) = forall p. p -> Par1 p
Par1 forall a b. (a -> b) -> a -> b
$ a -> b
f a
c
-- | from "GHC.Generics"
instance Invariant f => Invariant (Rec1 f) where invmap :: forall a b. (a -> b) -> (b -> a) -> Rec1 f a -> Rec1 f b
invmap a -> b
f b -> a
g (Rec1 f a
fp) = forall k (f :: k -> *) (p :: k). f p -> Rec1 f p
Rec1 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
fp
-- | from "GHC.Generics"
instance (Invariant f, Invariant g) => Invariant ((:.:) f g) where
  invmap :: forall a b. (a -> b) -> (b -> a) -> (:.:) f g a -> (:.:) f g b
invmap a -> b
f b -> a
g (Comp1 f (g a)
fgp) = forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) f (g a)
fgp

# if __GLASGOW_HASKELL__ >= 800
-- | from "GHC.Generics"
instance Invariant UAddr where
  invmap :: forall a b. (a -> b) -> (b -> a) -> UAddr a -> UAddr b
invmap a -> b
_ b -> a
_ (UAddr Addr#
a) = forall k (p :: k). Addr# -> URec (Ptr ()) p
UAddr Addr#
a

-- | from "GHC.Generics"
instance Invariant UChar where
  invmap :: forall a b. (a -> b) -> (b -> a) -> UChar a -> UChar b
invmap a -> b
_ b -> a
_ (UChar Char#
c) = forall k (p :: k). Char# -> URec Char p
UChar Char#
c

-- | from "GHC.Generics"
instance Invariant UDouble where
  invmap :: forall a b. (a -> b) -> (b -> a) -> UDouble a -> UDouble b
invmap a -> b
_ b -> a
_ (UDouble Double#
d) = forall k (p :: k). Double# -> URec Double p
UDouble Double#
d

-- | from "GHC.Generics"
instance Invariant UFloat where
  invmap :: forall a b. (a -> b) -> (b -> a) -> UFloat a -> UFloat b
invmap a -> b
_ b -> a
_ (UFloat Float#
f) = forall k (p :: k). Float# -> URec Float p
UFloat Float#
f

-- | from "GHC.Generics"
instance Invariant UInt where
  invmap :: forall a b. (a -> b) -> (b -> a) -> UInt a -> UInt b
invmap a -> b
_ b -> a
_ (UInt Int#
i) = forall k (p :: k). Int# -> URec Int p
UInt Int#
i

-- | from "GHC.Generics"
instance Invariant UWord where
  invmap :: forall a b. (a -> b) -> (b -> a) -> UWord a -> UWord b
invmap a -> b
_ b -> a
_ (UWord Word#
w) = forall k (p :: k). Word# -> URec Word p
UWord Word#
w
# endif

{- $ghcgenerics
With GHC 7.2 or later, 'Invariant' instances can be defined easily using GHC
generics like so:

@
&#123;-&#35; LANGUAGE DeriveGeneric, FlexibleContexts &#35;-&#125;

import Data.Functor.Invariant
import GHC.Generics

data T f a = T (f a) deriving Generic1

instance Invariant f => 'Invariant' (T f)
@

Be aware that generic 'Invariant' instances cannot be derived for data types
that have function arguments in which the last type parameter appears in a
position other than the result type (e.g., @data Fun a = Fun (a -> a)@). For
these, you can derive them using the "Data.Functor.Invariant.TH" module.
-}

-- | A generic implementation of 'invmap'.
genericInvmap :: (Generic1 f, Invariant (Rep1 f)) => (a -> b) -> (b -> a) -> f a -> f b
genericInvmap :: forall (f :: * -> *) a b.
(Generic1 f, Invariant (Rep1 f)) =>
(a -> b) -> (b -> a) -> f a -> f b
genericInvmap a -> b
f b -> a
g = forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1
#endif

-------------------------------------------------------------------------------
-- Wrappers
-------------------------------------------------------------------------------

-- | A 'Profunctor' with the same input and output types can be seen as an 'Invariant' functor.
newtype InvariantProfunctor p a = InvariantProfunctor (p a a)

instance Profunctor p => Invariant (InvariantProfunctor p) where
  invmap :: forall a b.
(a -> b)
-> (b -> a) -> InvariantProfunctor p a -> InvariantProfunctor p b
invmap a -> b
fn1 b -> a
fn2 (InvariantProfunctor p a a
f) = forall {k} (p :: k -> k -> *) (a :: k).
p a a -> InvariantProfunctor p a
InvariantProfunctor (forall (p :: * -> * -> *) a b.
Profunctor p =>
(a -> b) -> (b -> a) -> p a a -> p b b
invmapProfunctor a -> b
fn1 b -> a
fn2 p a a
f)

-- | An 'Arrow' with the same input and output types can be seen as an 'Invariant' functor.
newtype InvariantArrow c a = InvariantArrow (c a a)

instance Arrow c => Invariant (InvariantArrow c) where
  invmap :: forall a b.
(a -> b) -> (b -> a) -> InvariantArrow c a -> InvariantArrow c b
invmap a -> b
fn1 b -> a
fn2 (InvariantArrow c a a
arrow) = forall {k} (c :: k -> k -> *) (a :: k). c a a -> InvariantArrow c a
InvariantArrow (forall (arr :: * -> * -> *) a b.
Arrow arr =>
(a -> b) -> (b -> a) -> arr a a -> arr b b
invmapArrow a -> b
fn1 b -> a
fn2 c a a
arrow)