{-# OPTIONS_GHC -Wno-orphans #-}

module Dhall.Syntax.Instances.Bifunctor () where

import Data.Bifunctor                 (Bifunctor (..))
import Dhall.Syntax.Binding
import Dhall.Syntax.Expr
import Dhall.Syntax.FunctionBinding
import Dhall.Syntax.Instances.Functor ()
import Dhall.Syntax.Operations
import Dhall.Syntax.RecordField

import qualified Lens.Family as Lens

instance Bifunctor Binding where
    first :: forall a b c. (a -> b) -> Binding a c -> Binding b c
first a -> b
k (Binding Maybe a
src0 Text
a Maybe a
src1 Maybe (Maybe a, Expr a c)
b Maybe a
src2 Expr a c
c) =
        forall s a.
Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s a)
-> Maybe s
-> Expr s a
-> Binding s a
Binding (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
k Maybe a
src0) Text
a (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
k Maybe a
src1) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {f :: * -> *} {p :: * -> * -> *} {c}.
(Functor f, Bifunctor p) =>
(f a, p a c) -> (f b, p b c)
adapt0 Maybe (Maybe a, Expr a c)
b) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
k Maybe a
src2) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
c)
      where
        adapt0 :: (f a, p a c) -> (f b, p b c)
adapt0 (f a
src3, p a c
d) = (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
k f a
src3, forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k p a c
d)

    second :: forall b c a. (b -> c) -> Binding a b -> Binding a c
second = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

instance Bifunctor RecordField where
    first :: forall a b c. (a -> b) -> RecordField a c -> RecordField b c
first a -> b
k (RecordField Maybe a
s0 Expr a c
value' Maybe a
s1 Maybe a
s2) =
        forall s a.
Maybe s -> Expr s a -> Maybe s -> Maybe s -> RecordField s a
RecordField (a -> b
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
s0) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
value') (a -> b
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
s1) (a -> b
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
s2)
    second :: forall b c a. (b -> c) -> RecordField a b -> RecordField a c
second = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

instance Bifunctor FunctionBinding where
    first :: forall a b c.
(a -> b) -> FunctionBinding a c -> FunctionBinding b c
first a -> b
k (FunctionBinding Maybe a
src0 Text
label Maybe a
src1 Maybe a
src2 Expr a c
type_) =
        forall s a.
Maybe s
-> Text -> Maybe s -> Maybe s -> Expr s a -> FunctionBinding s a
FunctionBinding (a -> b
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
src0) Text
label (a -> b
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
src1) (a -> b
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
src2) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
type_)

    second :: forall b c a.
(b -> c) -> FunctionBinding a b -> FunctionBinding a c
second = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

instance Bifunctor Expr where
    first :: forall a b c. (a -> b) -> Expr a c -> Expr b c
first a -> b
k (Note a
a Expr a c
b   ) = forall s a. s -> Expr s a -> Expr s a
Note (a -> b
k a
a) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
b)
    first a -> b
_ (Embed c
a    ) = forall s a. a -> Expr s a
Embed c
a
    first a -> b
k (Let Binding a c
a Expr a c
b    ) = forall s a. Binding s a -> Expr s a -> Expr s a
Let (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Binding a c
a) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
b)
    first a -> b
k (Record Map Text (RecordField a c)
a   ) = forall s a. Map Text (RecordField s a) -> Expr s a
Record forall a b. (a -> b) -> a -> b
$ forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map Text (RecordField a c)
a
    first a -> b
k (RecordLit Map Text (RecordField a c)
a) = forall s a. Map Text (RecordField s a) -> Expr s a
RecordLit forall a b. (a -> b) -> a -> b
$ forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map Text (RecordField a c)
a
    first a -> b
k (Lam Maybe CharacterSet
cs FunctionBinding a c
a Expr a c
b ) = forall s a.
Maybe CharacterSet -> FunctionBinding s a -> Expr s a -> Expr s a
Lam Maybe CharacterSet
cs (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k FunctionBinding a c
a) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
b)
    first a -> b
k (Field Expr a c
a FieldSelection a
b  ) = forall s a. Expr s a -> FieldSelection s -> Expr s a
Field (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
a) (a -> b
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldSelection a
b)
    first a -> b
k  Expr a c
expression  = forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
Lens.over forall (f :: * -> *) s a t b.
Applicative f =>
(Expr s a -> f (Expr t b)) -> Expr s a -> f (Expr t b)
unsafeSubExpressions (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k) Expr a c
expression

    second :: forall b c a. (b -> c) -> Expr a b -> Expr a c
second = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap