{-# OPTIONS_GHC -Wunused-imports #-}

-- | A cut-down implementation of lenses, with names mostly taken from
--   Edward Kmett's lens package.

module Agda.Utils.Lens
  ( module Agda.Utils.Lens
  , (<&>) -- reexported from Agda.Utils.Functor
  , (&&&) -- reexported from Control.Arrow
  , (&)   -- reexported from Data.Function
  ) where

import Control.Applicative ( Const(Const), getConst )
import Control.Arrow       ( (&&&) )
import Control.Monad.State.Class (MonadState(..), gets, modify, modify')
import Control.Monad.Reader.Class (MonadReader(..))

import Data.Map (Map)
import Data.Map qualified as Map
import Data.Set (Set)
import Data.Set qualified as Set
import Data.Functor.Identity
import Data.Function ((&))
import Data.Functor ((<&>))

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

-- | Van Laarhoven style homogeneous lenses.
--   Mnemoic: "Lens outer inner", same type argument order as 'get :: o -> i'.
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
type Lens' s a = Lens s s a a

type LensGet o i = o -> i
type LensSet o i = i -> o -> o
type LensMap o i = (i -> i) -> o -> o

type Getting r s a   = (a -> Const r a) -> s -> Const r s
type ASetter s t a b = (a -> Identity b) -> s -> Identity t

-- * Elementary lens operations.

infixl 8 ^.
{-# INLINE (^.) #-}
-- | Get inner part @i@ of structure @o@ as designated by @Lens' o i@.
(^.) :: s -> Getting a s a -> a
s
s ^. :: forall s a. s -> Getting a s a -> a
^. Getting a s a
l = Const a s -> a
forall {k} a (b :: k). Const a b -> a
getConst (Getting a s a
l a -> Const a a
forall {k} a (b :: k). a -> Const a b
Const s
s)

{-# INLINE set #-}
-- | Set inner part @i@ of structure @o@ as designated by @Lens' o i@.
set :: ASetter s t a b -> b -> s -> t
set :: forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter s t a b
l = \b
b -> ASetter s t a b -> (a -> b) -> s -> t
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter s t a b
l (\a
_ -> b
b)

{-# INLINE set' #-}
-- | Strictly set inner part @i@ of structure @o@ as designated by @Lens' o i@.
set' :: ASetter s t a b -> b -> s -> t
set' :: forall s t a b. ASetter s t a b -> b -> s -> t
set' ASetter s t a b
l = \ !b
b -> ASetter s t a b -> (a -> b) -> s -> t
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter s t a b
l (\a
_ -> b
b)

{-# INLINE (.~) #-}
infixr 4 .~
(.~) :: ASetter s t a b -> b -> s -> t
.~ :: forall s t a b. ASetter s t a b -> b -> s -> t
(.~) = ASetter s t a b -> b -> s -> t
forall s t a b. ASetter s t a b -> b -> s -> t
set

{-# INLINE over #-}
-- | Modify inner part @i@ of structure @o@ using a function @i -> i@.
over :: ASetter s t a b -> (a -> b) -> s -> t
over :: forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter s t a b
l = \a -> b
f s
s -> Identity t -> t
forall a. Identity a -> a
runIdentity (ASetter s t a b
l (b -> Identity b
forall a. a -> Identity a
Identity (b -> Identity b) -> (a -> b) -> a -> Identity b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) s
s)

{-# INLINE over' #-}
-- | Strictly modify inner part @i@ of structure @o@ using a function @i -> i@.
over' :: ASetter s t a b -> (a -> b) -> s -> t
over' :: forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over' ASetter s t a b
l = \a -> b
f s
s -> Identity t -> t
forall a. Identity a -> a
runIdentity (ASetter s t a b
l (\a
x -> b -> Identity b
forall a. a -> Identity a
Identity (b -> Identity b) -> b -> Identity b
forall a b. (a -> b) -> a -> b
$! a -> b
f a
x) s
s)

infixr 4 %~
(%~) :: ASetter s t a b -> (a -> b) -> s -> t
%~ :: forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
(%~) = ASetter s t a b -> (a -> b) -> s -> t
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over

infixr 4 %~!
(%~!) :: ASetter s t a b -> (a -> b) -> s -> t
%~! :: forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
(%~!) = ASetter s t a b -> (a -> b) -> s -> t
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over'

{-# INLINE iso #-}
-- | Build a lens out of an isomorphism.
iso :: (o -> i) -> (i -> o) -> Lens' o i
iso :: forall o i. (o -> i) -> (i -> o) -> Lens' o i
iso o -> i
get i -> o
set = \i -> f i
f -> (i -> o) -> f i -> f o
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap i -> o
set (f i -> f o) -> (o -> f i) -> o -> f o
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> f i
f (i -> f i) -> (o -> i) -> o -> f i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. o -> i
get

{-# INLINE lens #-}
-- | Build a lens from a getter and a setter.
lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
lens :: forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens s -> a
sa s -> b -> t
sbt = \a -> f b
afb s
s -> s -> b -> t
sbt s
s (b -> t) -> f b -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
afb (s -> a
sa s
s)

{-# INLINE lensProduct #-}
-- | Only sound if the lenses are disjoint!
lensProduct :: Lens' s a -> Lens' s b -> Lens' s (a , b)
lensProduct :: forall s a b. Lens' s a -> Lens' s b -> Lens' s (a, b)
lensProduct Lens' s a
l1 Lens' s b
l2 = (s -> (a, b)) -> (s -> (a, b) -> s) -> Lens s s (a, b) (a, b)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\s
s -> (s
s s -> Getting a s a -> a
forall s a. s -> Getting a s a -> a
^. Getting a s a
Lens' s a
l1, s
s s -> Getting b s b -> b
forall s a. s -> Getting a s a -> a
^. Getting b s b
Lens' s b
l2)) (\s
s (a
a, b
b) -> ASetter s s a a -> a -> s -> s
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter s s a a
Lens' s a
l1 a
a (s -> s) -> s -> s
forall a b. (a -> b) -> a -> b
$ ASetter s s b b -> b -> s -> s
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter s s b b
Lens' s b
l2 b
b s
s)

-- * Reader/State accessors and modifiers.

-- | Read part of the environment.
{-# INLINE view #-}
view :: MonadReader s m => Getting a s a -> m a
view :: forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting a s a
l = (s -> Getting a s a -> a
forall s a. s -> Getting a s a -> a
^. Getting a s a
l) (s -> a) -> m s -> m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m s
forall r (m :: * -> *). MonadReader r m => m r
ask

{-# INLINE use #-}
-- | Read a part of the state.
use :: MonadState s m => Getting a s a -> m a
use :: forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting a s a
l = (s -> a) -> m a
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (s -> Getting a s a -> a
forall s a. s -> Getting a s a -> a
^. Getting a s a
l)

{-# INLINE (.=) #-}
infix 4 .=
-- | Write a part of the state.
(.=) :: MonadState s m => ASetter s s a b -> b -> m ()
ASetter s s a b
l .= :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= b
b = (s -> s) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (ASetter s s a b -> b -> s -> s
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter s s a b
l b
b)

{-# INLINE (.=!) #-}
infix 4 .=!
-- | Strictly write a part of the state.
(.=!) :: MonadState s m => ASetter s s a b -> b -> m ()
ASetter s s a b
l .=! :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.=! b
b = (s -> s) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify' (ASetter s s a b -> b -> s -> s
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter s s a b
l b
b)

{-# INLINE (%=) #-}
infix 4 %=
-- | Modify a part of the state.
(%=) :: MonadState s m => ASetter s s a b -> (a -> b) -> m ()
ASetter s s a b
l %= :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= a -> b
f = (s -> s) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (ASetter s s a b -> (a -> b) -> s -> s
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter s s a b
l a -> b
f)

{-# INLINE (%=!) #-}
infix 4 %=!
-- | Strictly modify a part of the state.
(%=!) :: MonadState s m => ASetter s s a b -> (a -> b) -> m ()
ASetter s s a b
l %=! :: forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%=! a -> b
f = (s -> s) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify' (ASetter s s a b -> (a -> b) -> s -> s
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter s s a b
l a -> b
f)

{-# INLINE (%==) #-}
infix 4 %==
-- | Modify a part of the state monadically.
(%==) :: MonadState s m => Lens' s a -> (a -> m a) -> m ()
Lens' s a
l %== :: forall s (m :: * -> *) a.
MonadState s m =>
Lens' s a -> (a -> m a) -> m ()
%== a -> m a
f = do
  a <- Getting a s a -> m a
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting a s a
Lens' s a
l
  a <- f a
  modify (set l a)

{-# INLINE (%==!) #-}
infix 4 %==!
-- | Strictly modify a part of the state monadically.
(%==!) :: MonadState s m => Lens' s a -> (a -> m a) -> m ()
Lens' s a
l %==! :: forall s (m :: * -> *) a.
MonadState s m =>
Lens' s a -> (a -> m a) -> m ()
%==! a -> m a
f = do
  a <- Getting a s a -> m a
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting a s a
Lens' s a
l
  a <- f a
  modify' (set l a)

{-# INLINE (%%=) #-}
infix 4 %%=
-- | Modify a part of the state monadically, and return some result.
(%%=) :: MonadState o m => Lens' o i -> (i -> m (i, r)) -> m r
Lens' o i
l %%= :: forall o (m :: * -> *) i r.
MonadState o m =>
Lens' o i -> (i -> m (i, r)) -> m r
%%= i -> m (i, r)
f = do
  i <- Getting i o i -> m i
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting i o i
Lens' o i
l
  (i', r) <- f i
  l .= i'
  return r

{-# INLINE (%%=!) #-}
infix 4 %%=!
-- | Strictly modify a part of the state monadically, and return some result.
(%%=!) :: MonadState o m => Lens' o i -> (i -> m (i, r)) -> m r
Lens' o i
l %%=! :: forall o (m :: * -> *) i r.
MonadState o m =>
Lens' o i -> (i -> m (i, r)) -> m r
%%=! i -> m (i, r)
f = do
  i <- Getting i o i -> m i
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting i o i
Lens' o i
l
  (!i', !r) <- f i
  l .= i'
  return r

{-# INLINE locallyState #-}
-- | Modify a part of the state locally.
locallyState :: MonadState o m => Lens' o i -> (i -> i) -> m r -> m r
locallyState :: forall o (m :: * -> *) i r.
MonadState o m =>
Lens' o i -> (i -> i) -> m r -> m r
locallyState Lens' o i
l i -> i
f m r
k = do
  old <- Getting i o i -> m i
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting i o i
Lens' o i
l
  l %= f
  x <- k
  l .= old
  return x

{-# INLINE locally #-}
-- | Modify a part of the state in a subcomputation.
locally :: MonadReader r m => ASetter r r a b -> (a -> b) -> m c -> m c
locally :: forall r (m :: * -> *) a b c.
MonadReader r m =>
ASetter r r a b -> (a -> b) -> m c -> m c
locally ASetter r r a b
l = (r -> r) -> m c -> m c
forall a. (r -> r) -> m a -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((r -> r) -> m c -> m c)
-> ((a -> b) -> r -> r) -> (a -> b) -> m c -> m c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter r r a b -> (a -> b) -> r -> r
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter r r a b
l

-- * Lenses for collections

{-# INLINE key #-}
-- | Access a map value at a given key.
key :: Ord k => k -> Lens' (Map k v) (Maybe v)
key :: forall k v. Ord k => k -> Lens' (Map k v) (Maybe v)
key k
k = \Maybe v -> f (Maybe v)
f Map k v
s -> (Maybe v -> f (Maybe v)) -> k -> Map k v -> f (Map k v)
forall (f :: * -> *) k a.
(Functor f, Ord k) =>
(Maybe a -> f (Maybe a)) -> k -> Map k a -> f (Map k a)
Map.alterF Maybe v -> f (Maybe v)
f k
k Map k v
s

{-# INLINE contains #-}
-- | Focus on given element in a set.
contains :: Ord k => k -> Lens' (Set k) Bool
contains :: forall k. Ord k => k -> Lens' (Set k) Bool
contains k
k Bool -> f Bool
f Set k
s = Bool -> f Bool
f (k -> Set k -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member k
k Set k
s) f Bool -> (Bool -> Set k) -> f (Set k)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
  Bool
True  -> k -> Set k -> Set k
forall a. Ord a => a -> Set a -> Set a
Set.insert k
k Set k
s
  Bool
False -> k -> Set k -> Set k
forall a. Ord a => a -> Set a -> Set a
Set.delete k
k Set k
s

-- Tuple field lenses (up to 5-tuples currently)
--------------------------------------------------------------------------------

class Field1 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  _1  :: Lens s t a b
  _1' :: Lens s t a b

instance Field1 (a,b) (a',b) a a' where
  _1 :: Lens (a, b) (a', b) a a'
_1  = \a -> f a'
k (a
a,b
b) -> (\  a'
a -> (a'
a,b
b)) (a' -> (a', b)) -> f a' -> f (a', b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a'
k a
a
  _1' :: Lens (a, b) (a', b) a a'
_1' = \a -> f a'
k (a
a,b
b) -> (\ !a'
a -> (a'
a,b
b)) (a' -> (a', b)) -> f a' -> f (a', b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a'
k a
a
  {-# INLINE _1 #-}
  {-# INLINE _1' #-}

instance Field1 (a,b,c) (a',b,c) a a' where
  _1 :: Lens (a, b, c) (a', b, c) a a'
_1  = \a -> f a'
k (a
a,b
b,c
c) -> (\  a'
a -> (a'
a,b
b,c
c)) (a' -> (a', b, c)) -> f a' -> f (a', b, c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a'
k a
a
  _1' :: Lens (a, b, c) (a', b, c) a a'
_1' = \a -> f a'
k (a
a,b
b,c
c) -> (\ !a'
a -> (a'
a,b
b,c
c)) (a' -> (a', b, c)) -> f a' -> f (a', b, c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a'
k a
a
  {-# INLINE _1 #-}
  {-# INLINE _1' #-}

instance Field1 (a,b,c,d) (a',b,c,d) a a' where
  _1 :: Lens (a, b, c, d) (a', b, c, d) a a'
_1  = \a -> f a'
k (a
a,b
b,c
c,d
d) -> (\  a'
a -> (a'
a,b
b,c
c,d
d)) (a' -> (a', b, c, d)) -> f a' -> f (a', b, c, d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a'
k a
a
  _1' :: Lens (a, b, c, d) (a', b, c, d) a a'
_1' = \a -> f a'
k (a
a,b
b,c
c,d
d) -> (\ !a'
a -> (a'
a,b
b,c
c,d
d)) (a' -> (a', b, c, d)) -> f a' -> f (a', b, c, d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a'
k a
a
  {-# INLINE _1 #-}
  {-# INLINE _1' #-}

instance Field1 (a,b,c,d,e) (a',b,c,d,e) a a' where
  _1 :: Lens (a, b, c, d, e) (a', b, c, d, e) a a'
_1  = \a -> f a'
k (a
a,b
b,c
c,d
d,e
e) -> (\  a'
a -> (a'
a,b
b,c
c,d
d,e
e)) (a' -> (a', b, c, d, e)) -> f a' -> f (a', b, c, d, e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a'
k a
a
  _1' :: Lens (a, b, c, d, e) (a', b, c, d, e) a a'
_1' = \a -> f a'
k (a
a,b
b,c
c,d
d,e
e) -> (\ !a'
a -> (a'
a,b
b,c
c,d
d,e
e)) (a' -> (a', b, c, d, e)) -> f a' -> f (a', b, c, d, e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a'
k a
a
  {-# INLINE _1 #-}
  {-# INLINE _1' #-}

class Field2 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  _2  :: Lens s t a b
  _2' :: Lens s t a b

instance Field2 (a,b) (a,b') b b' where
  _2 :: Lens (a, b) (a, b') b b'
_2  = \b -> f b'
k (a
a,b
b) -> (\  b'
b -> (a
a,b'
b)) (b' -> (a, b')) -> f b' -> f (a, b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f b'
k b
b
  _2' :: Lens (a, b) (a, b') b b'
_2' = \b -> f b'
k (a
a,b
b) -> (\ !b'
b -> (a
a,b'
b)) (b' -> (a, b')) -> f b' -> f (a, b')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f b'
k b
b
  {-# INLINE _2 #-}
  {-# INLINE _2' #-}

instance Field2 (a,b,c) (a,b',c) b b' where
  _2 :: Lens (a, b, c) (a, b', c) b b'
_2  = \b -> f b'
k (a
a,b
b,c
c) -> (\  b'
b -> (a
a,b'
b,c
c)) (b' -> (a, b', c)) -> f b' -> f (a, b', c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f b'
k b
b
  _2' :: Lens (a, b, c) (a, b', c) b b'
_2' = \b -> f b'
k (a
a,b
b,c
c) -> (\ !b'
b -> (a
a,b'
b,c
c)) (b' -> (a, b', c)) -> f b' -> f (a, b', c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f b'
k b
b
  {-# INLINE _2 #-}
  {-# INLINE _2' #-}

instance Field2 (a,b,c,d) (a,b',c,d) b b' where
  _2 :: Lens (a, b, c, d) (a, b', c, d) b b'
_2  = \b -> f b'
k (a
a,b
b,c
c,d
d) -> (\  b'
b -> (a
a,b'
b,c
c,d
d)) (b' -> (a, b', c, d)) -> f b' -> f (a, b', c, d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f b'
k b
b
  _2' :: Lens (a, b, c, d) (a, b', c, d) b b'
_2' = \b -> f b'
k (a
a,b
b,c
c,d
d) -> (\ !b'
b -> (a
a,b'
b,c
c,d
d)) (b' -> (a, b', c, d)) -> f b' -> f (a, b', c, d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f b'
k b
b
  {-# INLINE _2 #-}
  {-# INLINE _2' #-}

instance Field2 (a,b,c,d,e) (a,b',c,d,e) b b' where
  _2 :: Lens (a, b, c, d, e) (a, b', c, d, e) b b'
_2  = \b -> f b'
k (a
a,b
b,c
c,d
d,e
e) -> (\  b'
b -> (a
a,b'
b,c
c,d
d,e
e)) (b' -> (a, b', c, d, e)) -> f b' -> f (a, b', c, d, e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f b'
k b
b
  _2' :: Lens (a, b, c, d, e) (a, b', c, d, e) b b'
_2' = \b -> f b'
k (a
a,b
b,c
c,d
d,e
e) -> (\ !b'
b -> (a
a,b'
b,c
c,d
d,e
e)) (b' -> (a, b', c, d, e)) -> f b' -> f (a, b', c, d, e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f b'
k b
b
  {-# INLINE _2 #-}
  {-# INLINE _2' #-}

class Field3 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  _3  :: Lens s t a b
  _3' :: Lens s t a b

instance Field3 (a,b,c) (a,b,c') c c' where
  _3 :: Lens (a, b, c) (a, b, c') c c'
_3  = \c -> f c'
k (a
a,b
b,c
c) -> (\  c'
c -> (a
a,b
b,c'
c)) (c' -> (a, b, c')) -> f c' -> f (a, b, c')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> f c'
k c
c
  _3' :: Lens (a, b, c) (a, b, c') c c'
_3' = \c -> f c'
k (a
a,b
b,c
c) -> (\ !c'
c -> (a
a,b
b,c'
c)) (c' -> (a, b, c')) -> f c' -> f (a, b, c')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> f c'
k c
c
  {-# INLINE _3 #-}
  {-# INLINE _3' #-}

instance Field3 (a,b,c,d) (a,b,c',d) c c' where
  _3 :: Lens (a, b, c, d) (a, b, c', d) c c'
_3  = \c -> f c'
k (a
a,b
b,c
c,d
d) -> (\  c'
c -> (a
a,b
b,c'
c,d
d)) (c' -> (a, b, c', d)) -> f c' -> f (a, b, c', d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> f c'
k c
c
  _3' :: Lens (a, b, c, d) (a, b, c', d) c c'
_3' = \c -> f c'
k (a
a,b
b,c
c,d
d) -> (\ !c'
c -> (a
a,b
b,c'
c,d
d)) (c' -> (a, b, c', d)) -> f c' -> f (a, b, c', d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> f c'
k c
c
  {-# INLINE _3 #-}
  {-# INLINE _3' #-}

instance Field3 (a,b,c,d,e) (a,b,c',d,e) c c' where
  _3 :: Lens (a, b, c, d, e) (a, b, c', d, e) c c'
_3  = \c -> f c'
k (a
a,b
b,c
c,d
d,e
e) -> (\  c'
c -> (a
a,b
b,c'
c,d
d,e
e)) (c' -> (a, b, c', d, e)) -> f c' -> f (a, b, c', d, e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> f c'
k c
c
  _3' :: Lens (a, b, c, d, e) (a, b, c', d, e) c c'
_3' = \c -> f c'
k (a
a,b
b,c
c,d
d,e
e) -> (\ !c'
c -> (a
a,b
b,c'
c,d
d,e
e)) (c' -> (a, b, c', d, e)) -> f c' -> f (a, b, c', d, e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> c -> f c'
k c
c
  {-# INLINE _3 #-}
  {-# INLINE _3' #-}

class Field4 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  _4  :: Lens s t a b
  _4' :: Lens s t a b

instance Field4 (a,b,c,d) (a,b,c,d') d d' where
  _4 :: Lens (a, b, c, d) (a, b, c, d') d d'
_4  = \d -> f d'
k (a
a,b
b,c
c,d
d) -> (\  d'
d -> (a
a,b
b,c
c,d'
d)) (d' -> (a, b, c, d')) -> f d' -> f (a, b, c, d')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> d -> f d'
k d
d
  _4' :: Lens (a, b, c, d) (a, b, c, d') d d'
_4' = \d -> f d'
k (a
a,b
b,c
c,d
d) -> (\ !d'
d -> (a
a,b
b,c
c,d'
d)) (d' -> (a, b, c, d')) -> f d' -> f (a, b, c, d')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> d -> f d'
k d
d
  {-# INLINE _4 #-}
  {-# INLINE _4' #-}

instance Field4 (a,b,c,d,e) (a,b,c,d',e) d d' where
  _4 :: Lens (a, b, c, d, e) (a, b, c, d', e) d d'
_4  = \d -> f d'
k (a
a,b
b,c
c,d
d,e
e) -> (\  d'
d -> (a
a,b
b,c
c,d'
d,e
e)) (d' -> (a, b, c, d', e)) -> f d' -> f (a, b, c, d', e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> d -> f d'
k d
d
  _4' :: Lens (a, b, c, d, e) (a, b, c, d', e) d d'
_4' = \d -> f d'
k (a
a,b
b,c
c,d
d,e
e) -> (\ !d'
d -> (a
a,b
b,c
c,d'
d,e
e)) (d' -> (a, b, c, d', e)) -> f d' -> f (a, b, c, d', e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> d -> f d'
k d
d
  {-# INLINE _4 #-}
  {-# INLINE _4' #-}

class Field5 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  _5  :: Lens s t a b
  _5' :: Lens s t a b

instance Field5 (a,b,c,d,e) (a,b,c,d,e') e e' where
  _5 :: Lens (a, b, c, d, e) (a, b, c, d, e') e e'
_5  = \e -> f e'
k (a
a,b
b,c
c,d
d,e
e) -> (\  e'
e -> (a
a,b
b,c
c,d
d,e'
e)) (e' -> (a, b, c, d, e')) -> f e' -> f (a, b, c, d, e')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> f e'
k e
e
  _5' :: Lens (a, b, c, d, e) (a, b, c, d, e') e e'
_5' = \e -> f e'
k (a
a,b
b,c
c,d
d,e
e) -> (\ !e'
e -> (a
a,b
b,c
c,d
d,e'
e)) (e' -> (a, b, c, d, e')) -> f e' -> f (a, b, c, d, e')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> e -> f e'
k e
e
  {-# INLINE _5 #-}
  {-# INLINE _5' #-}