{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}

module Data.Type.Flip where

newtype Flip t a b = Flip { forall (t :: * -> * -> *) a b. Flip t a b -> t b a
unflip :: t b a } deriving Int -> Flip t a b -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (t :: * -> * -> *) a b.
Show (t b a) =>
Int -> Flip t a b -> ShowS
forall (t :: * -> * -> *) a b.
Show (t b a) =>
[Flip t a b] -> ShowS
forall (t :: * -> * -> *) a b. Show (t b a) => Flip t a b -> String
showList :: [Flip t a b] -> ShowS
$cshowList :: forall (t :: * -> * -> *) a b.
Show (t b a) =>
[Flip t a b] -> ShowS
show :: Flip t a b -> String
$cshow :: forall (t :: * -> * -> *) a b. Show (t b a) => Flip t a b -> String
showsPrec :: Int -> Flip t a b -> ShowS
$cshowsPrec :: forall (t :: * -> * -> *) a b.
Show (t b a) =>
Int -> Flip t a b -> ShowS
Show

infixl 4 <$%>, <*%>

ffmap, (<$%>) :: Functor (Flip t c) => (a -> b) -> t a c -> t b c
ffmap :: forall (t :: * -> * -> *) c a b.
Functor (Flip t c) =>
(a -> b) -> t a c -> t b c
ffmap a -> b
f = forall (t :: * -> * -> *) a b. Flip t a b -> t b a
unflip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> * -> *) a b. t b a -> Flip t a b
Flip
<$%> :: forall (t :: * -> * -> *) c a b.
Functor (Flip t c) =>
(a -> b) -> t a c -> t b c
(<$%>) = forall (t :: * -> * -> *) c a b.
Functor (Flip t c) =>
(a -> b) -> t a c -> t b c
ffmap

fpure :: Applicative (Flip t b) => a -> t a b
fpure :: forall (t :: * -> * -> *) b a. Applicative (Flip t b) => a -> t a b
fpure = forall (t :: * -> * -> *) a b. Flip t a b -> t b a
unflip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure

(<*%>) :: Applicative (Flip t c) => t (a -> b) c -> t a c -> t b c
t (a -> b) c
mf <*%> :: forall (t :: * -> * -> *) c a b.
Applicative (Flip t c) =>
t (a -> b) c -> t a c -> t b c
<*%> t a c
mx = forall (t :: * -> * -> *) a b. Flip t a b -> t b a
unflip forall a b. (a -> b) -> a -> b
$ forall (t :: * -> * -> *) a b. t b a -> Flip t a b
Flip t (a -> b) c
mf forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> * -> *) a b. t b a -> Flip t a b
Flip t a c
mx

infixl 1 >>=%

(>>=%) :: Monad (Flip t c) => t a c -> (a -> t b c) -> t b c
t a c
m >>=% :: forall (t :: * -> * -> *) c a b.
Monad (Flip t c) =>
t a c -> (a -> t b c) -> t b c
>>=% a -> t b c
f = forall (t :: * -> * -> *) a b. Flip t a b -> t b a
unflip forall a b. (a -> b) -> a -> b
$ forall (t :: * -> * -> *) a b. t b a -> Flip t a b
Flip t a c
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (t :: * -> * -> *) a b. t b a -> Flip t a b
Flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> t b c
f

infixr 1 =<<%

(=<<%) :: Monad (Flip t c) => (a -> t b c) -> t a c -> t b c
=<<% :: forall (t :: * -> * -> *) c a b.
Monad (Flip t c) =>
(a -> t b c) -> t a c -> t b c
(=<<%) = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (t :: * -> * -> *) c a b.
Monad (Flip t c) =>
t a c -> (a -> t b c) -> t b c
(>>=%)

ftraverse :: (Applicative (Flip s c), Traversable t) => (a -> s b c) -> t a -> s (t b) c
ftraverse :: forall (s :: * -> * -> *) c (t :: * -> *) a b.
(Applicative (Flip s c), Traversable t) =>
(a -> s b c) -> t a -> s (t b) c
ftraverse a -> s b c
f t a
t = forall (t :: * -> * -> *) a b. Flip t a b -> t b a
unflip forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (t :: * -> * -> *) a b. t b a -> Flip t a b
Flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> s b c
f) t a
t

fsequence :: (Applicative (Flip s c), Traversable t) => t (s a c) -> s (t a) c
fsequence :: forall (s :: * -> * -> *) c (t :: * -> *) a.
(Applicative (Flip s c), Traversable t) =>
t (s a c) -> s (t a) c
fsequence t (s a c)
tf = forall (t :: * -> * -> *) a b. Flip t a b -> t b a
unflip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA forall a b. (a -> b) -> a -> b
$ forall (t :: * -> * -> *) a b. t b a -> Flip t a b
Flip forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t (s a c)
tf