{-# 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 (Comonad(..), Cokleisli(..), liftW)

-- 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 = (a -> b) -> (b -> a) -> f a -> f b
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 :: (a -> b) -> (b -> a) -> f a -> f b
invmapFunctor = ((b -> a) -> (a -> b) -> f a -> f b)
-> (a -> b) -> (b -> a) -> f a -> f b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((b -> a) -> (a -> b) -> f a -> f b)
 -> (a -> b) -> (b -> a) -> f a -> f b)
-> ((b -> a) -> (a -> b) -> f a -> f b)
-> (a -> b)
-> (b -> a)
-> f a
-> f b
forall a b. (a -> b) -> a -> b
$ ((a -> b) -> f a -> f b) -> (b -> a) -> (a -> b) -> f a -> f b
forall a b. a -> b -> a
const (a -> b) -> f a -> f b
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 :: (a -> b) -> (b -> a) -> f a -> f b
invmapContravariant = ((b -> a) -> f a -> f b) -> (a -> b) -> (b -> a) -> f a -> f b
forall a b. a -> b -> a
const (b -> a) -> f a -> f b
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> 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 :: (a -> b) -> (b -> a) -> p a a -> p b b
invmapProfunctor = ((b -> a) -> (a -> b) -> p a a -> p b b)
-> (a -> b) -> (b -> a) -> p a a -> p b b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b -> a) -> (a -> b) -> p a a -> p b b
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 :: (a -> b) -> (b -> a) -> arr a a -> arr b b
invmapArrow a -> b
fn1 b -> a
fn2 arr a a
arrow = (a -> b) -> arr a b
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr a -> b
fn1 arr a b -> arr b a -> arr b b
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 arr a a -> arr b a -> arr b a
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. (b -> a) -> arr b a
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr b -> a
fn2

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

instance Invariant Maybe where invmap :: (a -> b) -> (b -> a) -> Maybe a -> Maybe b
invmap = (a -> b) -> (b -> a) -> Maybe a -> Maybe b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant [] where invmap :: (a -> b) -> (b -> a) -> [a] -> [b]
invmap = (a -> b) -> (b -> a) -> [a] -> [b]
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant IO where invmap :: (a -> b) -> (b -> a) -> IO a -> IO b
invmap = (a -> b) -> (b -> a) -> IO a -> IO b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant (Strict.ST s) where invmap :: (a -> b) -> (b -> a) -> ST s a -> ST s b
invmap = (a -> b) -> (b -> a) -> ST s a -> ST s b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant (Lazy.ST s) where invmap :: (a -> b) -> (b -> a) -> ST s a -> ST s b
invmap = (a -> b) -> (b -> a) -> ST s a -> ST s b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ReadP where invmap :: (a -> b) -> (b -> a) -> ReadP a -> ReadP b
invmap = (a -> b) -> (b -> a) -> ReadP a -> ReadP b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ReadPrec where invmap :: (a -> b) -> (b -> a) -> ReadPrec a -> ReadPrec b
invmap = (a -> b) -> (b -> a) -> ReadPrec a -> ReadPrec b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ((->) a) where invmap :: (a -> b) -> (b -> a) -> (a -> a) -> a -> b
invmap = (a -> b) -> (b -> a) -> (a -> a) -> a -> b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant (Either a) where invmap :: (a -> b) -> (b -> a) -> Either a a -> Either a b
invmap = (a -> b) -> (b -> a) -> Either a a -> Either a b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ((,) a) where invmap :: (a -> b) -> (b -> a) -> (a, a) -> (a, b)
invmap = (a -> b) -> (b -> a) -> (a, a) -> (a, b)
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
instance Invariant ((,,) a b) where invmap :: (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 :: (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 :: (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 :: (a -> b) -> (b -> a) -> Const a a -> Const a b
invmap = (a -> b) -> (b -> a) -> Const a a -> Const a b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Control.Applicative"
instance Invariant ZipList where invmap :: (a -> b) -> (b -> a) -> ZipList a -> ZipList b
invmap = (a -> b) -> (b -> a) -> ZipList a -> ZipList b
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 :: (a -> b) -> (b -> a) -> WrappedMonad m a -> WrappedMonad m b
invmap = (a -> b) -> (b -> a) -> WrappedMonad m a -> WrappedMonad m b
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 :: (a -> b)
-> (b -> a) -> WrappedArrow arr a a -> WrappedArrow arr a b
invmap a -> b
f b -> a
_ (App.WrapArrow arr a a
x) = arr a b -> WrappedArrow arr a b
forall (a :: * -> * -> *) b c. a b c -> WrappedArrow a b c
App.WrapArrow (arr a b -> WrappedArrow arr a b)
-> arr a b -> WrappedArrow arr a b
forall a b. (a -> b) -> a -> b
$ (((a -> b) -> arr a b
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr a -> b
f) arr a b -> arr a a -> arr a b
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 :: (a -> b) -> (b -> a) -> ArrowMonad a a -> ArrowMonad a b
invmap a -> b
f b -> a
_ (ArrowMonad a () a
m) = a () b -> ArrowMonad a b
forall (a :: * -> * -> *) b. a () b -> ArrowMonad a b
ArrowMonad (a () a
m a () a -> a a b -> a () b
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (a -> b) -> a a b
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr a -> b
f)
-- | from "Control.Arrow"
instance Monad m => Invariant (Kleisli m a) where
  invmap :: (a -> b) -> (b -> a) -> Kleisli m a a -> Kleisli m a b
invmap = (a -> a)
-> (a -> a)
-> (a -> b)
-> (b -> a)
-> Kleisli m a a
-> Kleisli m 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id

-- | from "Control.Exception"
instance Invariant Handler where
  invmap :: (a -> b) -> (b -> a) -> Handler a -> Handler b
invmap a -> b
f b -> a
_ (Handler e -> IO a
h) = (e -> IO b) -> Handler b
forall a e. Exception e => (e -> IO a) -> Handler a
Handler ((a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (IO a -> IO b) -> (e -> IO a) -> e -> IO b
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 :: (a -> b) -> (b -> a) -> Complex a -> Complex b
invmap a -> b
f b -> a
_ (a
r :+ a
i) = a -> b
f a
r b -> b -> Complex b
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 :: (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) =
    f (g b) -> Compose f g b
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Functor.Compose ((g a -> g b) -> (g b -> g a) -> f (g a) -> f (g b)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (b -> a) -> g a -> g b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> g b -> g a
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 :: (a -> b) -> (b -> a) -> Identity a -> Identity b
invmap = (a -> b) -> (b -> a) -> Identity a -> Identity b
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 :: (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) = f b -> g b -> Product f g b
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Functor.Pair ((a -> b) -> (b -> a) -> f a -> f b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
x) ((a -> b) -> (b -> a) -> g a -> g b
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 :: (a -> b) -> (b -> a) -> Sum f g a -> Sum f g b
invmap a -> b
f b -> a
g (InL f a
x) = f b -> Sum f g b
forall k (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL ((a -> b) -> (b -> a) -> f a -> f b
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) = g b -> Sum f g b
forall k (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR ((a -> b) -> (b -> a) -> g a -> g b
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 :: (a -> b) -> (b -> a) -> NonEmpty a -> NonEmpty b
invmap = (a -> b) -> (b -> a) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from "Data.Monoid"
instance Invariant Dual where
  invmap :: (a -> b) -> (b -> a) -> Dual a -> Dual b
invmap a -> b
f b -> a
_ (Dual a
x) = b -> Dual b
forall a. a -> Dual a
Dual (a -> b
f a
x)
-- | from "Data.Monoid"
instance Invariant Endo where
  invmap :: (a -> b) -> (b -> a) -> Endo a -> Endo b
invmap a -> b
f b -> a
g (Endo a -> a
x) = (b -> b) -> Endo b
forall a. (a -> a) -> Endo a
Endo (a -> b
f (a -> b) -> (b -> a) -> b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
x (a -> a) -> (b -> a) -> b -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a
g)
-- | from "Data.Monoid"
instance Invariant Monoid.First where
  invmap :: (a -> b) -> (b -> a) -> First a -> First b
invmap a -> b
f b -> a
g (Monoid.First Maybe a
x) = Maybe b -> First b
forall a. Maybe a -> First a
Monoid.First ((a -> b) -> (b -> a) -> Maybe a -> Maybe b
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 :: (a -> b) -> (b -> a) -> Last a -> Last b
invmap a -> b
f b -> a
g (Monoid.Last Maybe a
x) = Maybe b -> Last b
forall a. Maybe a -> Last a
Monoid.Last ((a -> b) -> (b -> a) -> Maybe a -> Maybe b
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 :: (a -> b) -> (b -> a) -> Product a -> Product b
invmap a -> b
f b -> a
_ (Monoid.Product a
x) = b -> Product b
forall a. a -> Product a
Monoid.Product (a -> b
f a
x)
-- | from "Data.Monoid"
instance Invariant Monoid.Sum where
  invmap :: (a -> b) -> (b -> a) -> Sum a -> Sum b
invmap a -> b
f b -> a
_ (Monoid.Sum a
x) = b -> Sum b
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 :: (a -> b) -> (b -> a) -> Alt f a -> Alt f b
invmap a -> b
f b -> a
g (Alt f a
x) = f b -> Alt f b
forall k (f :: k -> *) (a :: k). f a -> Alt f a
Alt ((a -> b) -> (b -> a) -> f a -> f b
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 :: (a -> b) -> (b -> a) -> Proxy a -> Proxy b
invmap = (a -> b) -> (b -> a) -> Proxy a -> Proxy b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from "Data.Semigroup"
instance Invariant Min where
  invmap :: (a -> b) -> (b -> a) -> Min a -> Min b
invmap = (a -> b) -> (b -> a) -> Min a -> Min b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Data.Semigroup"
instance Invariant Max where
  invmap :: (a -> b) -> (b -> a) -> Max a -> Max b
invmap = (a -> b) -> (b -> a) -> Max a -> Max b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Data.Semigroup"
instance Invariant Semigroup.First where
  invmap :: (a -> b) -> (b -> a) -> First a -> First b
invmap = (a -> b) -> (b -> a) -> First a -> First b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Data.Semigroup"
instance Invariant Semigroup.Last where
  invmap :: (a -> b) -> (b -> a) -> Last a -> Last b
invmap = (a -> b) -> (b -> a) -> Last a -> Last b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from "Data.Semigroup"
instance Invariant (Arg a) where
  invmap :: (a -> b) -> (b -> a) -> Arg a a -> Arg a b
invmap = (a -> b) -> (b -> a) -> Arg a a -> Arg a b
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 :: (a -> b) -> (b -> a) -> Option a -> Option b
invmap = (a -> b) -> (b -> a) -> Option a -> Option b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
#endif

-- | from "System.Console.GetOpt"
instance Invariant ArgDescr where
  invmap :: (a -> b) -> (b -> a) -> ArgDescr a -> ArgDescr b
invmap a -> b
f b -> a
_ (NoArg a
a)    = b -> ArgDescr b
forall a. a -> ArgDescr a
NoArg (a -> b
f a
a)
  invmap a -> b
f b -> a
_ (ReqArg String -> a
g String
s) = (String -> b) -> String -> ArgDescr b
forall a. (String -> a) -> String -> ArgDescr a
ReqArg (a -> b
f (a -> b) -> (String -> a) -> String -> b
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) = (Maybe String -> b) -> String -> ArgDescr b
forall a. (Maybe String -> a) -> String -> ArgDescr a
OptArg (a -> b
f (a -> b) -> (Maybe String -> a) -> Maybe String -> b
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 :: (a -> b) -> (b -> a) -> ArgOrder a -> ArgOrder b
invmap a -> b
_ b -> a
_ ArgOrder a
RequireOrder      = ArgOrder b
forall a. ArgOrder a
RequireOrder
  invmap a -> b
_ b -> a
_ ArgOrder a
Permute           = ArgOrder b
forall a. ArgOrder a
Permute
  invmap a -> b
f b -> a
_ (ReturnInOrder String -> a
g) = (String -> b) -> ArgOrder b
forall a. (String -> a) -> ArgOrder a
ReturnInOrder (a -> b
f (a -> b) -> (String -> a) -> String -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> a
g)
-- | from "System.Console.GetOpt"
instance Invariant OptDescr where
  invmap :: (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) = String -> [String] -> ArgDescr b -> String -> OptDescr b
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
GetOpt.Option String
a [String]
b ((a -> b) -> (b -> a) -> ArgDescr a -> ArgDescr 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 :: (a -> b) -> (b -> a) -> Array i a -> Array i b
invmap = (a -> b) -> (b -> a) -> Array i a -> Array i b
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 :: (a -> b) -> (b -> a) -> Biff p f g a a -> Biff p f g a b
invmap a -> b
f b -> a
g = p (f a) (g b) -> Biff p f g a b
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 (p (f a) (g b) -> Biff p f g a b)
-> (Biff p f g a a -> p (f a) (g b))
-> Biff p f g a a
-> Biff p f g a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f a -> f a)
-> (f a -> f a)
-> (g a -> g b)
-> (g b -> g a)
-> p (f a) (g a)
-> p (f a) (g b)
forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 f a -> f a
forall a. a -> a
id f a -> f a
forall a. a -> a
id ((a -> b) -> (b -> a) -> g a -> g b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> g b -> g a
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) (p (f a) (g a) -> p (f a) (g b))
-> (Biff p f g a a -> p (f a) (g a))
-> Biff p f g a a
-> p (f a) (g b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Biff p f g a a -> p (f a) (g a)
forall k1 k2 (p :: k1 -> k2 -> *) k3 (f :: k3 -> k1) k4
       (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 :: (a -> b) -> (b -> a) -> Clown f a a -> Clown f a b
invmap = (a -> b) -> (b -> a) -> Clown f a a -> Clown f a b
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 :: (a -> b) -> (b -> a) -> Fix p a -> Fix p b
invmap a -> b
f b -> a
g = p (Fix p b) b -> Fix p b
forall k (p :: * -> k -> *) (a :: k). p (Fix p a) a -> Fix p a
In (p (Fix p b) b -> Fix p b)
-> (Fix p a -> p (Fix p b) b) -> Fix p a -> Fix p b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Fix p a -> Fix p b)
-> (Fix p b -> Fix p a)
-> (a -> b)
-> (b -> a)
-> p (Fix p a) a
-> p (Fix p b) 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 -> b) -> (b -> a) -> Fix p a -> Fix p b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> Fix p b -> Fix p a
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 (p (Fix p a) a -> p (Fix p b) b)
-> (Fix p a -> p (Fix p a) a) -> Fix p a -> p (Fix p b) b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fix p a -> p (Fix p a) a
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 :: (a -> b) -> (b -> a) -> Flip p a a -> Flip p a b
invmap = (a -> a)
-> (a -> a) -> (a -> b) -> (b -> a) -> Flip p a a -> Flip p 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id
-- | from the @bifunctors@ package
instance Invariant2 p => Invariant (Join p) where
  invmap :: (a -> b) -> (b -> a) -> Join p a -> Join p b
invmap a -> b
f b -> a
g = p b b -> Join p b
forall k (p :: k -> k -> *) (a :: k). p a a -> Join p a
Join (p b b -> Join p b) -> (Join p a -> p b b) -> Join p a -> Join p b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> (b -> a) -> (a -> b) -> (b -> a) -> p a a -> p b 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 -> b
f b -> a
g a -> b
f b -> a
g (p a a -> p b b) -> (Join p a -> p a a) -> Join p a -> p b b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Join p a -> p a a
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 :: (a -> b) -> (b -> a) -> Joker g a a -> Joker g a b
invmap a -> b
f b -> a
g = g b -> Joker g a b
forall k k1 (g :: k -> *) (a :: k1) (b :: k). g b -> Joker g a b
Joker (g b -> Joker g a b)
-> (Joker g a a -> g b) -> Joker g a a -> Joker g a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> (b -> a) -> g a -> g b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g (g a -> g b) -> (Joker g a a -> g a) -> Joker g a a -> g b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Joker g a a -> g a
forall k1 (g :: k1 -> *) k2 (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 :: (a -> b) -> (b -> a) -> Tannen f p a a -> Tannen f p a b
invmap = (a -> a)
-> (a -> a)
-> (a -> b)
-> (b -> a)
-> Tannen f p a a
-> Tannen f p 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id
-- | from the @bifunctors@ package
instance Bifunctor p => Invariant (WrappedBifunctor p a) where
  invmap :: (a -> b)
-> (b -> a) -> WrappedBifunctor p a a -> WrappedBifunctor p a b
invmap = (a -> a)
-> (a -> a)
-> (a -> b)
-> (b -> a)
-> WrappedBifunctor p a a
-> WrappedBifunctor p 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id

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

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

-- | from the @contravariant@ package
instance Invariant Predicate where invmap :: (a -> b) -> (b -> a) -> Predicate a -> Predicate b
invmap = (a -> b) -> (b -> a) -> Predicate a -> Predicate b
forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant
-- | from the @contravariant@ package
instance Invariant Comparison where invmap :: (a -> b) -> (b -> a) -> Comparison a -> Comparison b
invmap = (a -> b) -> (b -> a) -> Comparison a -> Comparison b
forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant
-- | from the @contravariant@ package
instance Invariant Equivalence where invmap :: (a -> b) -> (b -> a) -> Equivalence a -> Equivalence b
invmap = (a -> b) -> (b -> a) -> Equivalence a -> Equivalence b
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 :: (a -> b) -> (b -> a) -> Op a a -> Op a b
invmap = (a -> b) -> (b -> a) -> Op a a -> Op a b
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 :: (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) =
    f (g b) -> Compose f g b
forall (f :: * -> *) (g :: * -> *) a. f (g a) -> Compose f g a
Contravariant.Compose (f (g b) -> Compose f g b) -> f (g b) -> Compose f g b
forall a b. (a -> b) -> a -> b
$ (g a -> g b) -> (g b -> g a) -> f (g a) -> f (g b)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (b -> a) -> g a -> g b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> g b -> g a
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 :: (a -> b) -> (b -> a) -> ComposeCF f g a -> ComposeCF f g b
invmap a -> b
f b -> a
g (ComposeCF f (g a)
x) = f (g b) -> ComposeCF f g b
forall (f :: * -> *) (g :: * -> *) a. f (g a) -> ComposeCF f g a
ComposeCF (f (g b) -> ComposeCF f g b) -> f (g b) -> ComposeCF f g b
forall a b. (a -> b) -> a -> b
$ (g a -> g b) -> (g b -> g a) -> f (g a) -> f (g b)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (b -> a) -> g a -> g b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> g b -> g a
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 :: (a -> b) -> (b -> a) -> ComposeFC f g a -> ComposeFC f g b
invmap a -> b
f b -> a
g (ComposeFC f (g a)
x) = f (g b) -> ComposeFC f g b
forall (f :: * -> *) (g :: * -> *) a. f (g a) -> ComposeFC f g a
ComposeFC (f (g b) -> ComposeFC f g b) -> f (g b) -> ComposeFC f g b
forall a b. (a -> b) -> a -> b
$ (g a -> g b) -> (g b -> g a) -> f (g a) -> f (g b)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (b -> a) -> g a -> g b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> g b -> g a
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 :: (a -> b) -> (b -> a) -> Star f a a -> Star f a b
invmap = (a -> a)
-> (a -> a) -> (a -> b) -> (b -> a) -> Star f a a -> Star f 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (Costar f a) where
  invmap :: (a -> b) -> (b -> a) -> Costar f a a -> Costar f a b
invmap = (a -> b) -> (b -> a) -> Costar f a a -> Costar f a b
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 :: (a -> b)
-> (b -> a) -> WrappedArrow arr a a -> WrappedArrow arr a b
invmap a -> b
f b -> a
_ (Pro.WrapArrow arr a a
x) = arr a b -> WrappedArrow arr a b
forall k k1 (p :: k -> k1 -> *) (a :: k) (b :: k1).
p a b -> WrappedArrow p a b
Pro.WrapArrow (arr a b -> WrappedArrow arr a b)
-> arr a b -> WrappedArrow arr a b
forall a b. (a -> b) -> a -> b
$ (((a -> b) -> arr a b
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr a -> b
f) arr a b -> arr a a -> arr a b
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 :: (a -> b) -> (b -> a) -> Forget r a a -> Forget r a b
invmap = (a -> b) -> (b -> a) -> Forget r a a -> Forget r a b
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 :: (a -> b) -> (b -> a) -> Closure p a a -> Closure p a b
invmap = (a -> a)
-> (a -> a)
-> (a -> b)
-> (b -> a)
-> Closure p a a
-> Closure p 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Codensity p a) where
  invmap :: (a -> b) -> (b -> a) -> Codensity p a a -> Codensity p a b
invmap = (a -> a)
-> (a -> a)
-> (a -> b)
-> (b -> a)
-> Codensity p a a
-> Codensity p 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Coprep p) where
  invmap :: (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 r. p b r -> r) -> Coprep p b
forall k (p :: k -> * -> *) (a :: k).
(forall r. p a r -> r) -> Coprep p a
Coprep (p a r -> r
forall r. p a r -> r
h (p a r -> r) -> (p b r -> p a r) -> p b r -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> a) -> (a -> b) -> (r -> r) -> (r -> r) -> p b r -> p a r
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 r -> r
forall a. a -> a
id r -> r
forall a. a -> a
id)
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Prep p) where
  invmap :: (a -> b) -> (b -> a) -> Prep p a -> Prep p b
invmap a -> b
f b -> a
g (Prep x
x p x a
p) = x -> p x b -> Prep p b
forall k x (p :: * -> k -> *) (a :: k). x -> p x a -> Prep p a
Prep x
x ((x -> x) -> (x -> x) -> (a -> b) -> (b -> a) -> p x a -> p x b
forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 x -> x
forall a. a -> a
id x -> x
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 :: (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) = p x b -> q a x -> Procompose p q a b
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 ((x -> x) -> (x -> x) -> (a -> b) -> (b -> a) -> p x a -> p x b
forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 x -> x
forall a. a -> a
id x -> x
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 :: (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 x. p b x -> q a x) -> Rift p q a b
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 (p a x -> q a x
forall x. p a x -> q a x
f (p a x -> q a x) -> (p b x -> p a x) -> p b x -> q a x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> a) -> (a -> b) -> (x -> x) -> (x -> x) -> p b x -> p a x
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 x -> x
forall a. a -> a
id x -> x
forall a. a -> a
id)
-- | from the @profunctors@ package
instance Invariant2 q => Invariant (Ran p q a) where
  invmap :: (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 x. p x a -> q x b) -> Ran p q a b
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 ((x -> x) -> (x -> x) -> (a -> b) -> (b -> a) -> q x a -> q x b
forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 x -> x
forall a. a -> a
id x -> x
forall a. a -> a
id a -> b
bd b -> a
db (q x a -> q x b) -> (p x a -> q x a) -> p x a -> q x b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p x a -> q x a
forall x. p x a -> q x a
f)
-- | from the @profunctors@ package
instance Invariant2 p => Invariant (Tambara p a) where
  invmap :: (a -> b) -> (b -> a) -> Tambara p a a -> Tambara p a b
invmap = (a -> a)
-> (a -> a)
-> (a -> b)
-> (b -> a)
-> Tambara p a a
-> Tambara p 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (Cotambara p a) where
  invmap :: (a -> b) -> (b -> a) -> Cotambara p a a -> Cotambara p a b
invmap = (a -> b) -> (b -> a) -> Cotambara p a a -> Cotambara p a b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor
-- | from the @profunctors@ package
instance Invariant (CotambaraSum p a) where
  invmap :: (a -> b) -> (b -> a) -> CotambaraSum p a a -> CotambaraSum p a b
invmap = (a -> b) -> (b -> a) -> CotambaraSum p a a -> CotambaraSum p a b
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 :: (a -> b) -> (b -> a) -> TambaraSum p a a -> TambaraSum p a b
invmap = (a -> a)
-> (a -> a)
-> (a -> b)
-> (b -> a)
-> TambaraSum p a a
-> TambaraSum p 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id
-- | from the @profunctors@ package
instance Invariant (Yoneda p a) where
  invmap :: (a -> b) -> (b -> a) -> Yoneda p a a -> Yoneda p a b
invmap = (a -> b) -> (b -> a) -> Yoneda p a a -> Yoneda p a b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

-- | from the @StateVar@ package
instance Invariant StateVar where
  invmap :: (a -> b) -> (b -> a) -> StateVar a -> StateVar b
invmap a -> b
f b -> a
g (StateVar IO a
ga a -> IO ()
sa) = IO b -> (b -> IO ()) -> StateVar b
forall a. IO a -> (a -> IO ()) -> StateVar a
StateVar ((a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f IO a
ga) ((b -> a) -> (a -> IO ()) -> b -> IO ()
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 :: (a -> b) -> (b -> a) -> SettableStateVar a -> SettableStateVar b
invmap = (a -> b) -> (b -> a) -> SettableStateVar a -> SettableStateVar b
forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant

-- | from the @stm@ package
instance Invariant STM where
  invmap :: (a -> b) -> (b -> a) -> STM a -> STM b
invmap = (a -> b) -> (b -> a) -> STM a -> STM b
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 :: (a -> b) -> (b -> a) -> Tagged s a -> Tagged s b
invmap = (a -> b) -> (b -> a) -> Tagged s a -> Tagged s b
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 :: (a -> b) -> (b -> a) -> Backwards f a -> Backwards f b
invmap a -> b
f b -> a
g (Backwards f a
a) = f b -> Backwards f b
forall k (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards ((a -> b) -> (b -> a) -> f a -> f b
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 :: (a -> b) -> (b -> a) -> Lift f a -> Lift f b
invmap a -> b
f b -> a
_ (Pure a
x)  = b -> Lift f b
forall (f :: * -> *) a. a -> Lift f a
Pure (a -> b
f a
x)
  invmap a -> b
f b -> a
g (Other f a
y) = f b -> Lift f b
forall (f :: * -> *) a. f a -> Lift f a
Other ((a -> b) -> (b -> a) -> f a -> f b
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 :: (a -> b) -> (b -> a) -> ContT r m a -> ContT r m b
invmap = (a -> b) -> (b -> a) -> ContT r m a -> ContT r m b
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 :: (a -> b) -> (b -> a) -> ExceptT e m a -> ExceptT e m b
invmap a -> b
f b -> a
g = m (Either e b) -> ExceptT e m b
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (m (Either e b) -> ExceptT e m b)
-> (ExceptT e m a -> m (Either e b))
-> ExceptT e m a
-> ExceptT e m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either e a -> Either e b)
-> (Either e b -> Either e a) -> m (Either e a) -> m (Either e b)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (b -> a) -> Either e a -> Either e b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> Either e b -> Either e a
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) (m (Either e a) -> m (Either e b))
-> (ExceptT e m a -> m (Either e a))
-> ExceptT e m a
-> m (Either e b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT e m a -> m (Either e a)
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 :: (a -> b) -> (b -> a) -> IdentityT m a -> IdentityT m b
invmap a -> b
f b -> a
g = (m a -> m b) -> IdentityT m a -> IdentityT m b
forall k1 k2 (m :: k1 -> *) (a :: k1) (n :: k2 -> *) (b :: k2).
(m a -> n b) -> IdentityT m a -> IdentityT n b
mapIdentityT ((a -> b) -> (b -> a) -> m a -> m b
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 :: (a -> b) -> (b -> a) -> MaybeT m a -> MaybeT m b
invmap a -> b
f b -> a
g = (m (Maybe a) -> m (Maybe b)) -> MaybeT m a -> MaybeT m b
forall (m :: * -> *) a (n :: * -> *) b.
(m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b
mapMaybeT ((m (Maybe a) -> m (Maybe b)) -> MaybeT m a -> MaybeT m b)
-> (m (Maybe a) -> m (Maybe b)) -> MaybeT m a -> MaybeT m b
forall a b. (a -> b) -> a -> b
$ (Maybe a -> Maybe b)
-> (Maybe b -> Maybe a) -> m (Maybe a) -> m (Maybe b)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (b -> a) -> Maybe a -> Maybe b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> Maybe b -> Maybe a
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 :: (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 = (r -> s -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Lazy.RWST ((r -> s -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \r
r s
s ->
    ((a, s, w) -> (b, s, w))
-> ((b, s, w) -> (a, s, w)) -> m (a, s, w) -> m (b, s, w)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (a, s, w) -> (b, s, w)
forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple a -> b
f) ((b -> a) -> (b, s, w) -> (a, s, w)
forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple b -> a
g) (m (a, s, w) -> m (b, s, w)) -> m (a, s, w) -> m (b, s, w)
forall a b. (a -> b) -> a -> b
$ RWST r w s m a -> r -> s -> m (a, s, w)
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 :: (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 :: (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 = (r -> s -> m (b, s, w)) -> RWST r w s m b
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST ((r -> s -> m (b, s, w)) -> RWST r w s m b)
-> (r -> s -> m (b, s, w)) -> RWST r w s m b
forall a b. (a -> b) -> a -> b
$ \r
r s
s ->
    ((a, s, w) -> (b, s, w))
-> ((b, s, w) -> (a, s, w)) -> m (a, s, w) -> m (b, s, w)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (a, s, w) -> (b, s, w)
forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple a -> b
f) ((b -> a) -> (b, s, w) -> (a, s, w)
forall a b c d. (a -> b) -> (a, c, d) -> (b, c, d)
mapFstTriple b -> a
g) (m (a, s, w) -> m (b, s, w)) -> m (a, s, w) -> m (b, s, w)
forall a b. (a -> b) -> a -> b
$ RWST r w s m a -> r -> s -> m (a, s, w)
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 :: (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 :: (a -> b) -> (b -> a) -> ReaderT r m a -> ReaderT r m b
invmap a -> b
f b -> a
g = (m a -> m b) -> ReaderT r m a -> ReaderT r m b
forall (m :: * -> *) a (n :: * -> *) b r.
(m a -> n b) -> ReaderT r m a -> ReaderT r n b
mapReaderT ((a -> b) -> (b -> a) -> m a -> m b
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 :: (a -> b) -> (b -> a) -> StateT s m a -> StateT s m b
invmap a -> b
f b -> a
g StateT s m a
m = (s -> m (b, s)) -> StateT s m b
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Lazy.StateT ((s -> m (b, s)) -> StateT s m b)
-> (s -> m (b, s)) -> StateT s m b
forall a b. (a -> b) -> a -> b
$ \s
s ->
    ((a, s) -> (b, s)) -> ((b, s) -> (a, s)) -> m (a, s) -> m (b, s)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (a, s) -> (b, s)
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
f) ((b -> a) -> (b, s) -> (a, s)
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair b -> a
g) (m (a, s) -> m (b, s)) -> m (a, s) -> m (b, s)
forall a b. (a -> b) -> a -> b
$ StateT s m a -> s -> m (a, s)
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 :: (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 :: (a -> b) -> (b -> a) -> StateT s m a -> StateT s m b
invmap a -> b
f b -> a
g StateT s m a
m = (s -> m (b, s)) -> StateT s m b
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Strict.StateT ((s -> m (b, s)) -> StateT s m b)
-> (s -> m (b, s)) -> StateT s m b
forall a b. (a -> b) -> a -> b
$ \s
s ->
    ((a, s) -> (b, s)) -> ((b, s) -> (a, s)) -> m (a, s) -> m (b, s)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (a, s) -> (b, s)
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
f) ((b -> a) -> (b, s) -> (a, s)
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair b -> a
g) (m (a, s) -> m (b, s)) -> m (a, s) -> m (b, s)
forall a b. (a -> b) -> a -> b
$ StateT s m a -> s -> m (a, s)
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 :: (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 :: (a -> b) -> (b -> a) -> WriterT w m a -> WriterT w m b
invmap a -> b
f b -> a
g = (m (a, w) -> m (b, w)) -> WriterT w m a -> WriterT w m b
forall (m :: * -> *) a w (n :: * -> *) b w'.
(m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
Lazy.mapWriterT ((m (a, w) -> m (b, w)) -> WriterT w m a -> WriterT w m b)
-> (m (a, w) -> m (b, w)) -> WriterT w m a -> WriterT w m b
forall a b. (a -> b) -> a -> b
$ ((a, w) -> (b, w)) -> ((b, w) -> (a, w)) -> m (a, w) -> m (b, w)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (a, w) -> (b, w)
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
f) ((b -> a) -> (b, w) -> (a, w)
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair b -> a
g)
    where mapFstPair :: (a -> b) -> (a, c) -> (b, c)
          mapFstPair :: (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 :: (a -> b) -> (b -> a) -> WriterT w m a -> WriterT w m b
invmap a -> b
f b -> a
g = (m (a, w) -> m (b, w)) -> WriterT w m a -> WriterT w m b
forall (m :: * -> *) a w (n :: * -> *) b w'.
(m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
Strict.mapWriterT ((m (a, w) -> m (b, w)) -> WriterT w m a -> WriterT w m b)
-> (m (a, w) -> m (b, w)) -> WriterT w m a -> WriterT w m b
forall a b. (a -> b) -> a -> b
$ ((a, w) -> (b, w)) -> ((b, w) -> (a, w)) -> m (a, w) -> m (b, w)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (a, w) -> (b, w)
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair a -> b
f) ((b -> a) -> (b, w) -> (a, w)
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFstPair b -> a
g)
    where mapFstPair :: (a -> b) -> (a, c) -> (b, c)
          mapFstPair :: (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 :: (a -> b) -> (b -> a) -> Constant a a -> Constant a b
invmap = (a -> b) -> (b -> a) -> Constant a a -> Constant a b
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 :: (a -> b) -> (b -> a) -> Reverse f a -> Reverse f b
invmap a -> b
f b -> a
g (Reverse f a
a) = f b -> Reverse f b
forall k (f :: k -> *) (a :: k). f a -> Reverse f a
Reverse ((a -> b) -> (b -> a) -> f a -> f b
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 :: (a -> b) -> (b -> a) -> ErrorT e m a -> ErrorT e m b
invmap a -> b
f b -> a
g = m (Either e b) -> ErrorT e m b
forall e (m :: * -> *) a. m (Either e a) -> ErrorT e m a
ErrorT (m (Either e b) -> ErrorT e m b)
-> (ErrorT e m a -> m (Either e b)) -> ErrorT e m a -> ErrorT e m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either e a -> Either e b)
-> (Either e b -> Either e a) -> m (Either e a) -> m (Either e b)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (b -> a) -> Either e a -> Either e b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> Either e b -> Either e a
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> a
g a -> b
f) (m (Either e a) -> m (Either e b))
-> (ErrorT e m a -> m (Either e a))
-> ErrorT e m a
-> m (Either e b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorT e m a -> m (Either e a)
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 :: (a -> b) -> (b -> a) -> ListT m a -> ListT m b
invmap a -> b
f b -> a
g = (m [a] -> m [b]) -> ListT m a -> ListT m b
forall (m :: * -> *) a (n :: * -> *) b.
(m [a] -> n [b]) -> ListT m a -> ListT n b
mapListT ((m [a] -> m [b]) -> ListT m a -> ListT m b)
-> (m [a] -> m [b]) -> ListT m a -> ListT m b
forall a b. (a -> b) -> a -> b
$ ([a] -> [b]) -> ([b] -> [a]) -> m [a] -> m [b]
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (b -> a) -> [a] -> [b]
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> [b] -> [a]
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 :: (a -> b) -> (b -> a) -> HashMap k a -> HashMap k b
invmap = (a -> b) -> (b -> a) -> HashMap k a -> HashMap k b
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 { WrappedFunctor f a -> f a
unwrapFunctor :: f a }
  deriving (WrappedFunctor f a -> WrappedFunctor f a -> Bool
(WrappedFunctor f a -> WrappedFunctor f a -> Bool)
-> (WrappedFunctor f a -> WrappedFunctor f a -> Bool)
-> Eq (WrappedFunctor f a)
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, Eq (WrappedFunctor f a)
Eq (WrappedFunctor f a)
-> (WrappedFunctor f a -> WrappedFunctor f a -> Ordering)
-> (WrappedFunctor f a -> WrappedFunctor f a -> Bool)
-> (WrappedFunctor f a -> WrappedFunctor f a -> Bool)
-> (WrappedFunctor f a -> WrappedFunctor f a -> Bool)
-> (WrappedFunctor f a -> WrappedFunctor f a -> Bool)
-> (WrappedFunctor f a -> WrappedFunctor f a -> WrappedFunctor f a)
-> (WrappedFunctor f a -> WrappedFunctor f a -> WrappedFunctor f a)
-> Ord (WrappedFunctor f a)
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
$cp1Ord :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Eq (WrappedFunctor f a)
Ord, ReadPrec [WrappedFunctor f a]
ReadPrec (WrappedFunctor f a)
Int -> ReadS (WrappedFunctor f a)
ReadS [WrappedFunctor f a]
(Int -> ReadS (WrappedFunctor f a))
-> ReadS [WrappedFunctor f a]
-> ReadPrec (WrappedFunctor f a)
-> ReadPrec [WrappedFunctor f a]
-> Read (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
[WrappedFunctor f a] -> ShowS
WrappedFunctor f a -> String
(Int -> WrappedFunctor f a -> ShowS)
-> (WrappedFunctor f a -> String)
-> ([WrappedFunctor f a] -> ShowS)
-> Show (WrappedFunctor f a)
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 :: (a -> b) -> (b -> a) -> WrappedFunctor f a -> WrappedFunctor f b
invmap = (a -> b) -> (b -> a) -> WrappedFunctor f a -> WrappedFunctor f b
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapFunctor

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

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

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

instance Monad m => Monad (WrappedFunctor m) where
  WrapFunctor m a
x >>= :: WrappedFunctor m a
-> (a -> WrappedFunctor m b) -> WrappedFunctor m b
>>= a -> WrappedFunctor m b
f = m b -> WrappedFunctor m b
forall k (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (m a
x m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= WrappedFunctor m b -> m b
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor (WrappedFunctor m b -> m b)
-> (a -> WrappedFunctor m b) -> a -> m b
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 :: WrappedFunctor m a
mzero = m a -> WrappedFunctor m a
forall k (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
  WrapFunctor m a
x mplus :: WrappedFunctor m a -> WrappedFunctor m a -> WrappedFunctor m a
`mplus` WrapFunctor m a
y = m a -> WrappedFunctor m a
forall k (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (m a
x m a -> m a -> m a
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 :: WrappedFunctor f m -> m
fold       = f m -> m
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
F.fold       (f m -> m)
-> (WrappedFunctor f m -> f m) -> WrappedFunctor f m -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f m -> f m
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldMap :: (a -> m) -> WrappedFunctor f a -> m
foldMap a -> m
f  = (a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
F.foldMap a -> m
f  (f a -> m)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldr :: (a -> b -> b) -> b -> WrappedFunctor f a -> b
foldr a -> b -> b
f b
z  = (a -> b -> b) -> b -> f a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr a -> b -> b
f b
z  (f a -> b)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldl :: (b -> a -> b) -> b -> WrappedFunctor f a -> b
foldl b -> a -> b
f b
q  = (b -> a -> b) -> b -> f a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl b -> a -> b
f b
q  (f a -> b)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldr1 :: (a -> a -> a) -> WrappedFunctor f a -> a
foldr1 a -> a -> a
f   = (a -> a -> a) -> f a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
F.foldr1 a -> a -> a
f   (f a -> a)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldl1 :: (a -> a -> a) -> WrappedFunctor f a -> a
foldl1 a -> a -> a
f   = (a -> a -> a) -> f a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
F.foldl1 a -> a -> a
f   (f a -> a)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
#if MIN_VERSION_base(4,6,0)
  foldr' :: (a -> b -> b) -> b -> WrappedFunctor f a -> b
foldr' a -> b -> b
f b
z = (a -> b -> b) -> b -> f a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr' a -> b -> b
f b
z (f a -> b)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  foldl' :: (b -> a -> b) -> b -> WrappedFunctor f a -> b
foldl' b -> a -> b
f b
q = (b -> a -> b) -> b -> f a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' b -> a -> b
f b
q (f a -> b)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
#endif
#if MIN_VERSION_base(4,8,0)
  toList :: WrappedFunctor f a -> [a]
toList     = f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList     (f a -> [a])
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  null :: WrappedFunctor f a -> Bool
null       = f a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
F.null       (f a -> Bool)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  length :: WrappedFunctor f a -> Int
length     = f a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
F.length     (f a -> Int)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  elem :: a -> WrappedFunctor f a -> Bool
elem a
x     = a -> f a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
F.elem a
x     (f a -> Bool)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  maximum :: WrappedFunctor f a -> a
maximum    = f a -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
F.maximum    (f a -> a)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  minimum :: WrappedFunctor f a -> a
minimum    = f a -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
F.minimum    (f a -> a)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  sum :: WrappedFunctor f a -> a
sum        = f a -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
F.sum        (f a -> a)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  product :: WrappedFunctor f a -> a
product    = f a -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
F.product    (f a -> a)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
#endif
#if MIN_VERSION_base(4,13,0)
  foldMap' :: (a -> m) -> WrappedFunctor f a -> m
foldMap' a -> m
f = (a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
F.foldMap' a -> m
f (f a -> m)
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
#endif

instance T.Traversable f => T.Traversable (WrappedFunctor f) where
  traverse :: (a -> f b) -> WrappedFunctor f a -> f (WrappedFunctor f b)
traverse a -> f b
f = (f b -> WrappedFunctor f b) -> f (f b) -> f (WrappedFunctor f b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap  f b -> WrappedFunctor f b
forall k (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (f (f b) -> f (WrappedFunctor f b))
-> (WrappedFunctor f a -> f (f b))
-> WrappedFunctor f a
-> f (WrappedFunctor f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> f a -> f (f b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
T.traverse a -> f b
f (f a -> f (f b))
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> f (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  sequenceA :: WrappedFunctor f (f a) -> f (WrappedFunctor f a)
sequenceA  = (f a -> WrappedFunctor f a) -> f (f a) -> f (WrappedFunctor f a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap  f a -> WrappedFunctor f a
forall k (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (f (f a) -> f (WrappedFunctor f a))
-> (WrappedFunctor f (f a) -> f (f a))
-> WrappedFunctor f (f a)
-> f (WrappedFunctor f a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (f a) -> f (f a)
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
T.sequenceA  (f (f a) -> f (f a))
-> (WrappedFunctor f (f a) -> f (f a))
-> WrappedFunctor f (f a)
-> f (f a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f (f a) -> f (f a)
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  mapM :: (a -> m b) -> WrappedFunctor f a -> m (WrappedFunctor f b)
mapM a -> m b
f     = (f b -> WrappedFunctor f b) -> m (f b) -> m (WrappedFunctor f b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM f b -> WrappedFunctor f b
forall k (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (m (f b) -> m (WrappedFunctor f b))
-> (WrappedFunctor f a -> m (f b))
-> WrappedFunctor f a
-> m (WrappedFunctor f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m b) -> f a -> m (f b)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
T.mapM a -> m b
f     (f a -> m (f b))
-> (WrappedFunctor f a -> f a) -> WrappedFunctor f a -> m (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f a -> f a
forall k (f :: k -> *) (a :: k). WrappedFunctor f a -> f a
unwrapFunctor
  sequence :: WrappedFunctor f (m a) -> m (WrappedFunctor f a)
sequence   = (f a -> WrappedFunctor f a) -> m (f a) -> m (WrappedFunctor f a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM f a -> WrappedFunctor f a
forall k (f :: k -> *) (a :: k). f a -> WrappedFunctor f a
WrapFunctor (m (f a) -> m (WrappedFunctor f a))
-> (WrappedFunctor f (m a) -> m (f a))
-> WrappedFunctor f (m a)
-> m (WrappedFunctor f a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (m a) -> m (f a)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
T.sequence   (f (m a) -> m (f a))
-> (WrappedFunctor f (m a) -> f (m a))
-> WrappedFunctor f (m a)
-> m (f a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedFunctor f (m a) -> f (m a)
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 { WrappedContravariant f a -> f a
unwrapContravariant :: f a }
  deriving (WrappedContravariant f a -> WrappedContravariant f a -> Bool
(WrappedContravariant f a -> WrappedContravariant f a -> Bool)
-> (WrappedContravariant f a -> WrappedContravariant f a -> Bool)
-> Eq (WrappedContravariant f a)
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, Eq (WrappedContravariant f a)
Eq (WrappedContravariant f a)
-> (WrappedContravariant f a
    -> WrappedContravariant f a -> Ordering)
-> (WrappedContravariant f a -> WrappedContravariant f a -> Bool)
-> (WrappedContravariant f a -> WrappedContravariant f a -> Bool)
-> (WrappedContravariant f a -> WrappedContravariant f a -> Bool)
-> (WrappedContravariant f a -> WrappedContravariant f a -> Bool)
-> (WrappedContravariant f a
    -> WrappedContravariant f a -> WrappedContravariant f a)
-> (WrappedContravariant f a
    -> WrappedContravariant f a -> WrappedContravariant f a)
-> Ord (WrappedContravariant f a)
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
$cp1Ord :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Eq (WrappedContravariant f a)
Ord, ReadPrec [WrappedContravariant f a]
ReadPrec (WrappedContravariant f a)
Int -> ReadS (WrappedContravariant f a)
ReadS [WrappedContravariant f a]
(Int -> ReadS (WrappedContravariant f a))
-> ReadS [WrappedContravariant f a]
-> ReadPrec (WrappedContravariant f a)
-> ReadPrec [WrappedContravariant f a]
-> Read (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
[WrappedContravariant f a] -> ShowS
WrappedContravariant f a -> String
(Int -> WrappedContravariant f a -> ShowS)
-> (WrappedContravariant f a -> String)
-> ([WrappedContravariant f a] -> ShowS)
-> Show (WrappedContravariant f a)
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 :: (a -> b)
-> (b -> a) -> WrappedContravariant f a -> WrappedContravariant f b
invmap = (a -> b)
-> (b -> a) -> WrappedContravariant f a -> WrappedContravariant f b
forall (f :: * -> *) a b.
Contravariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmapContravariant

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

instance Divisible f => Divisible (WrappedContravariant f) where
  divide :: (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) =
    f a -> WrappedContravariant f a
forall k (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant (f a -> WrappedContravariant f a)
-> f a -> WrappedContravariant f a
forall a b. (a -> b) -> a -> b
$ (a -> (b, c)) -> f b -> f c -> f a
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 :: WrappedContravariant f a
conquer = f a -> WrappedContravariant f a
forall k (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant f a
forall (f :: * -> *) a. Divisible f => f a
conquer

instance Decidable f => Decidable (WrappedContravariant f) where
  lose :: (a -> Void) -> WrappedContravariant f a
lose = f a -> WrappedContravariant f a
forall k (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant (f a -> WrappedContravariant f a)
-> ((a -> Void) -> f a) -> (a -> Void) -> WrappedContravariant f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Void) -> f a
forall (f :: * -> *) a. Decidable f => (a -> Void) -> f a
lose
  choose :: (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) =
    f a -> WrappedContravariant f a
forall k (f :: k -> *) (a :: k). f a -> WrappedContravariant f a
WrapContravariant (f a -> WrappedContravariant f a)
-> f a -> WrappedContravariant f a
forall a b. (a -> b) -> a -> b
$ (a -> Either b c) -> f b -> f c -> f a
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 :: (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
_ = (a -> c) -> (b -> d) -> f a b -> f c d
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 :: (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
_ = (c -> a) -> (b -> d) -> f a b -> f c d
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 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> (a -> b) -> c -> d
invmap2 = (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> (a -> b) -> c -> d
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 :: (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Either a b -> Either c d
invmap2 = (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Either a b -> Either c d
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 :: (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 :: (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 :: (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 :: (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 :: (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Const a b -> Const c d
invmap2 = (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Const a b -> Const c d
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 :: (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) = arr c d -> WrappedArrow arr c d
forall (a :: * -> * -> *) b c. a b c -> WrappedArrow a b c
App.WrapArrow (arr c d -> WrappedArrow arr c d)
-> arr c d -> WrappedArrow arr c d
forall a b. (a -> b) -> a -> b
$ (b -> d) -> arr b d
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr b -> d
g arr b d -> arr c b -> arr c d
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 arr a b -> arr c a -> arr c b
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. (c -> a) -> arr c a
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr c -> a
f'

-- | from "Control.Arrow"
instance Monad m => Invariant2 (Kleisli m) where
  invmap2 :: (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
_ (Kleisli a -> m b
m) = (c -> m d) -> Kleisli m c d
forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Kleisli ((c -> m d) -> Kleisli m c d) -> (c -> m d) -> Kleisli m c d
forall a b. (a -> b) -> a -> b
$ (b -> d) -> m b -> m d
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM b -> d
g (m b -> m d) -> (c -> m b) -> c -> m d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m b
m (a -> m b) -> (c -> a) -> c -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> a
f'

-- | from "Data.Semigroup"
instance Invariant2 Arg where
  invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> Arg a b -> Arg c d
invmap2 = (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> Arg a b -> Arg c d
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 :: (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' =
    p (f c) (g d) -> Biff p f g c d
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 (p (f c) (g d) -> Biff p f g c d)
-> (Biff p f g a b -> p (f c) (g d))
-> Biff p f g a b
-> Biff p f g c d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f a -> f c)
-> (f c -> f a)
-> (g b -> g d)
-> (g d -> g b)
-> p (f a) (g b)
-> p (f c) (g d)
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) -> (c -> a) -> f a -> f c
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> c
f c -> a
f') ((c -> a) -> (a -> c) -> f c -> f a
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap c -> a
f' a -> c
f) ((b -> d) -> (d -> b) -> g b -> g d
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> d
g d -> b
g') ((d -> b) -> (b -> d) -> g d -> g b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap d -> b
g' b -> d
g) (p (f a) (g b) -> p (f c) (g d))
-> (Biff p f g a b -> p (f a) (g b))
-> Biff p f g a b
-> p (f c) (g d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Biff p f g a b -> p (f a) (g b)
forall k1 k2 (p :: k1 -> k2 -> *) k3 (f :: k3 -> k1) k4
       (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 :: (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
_ = f c -> Clown f c d
forall k k1 (f :: k -> *) (a :: k) (b :: k1). f a -> Clown f a b
Clown (f c -> Clown f c d)
-> (Clown f a b -> f c) -> Clown f a b -> Clown f c d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> c) -> (c -> a) -> f a -> f c
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> c
f c -> a
f' (f a -> f c) -> (Clown f a b -> f a) -> Clown f a b -> f c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a b -> f a
forall k1 (f :: k1 -> *) (a :: k1) k2 (b :: k2). Clown f a b -> f a
runClown
-- | from the @bifunctors@ package
instance Invariant2 p => Invariant2 (Flip p) where
  invmap2 :: (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' = p d c -> Flip p c d
forall k k1 (p :: k -> k1 -> *) (a :: k1) (b :: k).
p b a -> Flip p a b
Flip (p d c -> Flip p c d)
-> (Flip p a b -> p d c) -> Flip p a b -> Flip p c d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> d) -> (d -> b) -> (a -> c) -> (c -> a) -> p b a -> p d 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' (p b a -> p d c) -> (Flip p a b -> p b a) -> Flip p a b -> p d c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a b -> p b a
forall k1 k2 (p :: k2 -> k1 -> *) (a :: k1) (b :: k2).
Flip p a b -> p b a
runFlip
-- | from the @bifunctors@ package
instance Invariant g => Invariant2 (Joker g) where
  invmap2 :: (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' = g d -> Joker g c d
forall k k1 (g :: k -> *) (a :: k1) (b :: k). g b -> Joker g a b
Joker (g d -> Joker g c d)
-> (Joker g a b -> g d) -> Joker g a b -> Joker g c d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> d) -> (d -> b) -> g b -> g d
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> d
g d -> b
g' (g b -> g d) -> (Joker g a b -> g b) -> Joker g a b -> g d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Joker g a b -> g b
forall k1 (g :: k1 -> *) k2 (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 :: (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) =
    f c d -> g c d -> Product f g c d
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 ((a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
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) ((a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> g a b -> g c d
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 :: (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) = p c d -> Sum p q c d
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
       (b :: k1).
p a b -> Sum p q a b
Bifunctor.L2 ((a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> p a b -> p c d
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) = q c d -> Sum p q c d
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
       (b :: k1).
q a b -> Sum p q a b
Bifunctor.R2 ((a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> q a b -> q c d
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 :: (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' =
    f (p c d) -> Tannen f p c d
forall k k1 k2 (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Tannen f p a b
Tannen (f (p c d) -> Tannen f p c d)
-> (Tannen f p a b -> f (p c d))
-> Tannen f p a b
-> Tannen f p c d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (p a b -> p c d) -> (p c d -> p a b) -> f (p a b) -> f (p c d)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> p a b -> p c d
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') ((c -> a) -> (a -> c) -> (d -> b) -> (b -> d) -> p c d -> p 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 c -> a
f' a -> c
f d -> b
g' b -> d
g) (f (p a b) -> f (p c d))
-> (Tannen f p a b -> f (p a b)) -> Tannen f p a b -> f (p c d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tannen f p a b -> f (p a b)
forall k1 (f :: k1 -> *) k2 k3 (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 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> WrappedBifunctor p a b
-> WrappedBifunctor p c d
invmap2 = (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> WrappedBifunctor p a b
-> WrappedBifunctor p c d
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 Comonad w => Invariant2 (Cokleisli w) where
   invmap2 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Cokleisli w a b
-> Cokleisli w c d
invmap2 a -> c
_ c -> a
f' b -> d
g d -> b
_ (Cokleisli w a -> b
w) = (w c -> d) -> Cokleisli w c d
forall k (w :: k -> *) (a :: k) b. (w a -> b) -> Cokleisli w a b
Cokleisli ((w c -> d) -> Cokleisli w c d) -> (w c -> d) -> Cokleisli w c d
forall a b. (a -> b) -> a -> b
$ b -> d
g (b -> d) -> (w c -> b) -> w c -> d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. w a -> b
w (w a -> b) -> (w c -> w a) -> w c -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a) -> w c -> w a
forall (w :: * -> *) a b. Comonad w => (a -> b) -> w a -> w b
liftW c -> a
f'

-- | from the @contravariant@ package
instance Invariant2 Op where
  invmap2 :: (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) = (d -> c) -> Op c d
forall a b. (b -> a) -> Op a b
Op ((d -> c) -> Op c d) -> (d -> c) -> Op c d
forall a b. (a -> b) -> a -> b
$ (b -> d) -> (d -> b) -> (a -> c) -> (c -> a) -> (b -> a) -> d -> 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' b -> a
x

-- | from the @profunctors@ package
instance Invariant f => Invariant2 (Star f) where
  invmap2 :: (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) = (c -> f d) -> Star f c d
forall k (f :: k -> *) d (c :: k). (d -> f c) -> Star f d c
Star ((c -> f d) -> Star f c d) -> (c -> f d) -> Star f c d
forall a b. (a -> b) -> a -> b
$ (b -> d) -> (d -> b) -> f b -> f d
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap b -> d
cd d -> b
dc (f b -> f d) -> (c -> f b) -> c -> f d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
afc (a -> f b) -> (c -> a) -> c -> f b
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 :: (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) = (f c -> d) -> Costar f c d
forall k (f :: k -> *) (d :: k) c. (f d -> c) -> Costar f d c
Costar ((f c -> d) -> Costar f c d) -> (f c -> d) -> Costar f c d
forall a b. (a -> b) -> a -> b
$ b -> d
cd (b -> d) -> (f c -> b) -> f c -> d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> b
fbc (f a -> b) -> (f c -> f a) -> f c -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a) -> (a -> c) -> f c -> f a
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 :: (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) = arr c d -> WrappedArrow arr c d
forall k k1 (p :: k -> k1 -> *) (a :: k) (b :: k1).
p a b -> WrappedArrow p a b
Pro.WrapArrow (arr c d -> WrappedArrow arr c d)
-> arr c d -> WrappedArrow arr c d
forall a b. (a -> b) -> a -> b
$ (b -> d) -> arr b d
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr b -> d
g arr b d -> arr c b -> arr c d
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 arr a b -> arr c a -> arr c b
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
Cat.. (c -> a) -> arr c a
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 :: (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Forget r a b -> Forget r c d
invmap2 = (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Forget r a b -> Forget r c d
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 :: (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' =
    f (p c d) -> Cayley f p c d
forall k k1 k2 (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Cayley f p a b
Cayley (f (p c d) -> Cayley f p c d)
-> (Cayley f p a b -> f (p c d))
-> Cayley f p a b
-> Cayley f p c d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (p a b -> p c d) -> (p c d -> p a b) -> f (p a b) -> f (p c d)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> p a b -> p c d
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') ((c -> a) -> (a -> c) -> (d -> b) -> (b -> d) -> p c d -> p 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 c -> a
f' a -> c
f d -> b
g' b -> d
g) (f (p a b) -> f (p c d))
-> (Cayley f p a b -> f (p a b)) -> Cayley f p a b -> f (p c d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cayley f p a b -> f (p a b)
forall k1 (f :: k1 -> *) k2 k3 (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 :: (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 x. p (x -> c) (x -> d)) -> Closure p c d
forall (p :: * -> * -> *) a b.
(forall x. p (x -> a) (x -> b)) -> Closure p a b
Closure ((forall x. p (x -> c) (x -> d)) -> Closure p c d)
-> (forall x. p (x -> c) (x -> d)) -> Closure p c d
forall a b. (a -> b) -> a -> b
$ ((x -> a) -> x -> c)
-> ((x -> c) -> x -> a)
-> ((x -> b) -> x -> d)
-> ((x -> d) -> x -> b)
-> p (x -> a) (x -> b)
-> p (x -> c) (x -> d)
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 (a -> c) -> (x -> a) -> x -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) (c -> a
f' (c -> a) -> (x -> c) -> x -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) (b -> d
g (b -> d) -> (x -> b) -> x -> d
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) (d -> b
g' (d -> b) -> (x -> d) -> x -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) p (x -> a) (x -> b)
forall x. p (x -> a) (x -> b)
p
-- | from the @profunctors@ package
instance Invariant2 (Environment p) where
  invmap2 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Environment p a b
-> Environment p c d
invmap2 = (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Environment p a b
-> Environment p c d
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 :: (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 x. p x c -> p x d) -> Codensity p c d
forall k k1 (p :: k -> k1 -> *) (a :: k1) (b :: k1).
(forall (x :: k). p x a -> p x b) -> Codensity p a b
Codensity ((x -> x) -> (x -> x) -> (b -> d) -> (d -> b) -> p x b -> p x d
forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 x -> x
forall a. a -> a
id x -> x
forall a. a -> a
id b -> d
bd d -> b
db (p x b -> p x d) -> (p x c -> p x b) -> p x c -> p x d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p x a -> p x b
forall x. p x a -> p x b
f (p x a -> p x b) -> (p x c -> p x a) -> p x c -> p x b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (x -> x) -> (x -> x) -> (c -> a) -> (a -> c) -> p x c -> p x a
forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 x -> x
forall a. a -> a
id x -> x
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 :: (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) =
    p x d -> q c x -> Procompose p q c d
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 ((x -> x) -> (x -> x) -> (b -> d) -> (d -> b) -> p x b -> p x d
forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 x -> x
forall a. a -> a
id x -> x
forall a. a -> a
id b -> d
r d -> b
r' p x b
f) ((a -> c) -> (c -> a) -> (x -> x) -> (x -> x) -> q a x -> q c 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
l c -> a
l' x -> x
forall a. a -> a
id x -> x
forall a. a -> a
id q a x
g)
-- | from the @profunctors@ package
instance (Invariant2 p, Invariant2 q) => Invariant2 (Rift p q) where
  invmap2 :: (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 x. p d x -> q c x) -> Rift p q c d
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 ((a -> c) -> (c -> a) -> (x -> x) -> (x -> x) -> q a x -> q c 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
ac c -> a
ca x -> x
forall a. a -> a
id x -> x
forall a. a -> a
id (q a x -> q c x) -> (p d x -> q a x) -> p d x -> q c x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p b x -> q a x
forall x. p b x -> q a x
f (p b x -> q a x) -> (p d x -> p b x) -> p d x -> q a x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (d -> b) -> (b -> d) -> (x -> x) -> (x -> x) -> p d x -> p 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 d -> b
db b -> d
bd x -> x
forall a. a -> a
id x -> x
forall a. a -> a
id)
-- | from the @profunctors@ package
instance (Invariant2 p, Invariant2 q) => Invariant2 (Ran p q) where
  invmap2 :: (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 x. p x c -> q x d) -> Ran p q c d
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 ((x -> x) -> (x -> x) -> (b -> d) -> (d -> b) -> q x b -> q x d
forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 x -> x
forall a. a -> a
id x -> x
forall a. a -> a
id b -> d
bd d -> b
db (q x b -> q x d) -> (p x c -> q x b) -> p x c -> q x d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p x a -> q x b
forall x. p x a -> q x b
f (p x a -> q x b) -> (p x c -> p x a) -> p x c -> q x b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (x -> x) -> (x -> x) -> (c -> a) -> (a -> c) -> p x c -> p x a
forall (f :: * -> * -> *) a c b d.
Invariant2 f =>
(a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
invmap2 x -> x
forall a. a -> a
id x -> x
forall a. a -> a
id c -> a
ca a -> c
ac)
-- | from the @profunctors@ package
instance Invariant2 p => Invariant2 (Tambara p) where
  invmap2 :: (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 c. p (c, c) (d, c)) -> Tambara p c d
forall (p :: * -> * -> *) a b.
(forall c. p (a, c) (b, c)) -> Tambara p a b
Tambara ((forall c. p (c, c) (d, c)) -> Tambara p c d)
-> (forall c. p (c, c) (d, c)) -> Tambara p c d
forall a b. (a -> b) -> a -> b
$ ((a, c) -> (c, c))
-> ((c, c) -> (a, c))
-> ((b, c) -> (d, c))
-> ((d, c) -> (b, c))
-> p (a, c) (b, c)
-> p (c, c) (d, 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 -> c) -> (a, c) -> (c, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> c
f) ((c -> a) -> (c, c) -> (a, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first c -> a
f') ((b -> d) -> (b, c) -> (d, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b -> d
g) ((d -> b) -> (d, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first d -> b
g') p (a, c) (b, c)
forall c. p (a, c) (b, c)
p
-- | from the @profunctors@ package
instance Invariant2 (PastroSum p) where
  invmap2 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> PastroSum p a b
-> PastroSum p c d
invmap2 = (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> PastroSum p a b
-> PastroSum p c d
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 :: (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 (f :: * -> *). Functor f => p (f c) (f d))
-> CofreeMapping p c d
forall (p :: * -> * -> *) a b.
(forall (f :: * -> *). Functor f => p (f a) (f b))
-> CofreeMapping p a b
CofreeMapping ((f a -> f c)
-> (f c -> f a)
-> (f b -> f d)
-> (f d -> f b)
-> p (f a) (f b)
-> p (f c) (f d)
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 a -> f c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> c
f) ((c -> a) -> f c -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> a
f') ((b -> d) -> f b -> f d
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> d
g) ((d -> b) -> f d -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap d -> b
g') p (f a) (f b)
forall (f :: * -> *). Functor f => p (f a) (f b)
p)
-- | from the @profunctors@ package
instance Invariant2 (FreeMapping p) where
  invmap2 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> FreeMapping p a b
-> FreeMapping p c d
invmap2 = (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> FreeMapping p a b
-> FreeMapping p c d
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 :: (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 (f :: * -> *). Traversable f => p (f c) (f d))
-> CofreeTraversing p c d
forall (p :: * -> * -> *) a b.
(forall (f :: * -> *). Traversable f => p (f a) (f b))
-> CofreeTraversing p a b
CofreeTraversing ((f a -> f c)
-> (f c -> f a)
-> (f b -> f d)
-> (f d -> f b)
-> p (f a) (f b)
-> p (f c) (f d)
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 a -> f c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> c
f) ((c -> a) -> f c -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> a
f') ((b -> d) -> f b -> f d
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> d
g) ((d -> b) -> f d -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap d -> b
g') p (f a) (f b)
forall (f :: * -> *). Traversable f => p (f a) (f b)
p)
-- | from the @profunctors@ package
instance Invariant2 (FreeTraversing p) where
  invmap2 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> FreeTraversing p a b
-> FreeTraversing p c d
invmap2 = (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> FreeTraversing p a b
-> FreeTraversing p c d
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 :: (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Pastro p a b -> Pastro p c d
invmap2 = (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Pastro p a b -> Pastro p c d
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 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Cotambara p a b
-> Cotambara p c d
invmap2 = (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> Cotambara p a b
-> Cotambara p c d
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 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> CopastroSum p a b
-> CopastroSum p c d
invmap2 = (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> CopastroSum p a b
-> CopastroSum p c d
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 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> CotambaraSum p a b
-> CotambaraSum p c d
invmap2 = (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> CotambaraSum p a b
-> CotambaraSum p c d
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 :: (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 c. p (Either c c) (Either d c)) -> TambaraSum p c d
forall (p :: * -> * -> *) a b.
(forall c. p (Either a c) (Either b c)) -> TambaraSum p a b
TambaraSum ((Either a c -> Either c c)
-> (Either c c -> Either a c)
-> (Either b c -> Either d c)
-> (Either d c -> Either b c)
-> p (Either a c) (Either b c)
-> p (Either c c) (Either d 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 -> c) -> Either a c -> Either c c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> c
f) ((c -> a) -> Either c c -> Either a c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first c -> a
f') ((b -> d) -> Either b c -> Either d c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b -> d
g) ((d -> b) -> Either d c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first d -> b
g') p (Either a c) (Either b c)
forall c. p (Either a c) (Either b c)
p)
-- | from the @profunctors@ package
instance Invariant2 (Yoneda p) where
  invmap2 :: (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Yoneda p a b -> Yoneda p c d
invmap2 = (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Yoneda p a b -> Yoneda p c d
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 :: (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Tagged a b -> Tagged c d
invmap2 = (a -> c)
-> (c -> a) -> (b -> d) -> (d -> b) -> Tagged a b -> Tagged c d
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 :: (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) = c -> Constant c d
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 { WrappedProfunctor p a b -> p a b
unwrapProfunctor :: p a b }
  deriving (WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool
(WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool)
-> (WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool)
-> Eq (WrappedProfunctor p a b)
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, Eq (WrappedProfunctor p a b)
Eq (WrappedProfunctor p a b)
-> (WrappedProfunctor p a b -> WrappedProfunctor p a b -> Ordering)
-> (WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool)
-> (WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool)
-> (WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool)
-> (WrappedProfunctor p a b -> WrappedProfunctor p a b -> Bool)
-> (WrappedProfunctor p a b
    -> WrappedProfunctor p a b -> WrappedProfunctor p a b)
-> (WrappedProfunctor p a b
    -> WrappedProfunctor p a b -> WrappedProfunctor p a b)
-> Ord (WrappedProfunctor p a b)
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
$cp1Ord :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
Eq (WrappedProfunctor p a b)
Ord, ReadPrec [WrappedProfunctor p a b]
ReadPrec (WrappedProfunctor p a b)
Int -> ReadS (WrappedProfunctor p a b)
ReadS [WrappedProfunctor p a b]
(Int -> ReadS (WrappedProfunctor p a b))
-> ReadS [WrappedProfunctor p a b]
-> ReadPrec (WrappedProfunctor p a b)
-> ReadPrec [WrappedProfunctor p a b]
-> Read (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
[WrappedProfunctor p a b] -> ShowS
WrappedProfunctor p a b -> String
(Int -> WrappedProfunctor p a b -> ShowS)
-> (WrappedProfunctor p a b -> String)
-> ([WrappedProfunctor p a b] -> ShowS)
-> Show (WrappedProfunctor p a b)
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 :: (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> WrappedProfunctor p a b
-> WrappedProfunctor p c d
invmap2 = (a -> c)
-> (c -> a)
-> (b -> d)
-> (d -> b)
-> WrappedProfunctor p a b
-> WrappedProfunctor p c d
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 :: (a -> b)
-> (b -> a) -> WrappedProfunctor p a a -> WrappedProfunctor p a b
invmap = (a -> a)
-> (a -> a)
-> (a -> b)
-> (b -> a)
-> WrappedProfunctor p a a
-> WrappedProfunctor p 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 -> a
forall a. a -> a
id a -> a
forall a. a -> a
id

instance Profunctor p => Profunctor (WrappedProfunctor p) where
  dimap :: (a -> b)
-> (c -> d) -> WrappedProfunctor p b c -> WrappedProfunctor p a d
dimap a -> b
f c -> d
g = p a d -> WrappedProfunctor p a d
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p a d -> WrappedProfunctor p a d)
-> (WrappedProfunctor p b c -> p a d)
-> WrappedProfunctor p b c
-> WrappedProfunctor p a d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> (c -> d) -> p b c -> p a d
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 (p b c -> p a d)
-> (WrappedProfunctor p b c -> p b c)
-> WrappedProfunctor p b c
-> p a d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p b c -> p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  lmap :: (a -> b) -> WrappedProfunctor p b c -> WrappedProfunctor p a c
lmap a -> b
f    = p a c -> WrappedProfunctor p a c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p a c -> WrappedProfunctor p a c)
-> (WrappedProfunctor p b c -> p a c)
-> WrappedProfunctor p b c
-> WrappedProfunctor p a c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> p b c -> p a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f    (p b c -> p a c)
-> (WrappedProfunctor p b c -> p b c)
-> WrappedProfunctor p b c
-> p a c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p b c -> p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  rmap :: (b -> c) -> WrappedProfunctor p a b -> WrappedProfunctor p a c
rmap b -> c
g    = p a c -> WrappedProfunctor p a c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p a c -> WrappedProfunctor p a c)
-> (WrappedProfunctor p a b -> p a c)
-> WrappedProfunctor p a b
-> WrappedProfunctor p a c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap b -> c
g    (p a b -> p a c)
-> (WrappedProfunctor p a b -> p a b)
-> WrappedProfunctor p a b
-> p a c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p a b -> p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  WrapProfunctor p b c
x .# :: WrappedProfunctor p b c -> q a b -> WrappedProfunctor p a c
.# q a b
f = p a c -> WrappedProfunctor p a c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
x p b c -> q a b -> p a c
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 #. :: q b c -> WrappedProfunctor p a b -> WrappedProfunctor p a c
#. WrapProfunctor p a b
x = p a c -> WrappedProfunctor p a c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (q b c
g q b c -> p a b -> p a c
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 :: WrappedProfunctor p a a
id = p a a -> WrappedProfunctor p a a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor p a a
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
Cat.id
  WrapProfunctor p b c
p1 . :: WrappedProfunctor p b c
-> WrappedProfunctor p a b -> WrappedProfunctor p a c
. WrapProfunctor p a b
p2 = p a c -> WrappedProfunctor p a c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 p b c -> p a b -> p a c
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 :: (b -> c) -> WrappedProfunctor p b c
arr    = p b c -> WrappedProfunctor p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c -> WrappedProfunctor p b c)
-> ((b -> c) -> p b c) -> (b -> c) -> WrappedProfunctor p b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> c) -> p b c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr
  first :: WrappedProfunctor p b c -> WrappedProfunctor p (b, d) (c, d)
first  = p (b, d) (c, d) -> WrappedProfunctor p (b, d) (c, d)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (b, d) (c, d) -> WrappedProfunctor p (b, d) (c, d))
-> (WrappedProfunctor p b c -> p (b, d) (c, d))
-> WrappedProfunctor p b c
-> WrappedProfunctor p (b, d) (c, d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p b c -> p (b, d) (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
Arr.first  (p b c -> p (b, d) (c, d))
-> (WrappedProfunctor p b c -> p b c)
-> WrappedProfunctor p b c
-> p (b, d) (c, d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p b c -> p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  second :: WrappedProfunctor p b c -> WrappedProfunctor p (d, b) (d, c)
second = p (d, b) (d, c) -> WrappedProfunctor p (d, b) (d, c)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (d, b) (d, c) -> WrappedProfunctor p (d, b) (d, c))
-> (WrappedProfunctor p b c -> p (d, b) (d, c))
-> WrappedProfunctor p b c
-> WrappedProfunctor p (d, b) (d, c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p b c -> p (d, b) (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
Arr.second (p b c -> p (d, b) (d, c))
-> (WrappedProfunctor p b c -> p b c)
-> WrappedProfunctor p b c
-> p (d, b) (d, c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p b c -> p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  WrapProfunctor p b c
p1 *** :: WrappedProfunctor p b c
-> WrappedProfunctor p b' c' -> WrappedProfunctor p (b, b') (c, c')
*** WrapProfunctor p b' c'
p2 = p (b, b') (c, c') -> WrappedProfunctor p (b, b') (c, c')
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 p b c -> p b' c' -> p (b, b') (c, c')
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 &&& :: WrappedProfunctor p b c
-> WrappedProfunctor p b c' -> WrappedProfunctor p b (c, c')
&&& WrapProfunctor p b c'
p2 = p b (c, c') -> WrappedProfunctor p b (c, c')
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 p b c -> p b c' -> p b (c, c')
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 :: WrappedProfunctor p b c
zeroArrow = p b c -> WrappedProfunctor p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor p b c
forall (a :: * -> * -> *) b c. ArrowZero a => a b c
zeroArrow

instance ArrowPlus p => ArrowPlus (WrappedProfunctor p) where
  WrapProfunctor p b c
p1 <+> :: WrappedProfunctor p b c
-> WrappedProfunctor p b c -> WrappedProfunctor p b c
<+> WrapProfunctor p b c
p2 = p b c -> WrappedProfunctor p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 p b c -> p b c -> p b c
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 :: WrappedProfunctor p b c
-> WrappedProfunctor p (Either b d) (Either c d)
left  = p (Either b d) (Either c d)
-> WrappedProfunctor p (Either b d) (Either c d)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (Either b d) (Either c d)
 -> WrappedProfunctor p (Either b d) (Either c d))
-> (WrappedProfunctor p b c -> p (Either b d) (Either c d))
-> WrappedProfunctor p b c
-> WrappedProfunctor p (Either b d) (Either c d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p b c -> p (Either b d) (Either c d)
forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either b d) (Either c d)
left  (p b c -> p (Either b d) (Either c d))
-> (WrappedProfunctor p b c -> p b c)
-> WrappedProfunctor p b c
-> p (Either b d) (Either c d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p b c -> p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  right :: WrappedProfunctor p b c
-> WrappedProfunctor p (Either d b) (Either d c)
right = p (Either d b) (Either d c)
-> WrappedProfunctor p (Either d b) (Either d c)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (Either d b) (Either d c)
 -> WrappedProfunctor p (Either d b) (Either d c))
-> (WrappedProfunctor p b c -> p (Either d b) (Either d c))
-> WrappedProfunctor p b c
-> WrappedProfunctor p (Either d b) (Either d c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p b c -> p (Either d b) (Either d c)
forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either d b) (Either d c)
right (p b c -> p (Either d b) (Either d c))
-> (WrappedProfunctor p b c -> p b c)
-> WrappedProfunctor p b c
-> p (Either d b) (Either d c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p b c -> p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  WrapProfunctor p b c
p1 +++ :: WrappedProfunctor p b c
-> WrappedProfunctor p b' c'
-> WrappedProfunctor p (Either b b') (Either c c')
+++ WrapProfunctor p b' c'
p2 = p (Either b b') (Either c c')
-> WrappedProfunctor p (Either b b') (Either c c')
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c
p1 p b c -> p b' c' -> p (Either b b') (Either c c')
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 ||| :: WrappedProfunctor p b d
-> WrappedProfunctor p c d -> WrappedProfunctor p (Either b c) d
||| WrapProfunctor p c d
p2 = p (Either b c) d -> WrappedProfunctor p (Either b c) d
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b d
p1 p b d -> p c d -> p (Either b c) d
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 :: WrappedProfunctor p (b, d) (c, d) -> WrappedProfunctor p b c
loop = p b c -> WrappedProfunctor p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p b c -> WrappedProfunctor p b c)
-> (WrappedProfunctor p (b, d) (c, d) -> p b c)
-> WrappedProfunctor p (b, d) (c, d)
-> WrappedProfunctor p b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (b, d) (c, d) -> p b c
forall (a :: * -> * -> *) b d c.
ArrowLoop a =>
a (b, d) (c, d) -> a b c
loop (p (b, d) (c, d) -> p b c)
-> (WrappedProfunctor p (b, d) (c, d) -> p (b, d) (c, d))
-> WrappedProfunctor p (b, d) (c, d)
-> p b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p (b, d) (c, d) -> p (b, d) (c, d)
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' :: WrappedProfunctor p a b -> WrappedProfunctor p (a, c) (b, c)
first'  = p (a, c) (b, c) -> WrappedProfunctor p (a, c) (b, c)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (a, c) (b, c) -> WrappedProfunctor p (a, c) (b, c))
-> (WrappedProfunctor p a b -> p (a, c) (b, c))
-> WrappedProfunctor p a b
-> WrappedProfunctor p (a, c) (b, c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (a, c) (b, c)
forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (a, c) (b, c)
first'  (p a b -> p (a, c) (b, c))
-> (WrappedProfunctor p a b -> p a b)
-> WrappedProfunctor p a b
-> p (a, c) (b, c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p a b -> p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  second' :: WrappedProfunctor p a b -> WrappedProfunctor p (c, a) (c, b)
second' = p (c, a) (c, b) -> WrappedProfunctor p (c, a) (c, b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (c, a) (c, b) -> WrappedProfunctor p (c, a) (c, b))
-> (WrappedProfunctor p a b -> p (c, a) (c, b))
-> WrappedProfunctor p a b
-> WrappedProfunctor p (c, a) (c, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (c, a) (c, b)
forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (c, a) (c, b)
second' (p a b -> p (c, a) (c, b))
-> (WrappedProfunctor p a b -> p a b)
-> WrappedProfunctor p a b
-> p (c, a) (c, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p a b -> p a b
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' :: WrappedProfunctor p a b
-> WrappedProfunctor p (Either a c) (Either b c)
left'  = p (Either a c) (Either b c)
-> WrappedProfunctor p (Either a c) (Either b c)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (Either a c) (Either b c)
 -> WrappedProfunctor p (Either a c) (Either b c))
-> (WrappedProfunctor p a b -> p (Either a c) (Either b c))
-> WrappedProfunctor p a b
-> WrappedProfunctor p (Either a c) (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (Either a c) (Either b c)
forall (p :: * -> * -> *) a b c.
Choice p =>
p a b -> p (Either a c) (Either b c)
left'  (p a b -> p (Either a c) (Either b c))
-> (WrappedProfunctor p a b -> p a b)
-> WrappedProfunctor p a b
-> p (Either a c) (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p a b -> p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  right' :: WrappedProfunctor p a b
-> WrappedProfunctor p (Either c a) (Either c b)
right' = p (Either c a) (Either c b)
-> WrappedProfunctor p (Either c a) (Either c b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (Either c a) (Either c b)
 -> WrappedProfunctor p (Either c a) (Either c b))
-> (WrappedProfunctor p a b -> p (Either c a) (Either c b))
-> WrappedProfunctor p a b
-> WrappedProfunctor p (Either c a) (Either c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (Either c a) (Either c b)
forall (p :: * -> * -> *) a b c.
Choice p =>
p a b -> p (Either c a) (Either c b)
right' (p a b -> p (Either c a) (Either c b))
-> (WrappedProfunctor p a b -> p a b)
-> WrappedProfunctor p a b
-> p (Either c a) (Either c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p a b -> p a b
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 :: WrappedProfunctor p (a, d) (b, d) -> WrappedProfunctor p a b
unfirst  = p a b -> WrappedProfunctor p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p a b -> WrappedProfunctor p a b)
-> (WrappedProfunctor p (a, d) (b, d) -> p a b)
-> WrappedProfunctor p (a, d) (b, d)
-> WrappedProfunctor p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (a, d) (b, d) -> p a b
forall (p :: * -> * -> *) a d b.
Costrong p =>
p (a, d) (b, d) -> p a b
unfirst  (p (a, d) (b, d) -> p a b)
-> (WrappedProfunctor p (a, d) (b, d) -> p (a, d) (b, d))
-> WrappedProfunctor p (a, d) (b, d)
-> p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p (a, d) (b, d) -> p (a, d) (b, d)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  unsecond :: WrappedProfunctor p (d, a) (d, b) -> WrappedProfunctor p a b
unsecond = p a b -> WrappedProfunctor p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p a b -> WrappedProfunctor p a b)
-> (WrappedProfunctor p (d, a) (d, b) -> p a b)
-> WrappedProfunctor p (d, a) (d, b)
-> WrappedProfunctor p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (d, a) (d, b) -> p a b
forall (p :: * -> * -> *) d a b.
Costrong p =>
p (d, a) (d, b) -> p a b
unsecond (p (d, a) (d, b) -> p a b)
-> (WrappedProfunctor p (d, a) (d, b) -> p (d, a) (d, b))
-> WrappedProfunctor p (d, a) (d, b)
-> p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p (d, a) (d, b) -> p (d, a) (d, b)
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 :: WrappedProfunctor p (Either a d) (Either b d)
-> WrappedProfunctor p a b
unleft  = p a b -> WrappedProfunctor p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p a b -> WrappedProfunctor p a b)
-> (WrappedProfunctor p (Either a d) (Either b d) -> p a b)
-> WrappedProfunctor p (Either a d) (Either b d)
-> WrappedProfunctor p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (Either a d) (Either b d) -> p a b
forall (p :: * -> * -> *) a d b.
Cochoice p =>
p (Either a d) (Either b d) -> p a b
unleft  (p (Either a d) (Either b d) -> p a b)
-> (WrappedProfunctor p (Either a d) (Either b d)
    -> p (Either a d) (Either b d))
-> WrappedProfunctor p (Either a d) (Either b d)
-> p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p (Either a d) (Either b d)
-> p (Either a d) (Either b d)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  unright :: WrappedProfunctor p (Either d a) (Either d b)
-> WrappedProfunctor p a b
unright = p a b -> WrappedProfunctor p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p a b -> WrappedProfunctor p a b)
-> (WrappedProfunctor p (Either d a) (Either d b) -> p a b)
-> WrappedProfunctor p (Either d a) (Either d b)
-> WrappedProfunctor p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (Either d a) (Either d b) -> p a b
forall (p :: * -> * -> *) d a b.
Cochoice p =>
p (Either d a) (Either d b) -> p a b
unright (p (Either d a) (Either d b) -> p a b)
-> (WrappedProfunctor p (Either d a) (Either d b)
    -> p (Either d a) (Either d b))
-> WrappedProfunctor p (Either d a) (Either d b)
-> p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p (Either d a) (Either d b)
-> p (Either d a) (Either d b)
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 :: WrappedProfunctor p a b -> WrappedProfunctor p (x -> a) (x -> b)
closed = p (x -> a) (x -> b) -> WrappedProfunctor p (x -> a) (x -> b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (x -> a) (x -> b) -> WrappedProfunctor p (x -> a) (x -> b))
-> (WrappedProfunctor p a b -> p (x -> a) (x -> b))
-> WrappedProfunctor p a b
-> WrappedProfunctor p (x -> a) (x -> b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (x -> a) (x -> b)
forall (p :: * -> * -> *) a b x.
Closed p =>
p a b -> p (x -> a) (x -> b)
closed (p a b -> p (x -> a) (x -> b))
-> (WrappedProfunctor p a b -> p a b)
-> WrappedProfunctor p a b
-> p (x -> a) (x -> b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p a b -> p a b
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' :: WrappedProfunctor p a b -> WrappedProfunctor p (f a) (f b)
traverse' = p (f a) (f b) -> WrappedProfunctor p (f a) (f b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (f a) (f b) -> WrappedProfunctor p (f a) (f b))
-> (WrappedProfunctor p a b -> p (f a) (f b))
-> WrappedProfunctor p a b
-> WrappedProfunctor p (f a) (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (f a) (f b)
forall (p :: * -> * -> *) (f :: * -> *) a b.
(Traversing p, Traversable f) =>
p a b -> p (f a) (f b)
traverse' (p a b -> p (f a) (f b))
-> (WrappedProfunctor p a b -> p a b)
-> WrappedProfunctor p a b
-> p (f a) (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p a b -> p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  wander :: (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  = p s t -> WrappedProfunctor p s t
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p s t -> WrappedProfunctor p s t)
-> (WrappedProfunctor p a b -> p s t)
-> WrappedProfunctor p a b
-> WrappedProfunctor p s t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (f :: * -> *). Applicative f => (a -> f b) -> s -> f t)
-> p a b -> p s t
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  (p a b -> p s t)
-> (WrappedProfunctor p a b -> p a b)
-> WrappedProfunctor p a b
-> p s t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p a b -> p a b
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' :: WrappedProfunctor p a b -> WrappedProfunctor p (f a) (f b)
map' = p (f a) (f b) -> WrappedProfunctor p (f a) (f b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedProfunctor p a b
WrapProfunctor (p (f a) (f b) -> WrappedProfunctor p (f a) (f b))
-> (WrappedProfunctor p a b -> p (f a) (f b))
-> WrappedProfunctor p a b
-> WrappedProfunctor p (f a) (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (f a) (f b)
forall (p :: * -> * -> *) (f :: * -> *) a b.
(Mapping p, Functor f) =>
p a b -> p (f a) (f b)
map' (p a b -> p (f a) (f b))
-> (WrappedProfunctor p a b -> p a b)
-> WrappedProfunctor p a b
-> p (f a) (f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedProfunctor p a b -> p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor

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

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

instance ProfunctorComonad WrappedProfunctor where
  proextract :: WrappedProfunctor p :-> p
proextract   = WrappedProfunctor p a b -> p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedProfunctor p a b -> p a b
unwrapProfunctor
  produplicate :: WrappedProfunctor p :-> WrappedProfunctor (WrappedProfunctor p)
produplicate = WrappedProfunctor p a b
-> WrappedProfunctor (WrappedProfunctor p) a b
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 :: (a -> b) -> (b -> a) -> V1 a -> V1 b
invmap a -> b
_ b -> a
_ V1 a
x = V1 a
x V1 a -> V1 b -> V1 b
`seq` String -> V1 b
forall a. HasCallStack => String -> a
error String
"Invariant V1"
-- | from "GHC.Generics"
instance Invariant U1 where invmap :: (a -> b) -> (b -> a) -> U1 a -> U1 b
invmap a -> b
_ b -> a
_ U1 a
_ = U1 b
forall k (p :: k). U1 p
U1
-- | from "GHC.Generics"
instance (Invariant l, Invariant r) => Invariant ((:+:) l r) where
  invmap :: (a -> b) -> (b -> a) -> (:+:) l r a -> (:+:) l r b
invmap a -> b
f b -> a
g (L1 l a
l) = l b -> (:+:) l r b
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (l b -> (:+:) l r b) -> l b -> (:+:) l r b
forall a b. (a -> b) -> a -> b
$ (a -> b) -> (b -> a) -> l a -> l 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) = r b -> (:+:) l r b
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (r b -> (:+:) l r b) -> r b -> (:+:) l r b
forall a b. (a -> b) -> a -> b
$ (a -> b) -> (b -> a) -> r a -> r 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 :: (a -> b) -> (b -> a) -> (:*:) l r a -> (:*:) l r b
invmap a -> b
f b -> a
g ~(l a
l :*: r a
r) = (a -> b) -> (b -> a) -> l a -> l 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 l b -> r b -> (:*:) l r b
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: (a -> b) -> (b -> a) -> r a -> r 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 (K1 i c) where invmap :: (a -> b) -> (b -> a) -> K1 i c a -> K1 i c b
invmap a -> b
_ b -> a
_ (K1 c
c) = c -> K1 i c b
forall k i c (p :: k). c -> K1 i c p
K1 c
c
-- | from "GHC.Generics"
instance Invariant2 (K1 i) where invmap2 :: (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) = c -> K1 i c d
forall k i c (p :: k). c -> K1 i c p
K1 (c -> K1 i c d) -> c -> K1 i c d
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 :: (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) = f b -> M1 i t f b
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (f b -> M1 i t f b) -> f b -> M1 i t f b
forall a b. (a -> b) -> a -> b
$ (a -> b) -> (b -> a) -> f a -> f 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 :: (a -> b) -> (b -> a) -> Par1 a -> Par1 b
invmap a -> b
f b -> a
_ (Par1 a
c) = b -> Par1 b
forall p. p -> Par1 p
Par1 (b -> Par1 b) -> b -> Par1 b
forall a b. (a -> b) -> a -> b
$ a -> b
f a
c
-- | from "GHC.Generics"
instance Invariant f => Invariant (Rec1 f) where invmap :: (a -> b) -> (b -> a) -> Rec1 f a -> Rec1 f b
invmap a -> b
f b -> a
g (Rec1 f a
fp) = f b -> Rec1 f b
forall k (f :: k -> *) (p :: k). f p -> Rec1 f p
Rec1 (f b -> Rec1 f b) -> f b -> Rec1 f b
forall a b. (a -> b) -> a -> b
$ (a -> b) -> (b -> a) -> f a -> f 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 :: (a -> b) -> (b -> a) -> (:.:) f g a -> (:.:) f g b
invmap a -> b
f b -> a
g (Comp1 f (g a)
fgp) = f (g b) -> (:.:) f g b
forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 (f (g b) -> (:.:) f g b) -> f (g b) -> (:.:) f g b
forall a b. (a -> b) -> a -> b
$ (g a -> g b) -> (g b -> g a) -> f (g a) -> f (g b)
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap ((a -> b) -> (b -> a) -> g a -> g b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g) ((b -> a) -> (a -> b) -> g b -> g a
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 :: (a -> b) -> (b -> a) -> UAddr a -> UAddr b
invmap a -> b
_ b -> a
_ (UAddr a) = Addr# -> UAddr b
forall k (p :: k). Addr# -> URec (Ptr ()) p
UAddr Addr#
a

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

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

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

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

-- | from "GHC.Generics"
instance Invariant UWord where
  invmap :: (a -> b) -> (b -> a) -> UWord a -> UWord b
invmap a -> b
_ b -> a
_ (UWord w) = Word# -> UWord b
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 :: (a -> b) -> (b -> a) -> f a -> f b
genericInvmap a -> b
f b -> a
g = Rep1 f b -> f b
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 (Rep1 f b -> f b) -> (f a -> Rep1 f b) -> f a -> f b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> (b -> a) -> Rep1 f a -> Rep1 f b
forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g (Rep1 f a -> Rep1 f b) -> (f a -> Rep1 f a) -> f a -> Rep1 f b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> Rep1 f a
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 :: (a -> b)
-> (b -> a) -> InvariantProfunctor p a -> InvariantProfunctor p b
invmap a -> b
fn1 b -> a
fn2 (InvariantProfunctor p a a
f) = p b b -> InvariantProfunctor p b
forall k (p :: k -> k -> *) (a :: k).
p a a -> InvariantProfunctor p a
InvariantProfunctor ((a -> b) -> (b -> a) -> p a a -> p b b
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 :: (a -> b) -> (b -> a) -> InvariantArrow c a -> InvariantArrow c b
invmap a -> b
fn1 b -> a
fn2 (InvariantArrow c a a
arrow) = c b b -> InvariantArrow c b
forall k (c :: k -> k -> *) (a :: k). c a a -> InvariantArrow c a
InvariantArrow ((a -> b) -> (b -> a) -> c a a -> c b b
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)