{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE GADTs                     #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE Rank2Types                #-}
{-# LANGUAGE ScopedTypeVariables       #-}
{-# LANGUAGE TupleSections             #-}
{-# LANGUAGE TypeFamilies              #-}
{-# LANGUAGE TypeFamilyDependencies    #-}
{-# LANGUAGE TypeOperators             #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Data.Generics.Internal.Profunctor.Lens
-- Copyright   :  (C) 2019 Csongor Kiss
-- License     :  BSD3
-- Maintainer  :  Csongor Kiss <kiss.csongor.kiss@gmail.com>
-- Stability   :  experimental
-- Portability :  non-portable
--
-- Internal lens helpers. Only exported for Haddock
--
-----------------------------------------------------------------------------
module Data.Generics.Internal.Profunctor.Lens where

import Data.Profunctor        (Profunctor(..), Strong(..))
import Data.Bifunctor
import GHC.Generics
import Data.Generics.Internal.Profunctor.Iso

type Lens s t a b
  = forall p . (Strong p) => p a b -> p s t

type LensLike p s t a b
  = p a b -> p s t


ravel :: (ALens a b a b -> ALens a b s t) -> Lens s t a b
ravel :: (ALens a b a b -> ALens a b s t) -> Lens s t a b
ravel l :: ALens a b a b -> ALens a b s t
l pab :: p a b
pab = ALens a b s t -> p a b -> p s t
forall a b s t. ALens a b s t -> Lens s t a b
conv (ALens a b a b -> ALens a b s t
l ALens a b a b
forall a b. ALens a b a b
idLens) p a b
pab
  where
    conv :: ALens a b s t -> Lens s t a b
    conv :: ALens a b s t -> Lens s t a b
conv (ALens _get :: s -> (c, a)
_get _set :: (c, b) -> t
_set) = (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b
forall s c a b t. (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b
lens s -> (c, a)
_get (c, b) -> t
_set

-- | Setting
set :: ((a -> b) -> s -> t) -> (s, b) -> t
set :: ((a -> b) -> s -> t) -> (s, b) -> t
set f :: (a -> b) -> s -> t
f (s :: s
s, b :: b
b)
  = (a -> b) -> s -> t
f  (b -> a -> b
forall a b. a -> b -> a
const b
b) s
s

view :: Lens s s a a -> s -> a
view :: Lens s s a a -> s -> a
view l :: Lens s s a a
l = Lens s s a a
-> (forall c. (s -> (c, a)) -> ((c, a) -> s) -> s -> a) -> s -> a
forall s t a b r.
Lens s t a b
-> (forall c. (s -> (c, a)) -> ((c, b) -> t) -> r) -> r
withLensPrim Lens s s a a
l (\get :: s -> (c, a)
get _ -> (c, a) -> a
forall a b. (a, b) -> b
snd ((c, a) -> a) -> (s -> (c, a)) -> s -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> (c, a)
get)

--withLens :: Lens s t a b -> ((s -> a) -> ((s, b) -> t) -> r) -> r
--ithLens l k =
-- case l idLens of
--   ALens _get _set -> k (snd . _get) (\(s, b) -> _set ((fst $ _get s), b))

withLensPrim :: Lens s t a b -> (forall c . (s -> (c,a)) -> ((c, b) -> t) -> r) -> r
withLensPrim :: Lens s t a b
-> (forall c. (s -> (c, a)) -> ((c, b) -> t) -> r) -> r
withLensPrim l :: Lens s t a b
l k :: forall c. (s -> (c, a)) -> ((c, b) -> t) -> r
k =
 case ALens a b a b -> ALens a b s t
Lens s t a b
l ALens a b a b
forall a b. ALens a b a b
idLens of
   ALens _get :: s -> (c, a)
_get _set :: (c, b) -> t
_set -> (s -> (c, a)) -> ((c, b) -> t) -> r
forall c. (s -> (c, a)) -> ((c, b) -> t) -> r
k s -> (c, a)
_get (c, b) -> t
_set

idLens :: ALens a b a b
idLens :: ALens a b a b
idLens = (a -> ((), a)) -> (((), b) -> b) -> ALens a b a b
forall a b s t c. (s -> (c, a)) -> ((c, b) -> t) -> ALens a b s t
ALens ((a -> ()) -> (a -> a) -> a -> ((), a)
forall a b c. (a -> b) -> (a -> c) -> a -> (b, c)
fork (() -> a -> ()
forall a b. a -> b -> a
const ()) a -> a
forall a. a -> a
id) ((), b) -> b
forall a b. (a, b) -> b
snd
{-# INLINE idLens #-}

-- | Lens focusing on the first element of a product
first :: Lens ((a :*: b) x) ((a' :*: b) x) (a x) (a' x)
first :: p (a x) (a' x) -> p ((:*:) a b x) ((:*:) a' b x)
first
  = ((:*:) a b x -> (b x, a x))
-> ((b x, a' x) -> (:*:) a' b x)
-> Lens ((:*:) a b x) ((:*:) a' b x) (a x) (a' x)
forall s c a b t. (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b
lens (\(a :: a x
a :*: b :: b x
b) -> (b x
b,a x
a)) (\(b :: b x
b, a' :: a' x
a') -> a' x
a' a' x -> b x -> (:*:) a' b x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: b x
b)

-- | Lens focusing on the second element of a product
second :: Lens ((a :*: b) x) ((a :*: b') x) (b x) (b' x)
second :: p (b x) (b' x) -> p ((:*:) a b x) ((:*:) a b' x)
second
  = ((:*:) a b x -> (a x, b x))
-> ((a x, b' x) -> (:*:) a b' x)
-> Lens ((:*:) a b x) ((:*:) a b' x) (b x) (b' x)
forall s c a b t. (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b
lens (\(a :: a x
a :*: b :: b x
b) -> (a x
a,b x
b)) (\(a :: a x
a, b' :: b' x
b') -> a x
a a x -> b' x -> (:*:) a b' x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: b' x
b')

fork :: (a -> b) -> (a -> c) -> a -> (b, c)
fork :: (a -> b) -> (a -> c) -> a -> (b, c)
fork f :: a -> b
f g :: a -> c
g a :: a
a = (a -> b
f a
a, a -> c
g a
a)

swap :: (a, b) -> (b, a)
swap :: (a, b) -> (b, a)
swap (a :: a
a, b :: b
b) = (b
b, a
a)

cross :: (a -> b) -> (c -> d) -> (a, c) -> (b, d)
cross :: (a -> b) -> (c -> d) -> (a, c) -> (b, d)
cross = (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap

--------------------------------------------------------------------------------

data Coyoneda f b = forall a. Coyoneda (a -> b) (f a)

instance Functor (Coyoneda f) where
  fmap :: (a -> b) -> Coyoneda f a -> Coyoneda f b
fmap f :: a -> b
f (Coyoneda g :: a -> a
g fa :: f a
fa)
    = (a -> b) -> f a -> Coyoneda f b
forall (f :: * -> *) b a. (a -> b) -> f a -> Coyoneda f b
Coyoneda (a -> b
f (a -> b) -> (a -> a) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
g) f a
fa

inj :: Functor f => Coyoneda f a -> f a
inj :: Coyoneda f a -> f a
inj (Coyoneda f :: a -> a
f a :: f a
a) = (a -> a) -> f a -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
f f a
a

proj :: Functor f => f a -> Coyoneda f a
proj :: f a -> Coyoneda f a
proj fa :: f a
fa = (a -> a) -> f a -> Coyoneda f a
forall (f :: * -> *) b a. (a -> b) -> f a -> Coyoneda f b
Coyoneda a -> a
forall a. a -> a
id f a
fa

newtype Alongside p s t a b = Alongside { Alongside p s t a b -> p (s, a) (t, b)
getAlongside :: p (s, a) (t, b) }

instance Profunctor p => Profunctor (Alongside p c d) where
  dimap :: (a -> b) -> (c -> d) -> Alongside p c d b c -> Alongside p c d a d
dimap f :: a -> b
f g :: c -> d
g (Alongside pab :: p (c, b) (d, c)
pab) = p (c, a) (d, d) -> Alongside p c d a d
forall (p :: * -> * -> *) s t a b.
p (s, a) (t, b) -> Alongside p s t a b
Alongside (p (c, a) (d, d) -> Alongside p c d a d)
-> p (c, a) (d, d) -> Alongside p c d a d
forall a b. (a -> b) -> a -> b
$ ((c, a) -> (c, b))
-> ((d, c) -> (d, d)) -> p (c, b) (d, c) -> p (c, a) (d, d)
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap ((a -> b) -> (c, a) -> (c, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) ((c -> d) -> (d, c) -> (d, d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> d
g) p (c, b) (d, c)
pab

instance Strong p => Strong (Alongside p c d) where
  second' :: Alongside p c d a b -> Alongside p c d (c, a) (c, b)
second' (Alongside pab :: p (c, a) (d, b)
pab) = p (c, (c, a)) (d, (c, b)) -> Alongside p c d (c, a) (c, b)
forall (p :: * -> * -> *) s t a b.
p (s, a) (t, b) -> Alongside p s t a b
Alongside (p (c, (c, a)) (d, (c, b)) -> Alongside p c d (c, a) (c, b))
-> (p (c, a) (d, b) -> p (c, (c, a)) (d, (c, b)))
-> p (c, a) (d, b)
-> Alongside p c d (c, a) (c, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((c, (c, a)) -> (c, (c, a)))
-> ((c, (d, b)) -> (d, (c, b)))
-> p (c, (c, a)) (c, (d, b))
-> p (c, (c, a)) (d, (c, b))
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (c, (c, a)) -> (c, (c, a))
forall a a b. (a, (a, b)) -> (a, (a, b))
shuffle (c, (d, b)) -> (d, (c, b))
forall a a b. (a, (a, b)) -> (a, (a, b))
shuffle (p (c, (c, a)) (c, (d, b)) -> p (c, (c, a)) (d, (c, b)))
-> (p (c, a) (d, b) -> p (c, (c, a)) (c, (d, b)))
-> p (c, a) (d, b)
-> p (c, (c, a)) (d, (c, b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (c, a) (d, b) -> p (c, (c, a)) (c, (d, b))
forall (p :: * -> * -> *) a b c.
Strong p =>
p a b -> p (c, a) (c, b)
second' (p (c, a) (d, b) -> Alongside p c d (c, a) (c, b))
-> p (c, a) (d, b) -> Alongside p c d (c, a) (c, b)
forall a b. (a -> b) -> a -> b
$ p (c, a) (d, b)
pab
   where
    shuffle :: (a, (a, b)) -> (a, (a, b))
shuffle (x :: a
x,(y :: a
y,z :: b
z)) = (a
y,(a
x,b
z))

(??) :: Functor f => f (a -> b) -> a -> f b
fab :: f (a -> b)
fab ?? :: f (a -> b) -> a -> f b
?? a :: a
a = ((a -> b) -> b) -> f (a -> b) -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ a
a) f (a -> b)
fab

-- Could implement this using primitives?
alongside :: Profunctor p =>
          LensLike (Alongside p s' t') s  t  a  b
          -> LensLike (Alongside p a b) s' t' a' b'
          -> LensLike p (s, s') (t, t') (a, a') (b, b')
alongside :: LensLike (Alongside p s' t') s t a b
-> LensLike (Alongside p a b) s' t' a' b'
-> LensLike p (s, s') (t, t') (a, a') (b, b')
alongside l1 :: LensLike (Alongside p s' t') s t a b
l1 l2 :: LensLike (Alongside p a b) s' t' a' b'
l2
  = ((s, s') -> (s', s))
-> ((t', t) -> (t, t')) -> p (s', s) (t', t) -> p (s, s') (t, t')
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (s, s') -> (s', s)
forall a b. (a, b) -> (b, a)
swap (t', t) -> (t, t')
forall a b. (a, b) -> (b, a)
swap (p (s', s) (t', t) -> p (s, s') (t, t'))
-> (p (a, a') (b, b') -> p (s', s) (t', t))
-> LensLike p (s, s') (t, t') (a, a') (b, b')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Alongside p s' t' s t -> p (s', s) (t', t)
forall (p :: * -> * -> *) s t a b.
Alongside p s t a b -> p (s, a) (t, b)
getAlongside (Alongside p s' t' s t -> p (s', s) (t', t))
-> (p (a, a') (b, b') -> Alongside p s' t' s t)
-> p (a, a') (b, b')
-> p (s', s) (t', t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike (Alongside p s' t') s t a b
l1 LensLike (Alongside p s' t') s t a b
-> (p (a, a') (b, b') -> Alongside p s' t' a b)
-> p (a, a') (b, b')
-> Alongside p s' t' s t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (s', a) (t', b) -> Alongside p s' t' a b
forall (p :: * -> * -> *) s t a b.
p (s, a) (t, b) -> Alongside p s t a b
Alongside (p (s', a) (t', b) -> Alongside p s' t' a b)
-> (p (a, a') (b, b') -> p (s', a) (t', b))
-> p (a, a') (b, b')
-> Alongside p s' t' a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((s', a) -> (a, s'))
-> ((b, t') -> (t', b)) -> p (a, s') (b, t') -> p (s', a) (t', b)
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (s', a) -> (a, s')
forall a b. (a, b) -> (b, a)
swap (b, t') -> (t', b)
forall a b. (a, b) -> (b, a)
swap (p (a, s') (b, t') -> p (s', a) (t', b))
-> (p (a, a') (b, b') -> p (a, s') (b, t'))
-> p (a, a') (b, b')
-> p (s', a) (t', b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Alongside p a b s' t' -> p (a, s') (b, t')
forall (p :: * -> * -> *) s t a b.
Alongside p s t a b -> p (s, a) (t, b)
getAlongside (Alongside p a b s' t' -> p (a, s') (b, t'))
-> (p (a, a') (b, b') -> Alongside p a b s' t')
-> p (a, a') (b, b')
-> p (a, s') (b, t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike (Alongside p a b) s' t' a' b'
l2 LensLike (Alongside p a b) s' t' a' b'
-> (p (a, a') (b, b') -> Alongside p a b a' b')
-> p (a, a') (b, b')
-> Alongside p a b s' t'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (a, a') (b, b') -> Alongside p a b a' b'
forall (p :: * -> * -> *) s t a b.
p (s, a) (t, b) -> Alongside p s t a b
Alongside

assoc3L :: Lens ((a, b), c) ((a', b'), c') (a, (b, c)) (a', (b', c'))
assoc3L :: p (a, (b, c)) (a', (b', c')) -> p ((a, b), c) ((a', b'), c')
assoc3L f :: p (a, (b, c)) (a', (b', c'))
f = p (a, (b, c)) (a', (b', c')) -> p ((a, b), c) ((a', b'), c')
forall a b c a' b' c'.
Iso ((a, b), c) ((a', b'), c') (a, (b, c)) (a', (b', c'))
assoc3 p (a, (b, c)) (a', (b', c'))
f

stron :: (Either s s', b) -> Either (s, b) (s', b)
stron :: (Either s s', b) -> Either (s, b) (s', b)
stron (e :: Either s s'
e, b :: b
b) =  (s -> (s, b))
-> (s' -> (s', b)) -> Either s s' -> Either (s, b) (s', b)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (,b
b) (, b
b) Either s s'
e

choosing :: forall s t a b s' t' . Lens s t a b -> Lens s' t' a b -> Lens (Either s s') (Either t t') a b
choosing :: Lens s t a b
-> Lens s' t' a b -> Lens (Either s s') (Either t t') a b
choosing l :: Lens s t a b
l r :: Lens s' t' a b
r = Lens s t a b
-> (forall c.
    (s -> (c, a))
    -> ((c, b) -> t) -> p a b -> p (Either s s') (Either t t'))
-> p a b
-> p (Either s s') (Either t t')
forall s t a b r.
Lens s t a b
-> (forall c. (s -> (c, a)) -> ((c, b) -> t) -> r) -> r
withLensPrim Lens s t a b
l (\getl :: s -> (c, a)
getl setl :: (c, b) -> t
setl ->
                  Lens s' t' a b
-> (forall c.
    (s' -> (c, a))
    -> ((c, b) -> t') -> p a b -> p (Either s s') (Either t t'))
-> p a b
-> p (Either s s') (Either t t')
forall s t a b r.
Lens s t a b
-> (forall c. (s -> (c, a)) -> ((c, b) -> t) -> r) -> r
withLensPrim Lens s' t' a b
r (\getr :: s' -> (c, a)
getr setr :: (c, b) -> t'
setr ->
                            let --g :: Either s s' -> a
                                g :: Either s s' -> (Either c c, a)
g e :: Either s s'
e = case Either s s'
e of
                                        Left v :: s
v -> let (c :: c
c, v' :: a
v') = s -> (c, a)
getl s
v in (c -> Either c c
forall a b. a -> Either a b
Left c
c, a
v')
                                        Right v :: s'
v -> let (c :: c
c, v' :: a
v') = s' -> (c, a)
getr s'
v in (c -> Either c c
forall a b. b -> Either a b
Right c
c, a
v')
                                s :: (Either c c, b) -> Either t t'
s = ((c, b) -> t)
-> ((c, b) -> t') -> Either (c, b) (c, b) -> Either t t'
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (c, b) -> t
setl (c, b) -> t'
setr (Either (c, b) (c, b) -> Either t t')
-> ((Either c c, b) -> Either (c, b) (c, b))
-> (Either c c, b)
-> Either t t'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either c c, b) -> Either (c, b) (c, b)
forall s s' b. (Either s s', b) -> Either (s, b) (s', b)
stron
                            in (Either s s' -> (Either c c, a))
-> ((Either c c, b) -> Either t t')
-> Lens (Either s s') (Either t t') a b
forall s c a b t. (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b
lens Either s s' -> (Either c c, a)
g (Either c c, b) -> Either t t'
s))

lens :: (s -> (c,a)) -> ((c,b) -> t) -> Lens s t a b
lens :: (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b
lens get :: s -> (c, a)
get _set :: (c, b) -> t
_set = (s -> (c, a)) -> ((c, b) -> t) -> p (c, a) (c, b) -> p s t
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap s -> (c, a)
get (c, b) -> t
_set (p (c, a) (c, b) -> p s t)
-> (p a b -> p (c, a) (c, b)) -> p a b -> p s t
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'
{-# INLINE lens #-}

------------------------------------------------------------------------------

data ALens a b s t = forall c . ALens (s -> (c,a)) ((c, b) -> t)

instance Functor (ALens a b s) where
  fmap :: (a -> b) -> ALens a b s a -> ALens a b s b
fmap f :: a -> b
f (ALens _get :: s -> (c, a)
_get _set :: (c, b) -> a
_set) = (s -> (c, a)) -> ((c, b) -> b) -> ALens a b s b
forall a b s t c. (s -> (c, a)) -> ((c, b) -> t) -> ALens a b s t
ALens s -> (c, a)
_get (a -> b
f (a -> b) -> ((c, b) -> a) -> (c, b) -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c, b) -> a
_set)

instance Profunctor (ALens a b) where
  dimap :: (a -> b) -> (c -> d) -> ALens a b b c -> ALens a b a d
dimap f :: a -> b
f g :: c -> d
g (ALens get :: b -> (c, a)
get _set :: (c, b) -> c
_set) = (a -> (c, a)) -> ((c, b) -> d) -> ALens a b a d
forall a b s t c. (s -> (c, a)) -> ((c, b) -> t) -> ALens a b s t
ALens (b -> (c, a)
get (b -> (c, a)) -> (a -> b) -> a -> (c, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) (c -> d
g (c -> d) -> ((c, b) -> c) -> (c, b) -> d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c, b) -> c
_set)

instance Strong (ALens a b) where
  second' :: ALens a b a b -> ALens a b (c, a) (c, b)
second' (ALens get :: a -> (c, a)
get _set :: (c, b) -> b
_set) = ((c, a) -> ((c, c), a))
-> (((c, c), b) -> (c, b)) -> ALens a b (c, a) (c, b)
forall a b s t c. (s -> (c, a)) -> ((c, b) -> t) -> ALens a b s t
ALens (c, a) -> ((c, c), a)
get' ((c, c), b) -> (c, b)
set' --(bimap id _set . assoc)
    where
      get' :: (c, a) -> ((c, c), a)
get' (c :: c
c, a1 :: a
a1) = let (c1 :: c
c1, a :: a
a) = a -> (c, a)
get a
a1 in ((c
c, c
c1), a
a)
      set' :: ((c, c), b) -> (c, b)
set' ((c :: c
c, c1 :: c
c1), b :: b
b) = (c
c, (c, b) -> b
_set (c
c1, b
b))
  {-# INLINE second' #-}

-- These are specialised versions of the Isos. On GHC 8.0.2, having
-- these functions eta-expanded allows the optimiser to inline these functions.
mLens :: Lens (M1 i c f p) (M1 i c g p) (f p) (g p)
mLens :: p (f p) (g p) -> p (M1 i c f p) (M1 i c g p)
mLens f :: p (f p) (g p)
f = p (f p) (g p) -> p (M1 i c f p) (M1 i c g p)
forall i (c :: Meta) (f :: * -> *) p (g :: * -> *).
Iso (M1 i c f p) (M1 i c g p) (f p) (g p)
mIso p (f p) (g p)
f

repLens :: (Generic a, Generic b) => Lens a b (Rep a x) (Rep b x)
repLens :: Lens a b (Rep a x) (Rep b x)
repLens f :: p (Rep a x) (Rep b x)
f = p (Rep a x) (Rep b x) -> p a b
forall a b x. (Generic a, Generic b) => Iso a b (Rep a x) (Rep b x)
repIso p (Rep a x) (Rep b x)
f

prodL :: Lens ((a :*: b) x) ((a' :*: b') x) (a x, b x) (a' x, b' x)
prodL :: p (a x, b x) (a' x, b' x) -> p ((:*:) a b x) ((:*:) a' b' x)
prodL f :: p (a x, b x) (a' x, b' x)
f = p (a x, b x) (a' x, b' x) -> p ((:*:) a b x) ((:*:) a' b' x)
forall (a :: * -> *) (b :: * -> *) x (a' :: * -> *) (b' :: * -> *).
Iso ((:*:) a b x) ((:*:) a' b' x) (a x, b x) (a' x, b' x)
prodIso p (a x, b x) (a' x, b' x)
f

prodR :: Lens (a' x, b' x) (a x, b x) ((a' :*: b') x) ((a :*: b) x)
prodR :: p ((:*:) a' b' x) ((:*:) a b x) -> p (a' x, b' x) (a x, b x)
prodR f :: p ((:*:) a' b' x) ((:*:) a b x)
f = Iso ((:*:) a b x) ((:*:) a' b' x) (a x, b x) (a' x, b' x)
-> p ((:*:) a' b' x) ((:*:) a b x) -> p (a' x, b' x) (a x, b x)
forall s t a b. Iso s t a b -> Iso b a t s
fromIso forall (a :: * -> *) (b :: * -> *) x (a' :: * -> *) (b' :: * -> *).
Iso ((:*:) a b x) ((:*:) a' b' x) (a x, b x) (a' x, b' x)
Iso ((:*:) a b x) ((:*:) a' b' x) (a x, b x) (a' x, b' x)
prodIso p ((:*:) a' b' x) ((:*:) a b x)
f

assoc3R :: Lens (a', (b', c')) (a, (b, c)) ((a', b'), c') ((a, b), c)
assoc3R :: p ((a', b'), c') ((a, b), c) -> p (a', (b', c')) (a, (b, c))
assoc3R f :: p ((a', b'), c') ((a, b), c)
f = Iso ((a, b), c) ((a', b'), c') (a, (b, c)) (a', (b', c'))
-> p ((a', b'), c') ((a, b), c) -> p (a', (b', c')) (a, (b, c))
forall s t a b. Iso s t a b -> Iso b a t s
fromIso forall a b c a' b' c'.
Iso ((a, b), c) ((a', b'), c') (a, (b, c)) (a', (b', c'))
Iso ((a, b), c) ((a', b'), c') (a, (b, c)) (a', (b', c'))
assoc3 p ((a', b'), c') ((a, b), c)
f