module Pandora.Pattern.Functor.Invariant where

import Pandora.Pattern.Category (($))

{- |
> When providing a new instance, you should ensure it satisfies the two laws:
> Identity morphisms: invmap identity identity = identity
> Interpreted of morphisms: invmap g j . invmap f h = invmap (g . f) (h . j)
-}

class Invariant (t :: * -> *) where
	{-# MINIMAL (>-<) #-}
	(>-<) :: (a -> b) -> (b -> a) -> t a -> t b
	-- | Prefix version of '>-<'
	invmap :: (a -> b) -> (b -> a) -> t a -> t b
	invmap a -> b
f b -> a
g t a
x = a -> b
f (a -> b) -> (b -> a) -> t a -> t b
forall (t :: * -> *) a b.
Invariant t =>
(a -> b) -> (b -> a) -> t a -> t b
>-< b -> a
g (t a -> t b) -> t a -> t b
forall (m :: * -> * -> *) a b. Category m => m a b -> m a b
$ t a
x