module Pandora.Paradigm.Primary.Transformer.Flip where

import Pandora.Pattern.Category (($))
import Pandora.Pattern.Functor.Bivariant (Bivariant ((<->)))
import Pandora.Paradigm.Controlflow.Effect.Interpreted (Interpreted (Primary, run, unite))

newtype Flip (v :: * -> * -> *) a e = Flip (v e a)

instance Interpreted (Flip v a) where
	type Primary (Flip v a) e = v e a
	run :: Flip v a a -> Primary (Flip v a) a
run ~(Flip v a a
x) = v a a
Primary (Flip v a) a
x
	unite :: Primary (Flip v a) a -> Flip v a a
unite = Primary (Flip v a) a -> Flip v a a
forall (v :: * -> * -> *) a e. v e a -> Flip v a e
Flip

instance Bivariant v => Bivariant (Flip v) where
	a -> b
f <-> :: (a -> b) -> (c -> d) -> Flip v a c -> Flip v b d
<-> c -> d
g = \Flip v a c
x -> v d b -> Flip v b d
forall (t :: * -> *) a. Interpreted t => Primary t a -> t a
unite (v d b -> Flip v b d) -> v d b -> Flip v b d
forall (m :: * -> * -> *). Category m => m ~~> m
$ c -> d
g (c -> d) -> (a -> b) -> v c a -> v d b
forall (v :: * -> * -> *) a b c d.
Bivariant v =>
(a -> b) -> (c -> d) -> v a c -> v b d
<-> a -> b
f (v c a -> v d b) -> v c a -> v d b
forall (m :: * -> * -> *). Category m => m ~~> m
$ Flip v a c -> Primary (Flip v a) c
forall (t :: * -> *) a. Interpreted t => t a -> Primary t a
run Flip v a c
x