{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE TypeFamilies #-}

-----------------------------------------------------------------------------
-- |
-- Copyright   :  (C) 2008-2016 Edward Kmett
-- License     :  BSD-style (see the file LICENSE)
--
-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
-- Stability   :  provisional
-- Portability :  portable
--
-- From the Functional Pearl \"Clowns to the Left of me, Jokers to the Right: Dissecting Data Structures\"
-- by Conor McBride.
----------------------------------------------------------------------------
module Data.Bifunctor.Clown
  ( Clown(..)
  ) where

import Data.Biapplicative
import Data.Bifoldable
import Data.Bifoldable1 (Bifoldable1(..))
import Data.Bitraversable
import Data.Foldable1 (Foldable1(..))
import Data.Functor.Classes
import GHC.Generics

-- | Make a 'Functor' over the first argument of a 'Bifunctor'.
--
-- Mnemonic: C__l__owns to the __l__eft (parameter of the Bifunctor),
--           joke__r__s to the __r__ight.
newtype Clown f a b = Clown { forall {k} {k} (f :: k -> *) (a :: k) (b :: k). Clown f a b -> f a
runClown :: f a }
  deriving (Clown f a b -> Clown f a b -> Bool
(Clown f a b -> Clown f a b -> Bool)
-> (Clown f a b -> Clown f a b -> Bool) -> Eq (Clown f a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (f :: k -> *) (a :: k) k (b :: k).
Eq (f a) =>
Clown f a b -> Clown f a b -> Bool
$c== :: forall k (f :: k -> *) (a :: k) k (b :: k).
Eq (f a) =>
Clown f a b -> Clown f a b -> Bool
== :: Clown f a b -> Clown f a b -> Bool
$c/= :: forall k (f :: k -> *) (a :: k) k (b :: k).
Eq (f a) =>
Clown f a b -> Clown f a b -> Bool
/= :: Clown f a b -> Clown f a b -> Bool
Eq, Eq (Clown f a b)
Eq (Clown f a b) =>
(Clown f a b -> Clown f a b -> Ordering)
-> (Clown f a b -> Clown f a b -> Bool)
-> (Clown f a b -> Clown f a b -> Bool)
-> (Clown f a b -> Clown f a b -> Bool)
-> (Clown f a b -> Clown f a b -> Bool)
-> (Clown f a b -> Clown f a b -> Clown f a b)
-> (Clown f a b -> Clown f a b -> Clown f a b)
-> Ord (Clown f a b)
Clown f a b -> Clown f a b -> Bool
Clown f a b -> Clown f a b -> Ordering
Clown f a b -> Clown f a b -> Clown f 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 (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Eq (Clown f a b)
forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Bool
forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Ordering
forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Clown f a b
$ccompare :: forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Ordering
compare :: Clown f a b -> Clown f a b -> Ordering
$c< :: forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Bool
< :: Clown f a b -> Clown f a b -> Bool
$c<= :: forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Bool
<= :: Clown f a b -> Clown f a b -> Bool
$c> :: forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Bool
> :: Clown f a b -> Clown f a b -> Bool
$c>= :: forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Bool
>= :: Clown f a b -> Clown f a b -> Bool
$cmax :: forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Clown f a b
max :: Clown f a b -> Clown f a b -> Clown f a b
$cmin :: forall k (f :: k -> *) (a :: k) k (b :: k).
Ord (f a) =>
Clown f a b -> Clown f a b -> Clown f a b
min :: Clown f a b -> Clown f a b -> Clown f a b
Ord, Int -> Clown f a b -> ShowS
[Clown f a b] -> ShowS
Clown f a b -> String
(Int -> Clown f a b -> ShowS)
-> (Clown f a b -> String)
-> ([Clown f a b] -> ShowS)
-> Show (Clown f a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (f :: k -> *) (a :: k) k (b :: k).
Show (f a) =>
Int -> Clown f a b -> ShowS
forall k (f :: k -> *) (a :: k) k (b :: k).
Show (f a) =>
[Clown f a b] -> ShowS
forall k (f :: k -> *) (a :: k) k (b :: k).
Show (f a) =>
Clown f a b -> String
$cshowsPrec :: forall k (f :: k -> *) (a :: k) k (b :: k).
Show (f a) =>
Int -> Clown f a b -> ShowS
showsPrec :: Int -> Clown f a b -> ShowS
$cshow :: forall k (f :: k -> *) (a :: k) k (b :: k).
Show (f a) =>
Clown f a b -> String
show :: Clown f a b -> String
$cshowList :: forall k (f :: k -> *) (a :: k) k (b :: k).
Show (f a) =>
[Clown f a b] -> ShowS
showList :: [Clown f a b] -> ShowS
Show, ReadPrec [Clown f a b]
ReadPrec (Clown f a b)
Int -> ReadS (Clown f a b)
ReadS [Clown f a b]
(Int -> ReadS (Clown f a b))
-> ReadS [Clown f a b]
-> ReadPrec (Clown f a b)
-> ReadPrec [Clown f a b]
-> Read (Clown f a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (f :: k -> *) (a :: k) k (b :: k).
Read (f a) =>
ReadPrec [Clown f a b]
forall k (f :: k -> *) (a :: k) k (b :: k).
Read (f a) =>
ReadPrec (Clown f a b)
forall k (f :: k -> *) (a :: k) k (b :: k).
Read (f a) =>
Int -> ReadS (Clown f a b)
forall k (f :: k -> *) (a :: k) k (b :: k).
Read (f a) =>
ReadS [Clown f a b]
$creadsPrec :: forall k (f :: k -> *) (a :: k) k (b :: k).
Read (f a) =>
Int -> ReadS (Clown f a b)
readsPrec :: Int -> ReadS (Clown f a b)
$creadList :: forall k (f :: k -> *) (a :: k) k (b :: k).
Read (f a) =>
ReadS [Clown f a b]
readList :: ReadS [Clown f a b]
$creadPrec :: forall k (f :: k -> *) (a :: k) k (b :: k).
Read (f a) =>
ReadPrec (Clown f a b)
readPrec :: ReadPrec (Clown f a b)
$creadListPrec :: forall k (f :: k -> *) (a :: k) k (b :: k).
Read (f a) =>
ReadPrec [Clown f a b]
readListPrec :: ReadPrec [Clown f a b]
Read, (forall x. Clown f a b -> Rep (Clown f a b) x)
-> (forall x. Rep (Clown f a b) x -> Clown f a b)
-> Generic (Clown f a b)
forall x. Rep (Clown f a b) x -> Clown f a b
forall x. Clown f a b -> Rep (Clown f a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (f :: k -> *) (a :: k) k (b :: k) x.
Rep (Clown f a b) x -> Clown f a b
forall k (f :: k -> *) (a :: k) k (b :: k) x.
Clown f a b -> Rep (Clown f a b) x
$cfrom :: forall k (f :: k -> *) (a :: k) k (b :: k) x.
Clown f a b -> Rep (Clown f a b) x
from :: forall x. Clown f a b -> Rep (Clown f a b) x
$cto :: forall k (f :: k -> *) (a :: k) k (b :: k) x.
Rep (Clown f a b) x -> Clown f a b
to :: forall x. Rep (Clown f a b) x -> Clown f a b
Generic, (forall (a :: k). Clown f a a -> Rep1 (Clown f a) a)
-> (forall (a :: k). Rep1 (Clown f a) a -> Clown f a a)
-> Generic1 (Clown f a)
forall (a :: k). Rep1 (Clown f a) a -> Clown f a a
forall (a :: k). Clown f a a -> Rep1 (Clown f a) a
forall k k (f :: k -> *) (a :: k) (a :: k).
Rep1 (Clown f a) a -> Clown f a a
forall k k (f :: k -> *) (a :: k) (a :: k).
Clown f a a -> Rep1 (Clown f a) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall k k (f :: k -> *) (a :: k) (a :: k).
Clown f a a -> Rep1 (Clown f a) a
from1 :: forall (a :: k). Clown f a a -> Rep1 (Clown f a) a
$cto1 :: forall k k (f :: k -> *) (a :: k) (a :: k).
Rep1 (Clown f a) a -> Clown f a a
to1 :: forall (a :: k). Rep1 (Clown f a) a -> Clown f a a
Generic1)

instance (Eq1 f, Eq a) => Eq1 (Clown f a) where
  liftEq :: forall a b. (a -> b -> Bool) -> Clown f a a -> Clown f a b -> Bool
liftEq = (a -> a -> Bool)
-> (a -> b -> Bool) -> Clown f a a -> Clown f a b -> Bool
forall a b c d.
(a -> b -> Bool)
-> (c -> d -> Bool) -> Clown f a c -> Clown f b d -> Bool
forall (f :: * -> * -> *) a b c d.
Eq2 f =>
(a -> b -> Bool) -> (c -> d -> Bool) -> f a c -> f b d -> Bool
liftEq2 a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
instance Eq1 f => Eq2 (Clown f) where
  liftEq2 :: forall a b c d.
(a -> b -> Bool)
-> (c -> d -> Bool) -> Clown f a c -> Clown f b d -> Bool
liftEq2 a -> b -> Bool
f c -> d -> Bool
_ = (f a -> f b -> Bool) -> Clown f a c -> Clown f b d -> Bool
forall {k} {k} {k} (f :: k -> *) (a1 :: k) (a2 :: k) (b1 :: k)
       (b2 :: k).
(f a1 -> f a2 -> Bool) -> Clown f a1 b1 -> Clown f a2 b2 -> Bool
eqClown ((a -> b -> Bool) -> f a -> f b -> Bool
forall a b. (a -> b -> Bool) -> f a -> f b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
f)

instance (Ord1 f, Ord a) => Ord1 (Clown f a) where
  liftCompare :: forall a b.
(a -> b -> Ordering) -> Clown f a a -> Clown f a b -> Ordering
liftCompare = (a -> a -> Ordering)
-> (a -> b -> Ordering) -> Clown f a a -> Clown f a b -> Ordering
forall a b c d.
(a -> b -> Ordering)
-> (c -> d -> Ordering) -> Clown f a c -> Clown f b d -> Ordering
forall (f :: * -> * -> *) a b c d.
Ord2 f =>
(a -> b -> Ordering)
-> (c -> d -> Ordering) -> f a c -> f b d -> Ordering
liftCompare2 a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
instance Ord1 f => Ord2 (Clown f) where
  liftCompare2 :: forall a b c d.
(a -> b -> Ordering)
-> (c -> d -> Ordering) -> Clown f a c -> Clown f b d -> Ordering
liftCompare2 a -> b -> Ordering
f c -> d -> Ordering
_ = (f a -> f b -> Ordering) -> Clown f a c -> Clown f b d -> Ordering
forall {k} {k} {k} (f :: k -> *) (a1 :: k) (a2 :: k) (b1 :: k)
       (b2 :: k).
(f a1 -> f a2 -> Ordering)
-> Clown f a1 b1 -> Clown f a2 b2 -> Ordering
compareClown ((a -> b -> Ordering) -> f a -> f b -> Ordering
forall a b. (a -> b -> Ordering) -> f a -> f b -> Ordering
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
f)

instance (Read1 f, Read a) => Read1 (Clown f a) where
  liftReadsPrec :: forall a.
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Clown f a a)
liftReadsPrec = (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS a)
-> ReadS [a]
-> Int
-> ReadS (Clown f a a)
forall a b.
(Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (Clown f a b)
forall (f :: * -> * -> *) a b.
Read2 f =>
(Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (f a b)
liftReadsPrec2 Int -> ReadS a
forall a. Read a => Int -> ReadS a
readsPrec ReadS [a]
forall a. Read a => ReadS [a]
readList
instance Read1 f => Read2 (Clown f) where
  liftReadsPrec2 :: forall a b.
(Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (Clown f a b)
liftReadsPrec2 Int -> ReadS a
rp1 ReadS [a]
rl1 Int -> ReadS b
_ ReadS [b]
_ = (Int -> ReadS (f a)) -> Int -> ReadS (Clown f a b)
forall {k} {k} (f :: k -> *) (a :: k) (b :: k).
(Int -> ReadS (f a)) -> Int -> ReadS (Clown f a b)
readsPrecClown ((Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
forall a. (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
rp1 ReadS [a]
rl1)

instance (Show1 f, Show a) => Show1 (Clown f a) where
  liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Clown f a a -> ShowS
liftShowsPrec = (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> Int
-> Clown f a a
-> ShowS
forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> Clown f a b
-> ShowS
forall (f :: * -> * -> *) a b.
Show2 f =>
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> f a b
-> ShowS
liftShowsPrec2 Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec [a] -> ShowS
forall a. Show a => [a] -> ShowS
showList
instance Show1 f => Show2 (Clown f) where
  liftShowsPrec2 :: forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> Clown f a b
-> ShowS
liftShowsPrec2 Int -> a -> ShowS
sp1 [a] -> ShowS
sl1 Int -> b -> ShowS
_ [b] -> ShowS
_ = (Int -> f a -> ShowS) -> Int -> Clown f a b -> ShowS
forall {k} {k} (f :: k -> *) (a :: k) (b :: k).
(Int -> f a -> ShowS) -> Int -> Clown f a b -> ShowS
showsPrecClown ((Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp1 [a] -> ShowS
sl1)

eqClown :: (f a1 -> f a2 -> Bool)
        -> Clown f a1 b1 -> Clown f a2 b2 -> Bool
eqClown :: forall {k} {k} {k} (f :: k -> *) (a1 :: k) (a2 :: k) (b1 :: k)
       (b2 :: k).
(f a1 -> f a2 -> Bool) -> Clown f a1 b1 -> Clown f a2 b2 -> Bool
eqClown f a1 -> f a2 -> Bool
eqA (Clown f a1
x) (Clown f a2
y) = f a1 -> f a2 -> Bool
eqA f a1
x f a2
y

compareClown :: (f a1 -> f a2 -> Ordering)
             -> Clown f a1 b1 -> Clown f a2 b2 -> Ordering
compareClown :: forall {k} {k} {k} (f :: k -> *) (a1 :: k) (a2 :: k) (b1 :: k)
       (b2 :: k).
(f a1 -> f a2 -> Ordering)
-> Clown f a1 b1 -> Clown f a2 b2 -> Ordering
compareClown f a1 -> f a2 -> Ordering
compareA (Clown f a1
x) (Clown f a2
y) = f a1 -> f a2 -> Ordering
compareA f a1
x f a2
y

readsPrecClown :: (Int -> ReadS (f a))
               -> Int -> ReadS (Clown f a b)
readsPrecClown :: forall {k} {k} (f :: k -> *) (a :: k) (b :: k).
(Int -> ReadS (f a)) -> Int -> ReadS (Clown f a b)
readsPrecClown Int -> ReadS (f a)
rpA Int
p =
  Bool -> ReadS (Clown f a b) -> ReadS (Clown f a b)
forall a. Bool -> ReadS a -> ReadS a
readParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ReadS (Clown f a b) -> ReadS (Clown f a b))
-> ReadS (Clown f a b) -> ReadS (Clown f a b)
forall a b. (a -> b) -> a -> b
$ \String
s0 -> do
    (String
"Clown",    String
s1) <- ReadS String
lex String
s0
    (String
"{",        String
s2) <- ReadS String
lex String
s1
    (String
"runClown", String
s3) <- ReadS String
lex String
s2
    (f a
x,          String
s4) <- Int -> ReadS (f a)
rpA Int
0 String
s3
    (String
"}",        String
s5) <- ReadS String
lex String
s4
    (Clown f a b, String) -> [(Clown f a b, String)]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (f a -> Clown f a b
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). f a -> Clown f a b
Clown f a
x, String
s5)

showsPrecClown :: (Int -> f a -> ShowS)
               -> Int -> Clown f a b -> ShowS
showsPrecClown :: forall {k} {k} (f :: k -> *) (a :: k) (b :: k).
(Int -> f a -> ShowS) -> Int -> Clown f a b -> ShowS
showsPrecClown Int -> f a -> ShowS
spA Int
p (Clown f a
x) =
  Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
      String -> ShowS
showString String
"Clown {runClown = "
    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> f a -> ShowS
spA Int
0 f a
x
    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'}'

instance Functor f => Bifunctor (Clown f) where
  first :: forall a b c. (a -> b) -> Clown f a c -> Clown f b c
first a -> b
f = f b -> Clown f b c
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). f a -> Clown f a b
Clown (f b -> Clown f b c)
-> (Clown f a c -> f b) -> Clown f a c -> Clown f b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> f a -> f b
forall a b. (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) -> (Clown f a c -> f a) -> Clown f a c -> f b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a c -> f a
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). Clown f a b -> f a
runClown
  {-# INLINE first #-}
  second :: forall b c a. (b -> c) -> Clown f a b -> Clown f a c
second b -> c
_ = f a -> Clown f a c
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). f a -> Clown f a b
Clown (f a -> Clown f a c)
-> (Clown f a b -> f a) -> Clown f a b -> Clown f a c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a b -> f a
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). Clown f a b -> f a
runClown
  {-# INLINE second #-}
  bimap :: forall a b c d. (a -> b) -> (c -> d) -> Clown f a c -> Clown f b d
bimap a -> b
f c -> d
_ = f b -> Clown f b d
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). f a -> Clown f a b
Clown (f b -> Clown f b d)
-> (Clown f a c -> f b) -> Clown f a c -> Clown f b d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> f a -> f b
forall a b. (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) -> (Clown f a c -> f a) -> Clown f a c -> f b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a c -> f a
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). Clown f a b -> f a
runClown
  {-# INLINE bimap #-}

instance Functor (Clown f a) where
  fmap :: forall a b. (a -> b) -> Clown f a a -> Clown f a b
fmap a -> b
_ = f a -> Clown f a b
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). f a -> Clown f a b
Clown (f a -> Clown f a b)
-> (Clown f a a -> f a) -> Clown f a a -> Clown f a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a a -> f a
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). Clown f a b -> f a
runClown
  {-# INLINE fmap #-}

instance Applicative f => Biapplicative (Clown f) where
  bipure :: forall a b. a -> b -> Clown f a b
bipure a
a b
_ = f a -> Clown f a b
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). f a -> Clown f a b
Clown (a -> f a
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a)
  {-# INLINE bipure #-}

  Clown f (a -> b)
mf <<*>> :: forall a b c d.
Clown f (a -> b) (c -> d) -> Clown f a c -> Clown f b d
<<*>> Clown f a
mx = f b -> Clown f b d
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). f a -> Clown f a b
Clown (f (a -> b)
mf f (a -> b) -> f a -> f b
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f a
mx)
  {-# INLINE (<<*>>) #-}

instance Foldable f => Bifoldable (Clown f) where
  bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> Clown f a b -> m
bifoldMap a -> m
f b -> m
_ = (a -> m) -> f a -> m
forall m a. Monoid m => (a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f (f a -> m) -> (Clown f a b -> f a) -> Clown f a b -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a b -> f a
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). Clown f a b -> f a
runClown
  {-# INLINE bifoldMap #-}

instance Foldable1 f => Bifoldable1 (Clown f) where
  bifoldMap1 :: forall m a b.
Semigroup m =>
(a -> m) -> (b -> m) -> Clown f a b -> m
bifoldMap1 a -> m
f b -> m
_ = (a -> m) -> f a -> m
forall m a. Semigroup m => (a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable1 t, Semigroup m) =>
(a -> m) -> t a -> m
foldMap1 a -> m
f (f a -> m) -> (Clown f a b -> f a) -> Clown f a b -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a b -> f a
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). Clown f a b -> f a
runClown
  {-# INLINE bifoldMap1 #-}

instance Foldable (Clown f a) where
  foldMap :: forall m a. Monoid m => (a -> m) -> Clown f a a -> m
foldMap a -> m
_ = Clown f a a -> m
forall a. Monoid a => a
mempty
  {-# INLINE foldMap #-}

instance Traversable f => Bitraversable (Clown f) where
  bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Clown f a b -> f (Clown f c d)
bitraverse a -> f c
f b -> f d
_ = (f c -> Clown f c d) -> f (f c) -> f (Clown f c d)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f c -> Clown f c d
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). f a -> Clown f a b
Clown (f (f c) -> f (Clown f c d))
-> (Clown f a b -> f (f c)) -> Clown f a b -> f (Clown f c d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f c) -> f a -> f (f c)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> f a -> f (f b)
traverse a -> f c
f (f a -> f (f c)) -> (Clown f a b -> f a) -> Clown f a b -> f (f c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a b -> f a
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). Clown f a b -> f a
runClown
  {-# INLINE bitraverse #-}

instance Traversable (Clown f a) where
  traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Clown f a a -> f (Clown f a b)
traverse a -> f b
_ = Clown f a b -> f (Clown f a b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Clown f a b -> f (Clown f a b))
-> (Clown f a a -> Clown f a b) -> Clown f a a -> f (Clown f a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> Clown f a b
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). f a -> Clown f a b
Clown (f a -> Clown f a b)
-> (Clown f a a -> f a) -> Clown f a a -> Clown f a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Clown f a a -> f a
forall {k} {k} (f :: k -> *) (a :: k) (b :: k). Clown f a b -> f a
runClown
  {-# INLINE traverse #-}