    {-# 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) =
            Maybe b
    -> Text
    -> Maybe b
    -> Maybe (Maybe b, Expr b c)
    -> Maybe b
    -> Expr b c
    -> Binding b c
    forall s a.
    Maybe s
    -> Text
    -> Maybe s
    -> Maybe (Maybe s, Expr s a)
    -> Maybe s
    -> Expr s a
    -> Binding s a
    Binding ((a -> b) -> Maybe a -> Maybe b
    forall a b. (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> b
    k Maybe a
    src0) Text
    a ((a -> b) -> Maybe a -> Maybe b
    forall a b. (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> b
    k Maybe a
    src1) (((Maybe a, Expr a c) -> (Maybe b, Expr b c))
    -> Maybe (Maybe a, Expr a c) -> Maybe (Maybe b, Expr b c)
    forall a b. (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Maybe a, Expr a c) -> (Maybe b, Expr b c)
    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) ((a -> b) -> Maybe a -> Maybe b
    forall a b. (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> b
    k Maybe a
    src2) ((a -> b) -> Expr a c -> Expr b c
    forall a b c. (a -> b) -> Expr a c -> Expr b c
    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) = ((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
    k f a
    src3, (a -> b) -> p a c -> p b c
    forall a b c. (a -> b) -> p a c -> p b c
    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 = (b -> c) -> Binding a b -> Binding a c
    forall a b. (a -> b) -> Binding a a -> Binding a b
    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) =
            Maybe b -> Expr b c -> Maybe b -> Maybe b -> RecordField b c
    forall s a.
    Maybe s -> Expr s a -> Maybe s -> Maybe s -> RecordField s a
    RecordField (a -> b
    k (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe a
    s0) ((a -> b) -> Expr a c -> Expr b c
    forall a b c. (a -> b) -> Expr a c -> Expr b c
    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 (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe a
    s1) (a -> b
    k (a -> b) -> Maybe a -> Maybe b
    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 = (b -> c) -> RecordField a b -> RecordField a c
    forall a b. (a -> b) -> RecordField a a -> RecordField a b
    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_) =
            Maybe b
    -> Text -> Maybe b -> Maybe b -> Expr b c -> FunctionBinding b c
    forall s a.
    Maybe s
    -> Text -> Maybe s -> Maybe s -> Expr s a -> FunctionBinding s a
    FunctionBinding (a -> b
    k (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe a
    src0) Text
    label (a -> b
    k (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe a
    src1) (a -> b
    k (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe a
    src2) ((a -> b) -> Expr a c -> Expr b c
    forall a b c. (a -> b) -> Expr a c -> Expr b c
    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 = (b -> c) -> FunctionBinding a b -> FunctionBinding a c
    forall a b. (a -> b) -> FunctionBinding a a -> FunctionBinding a b
    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   ) = b -> Expr b c -> Expr b c
    forall s a. s -> Expr s a -> Expr s a
    Note (a -> b
    k a
    a) ((a -> b) -> Expr a c -> Expr b c
    forall a b c. (a -> b) -> Expr a c -> Expr b c
    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    ) = c -> Expr b c
    forall s a. a -> Expr s a
    Embed c
    a
        first a -> b
    k (Let Binding a c
    a Expr a c
    b    ) = Binding b c -> Expr b c -> Expr b c
    forall s a. Binding s a -> Expr s a -> Expr s a
    Let ((a -> b) -> Binding a c -> Binding b c
    forall a b c. (a -> b) -> Binding a c -> Binding b c
    forall (p :: * -> * -> *) a b c.
    Bifunctor p =>
    (a -> b) -> p a c -> p b c
    first a -> b
    k Binding a c
    a) ((a -> b) -> Expr a c -> Expr b c
    forall a b c. (a -> b) -> Expr a c -> Expr b c
    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   ) = Map Text (RecordField b c) -> Expr b c
    forall s a. Map Text (RecordField s a) -> Expr s a
    Record (Map Text (RecordField b c) -> Expr b c)
    -> Map Text (RecordField b c) -> Expr b c
    forall a b. (a -> b) -> a -> b
    $ (a -> b) -> RecordField a c -> RecordField b c
    forall a b c. (a -> b) -> RecordField a c -> RecordField b c
    forall (p :: * -> * -> *) a b c.
    Bifunctor p =>
    (a -> b) -> p a c -> p b c
    first a -> b
    k (RecordField a c -> RecordField b c)
    -> Map Text (RecordField a c) -> Map Text (RecordField b c)
    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) = Map Text (RecordField b c) -> Expr b c
    forall s a. Map Text (RecordField s a) -> Expr s a
    RecordLit (Map Text (RecordField b c) -> Expr b c)
    -> Map Text (RecordField b c) -> Expr b c
    forall a b. (a -> b) -> a -> b
    $ (a -> b) -> RecordField a c -> RecordField b c
    forall a b c. (a -> b) -> RecordField a c -> RecordField b c
    forall (p :: * -> * -> *) a b c.
    Bifunctor p =>
    (a -> b) -> p a c -> p b c
    first a -> b
    k (RecordField a c -> RecordField b c)
    -> Map Text (RecordField a c) -> Map Text (RecordField b c)
    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 ) = Maybe CharacterSet -> FunctionBinding b c -> Expr b c -> Expr b c
    forall s a.
    Maybe CharacterSet -> FunctionBinding s a -> Expr s a -> Expr s a
    Lam Maybe CharacterSet
    cs ((a -> b) -> FunctionBinding a c -> FunctionBinding b c
    forall a b c.
    (a -> b) -> FunctionBinding a c -> FunctionBinding b c
    forall (p :: * -> * -> *) a b c.
    Bifunctor p =>
    (a -> b) -> p a c -> p b c
    first a -> b
    k FunctionBinding a c
    a) ((a -> b) -> Expr a c -> Expr b c
    forall a b c. (a -> b) -> Expr a c -> Expr b c
    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  ) = Expr b c -> FieldSelection b -> Expr b c
    forall s a. Expr s a -> FieldSelection s -> Expr s a
    Field ((a -> b) -> Expr a c -> Expr b c
    forall a b c. (a -> b) -> Expr a c -> Expr b c
    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 (a -> b) -> FieldSelection a -> FieldSelection b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> FieldSelection a
    b)
        first a -> b
    k  Expr a c
    expression  = ASetter (Expr a c) (Expr b c) (Expr a c) (Expr b c)
    -> (Expr a c -> Expr b c) -> Expr a c -> Expr b c
    forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
    Lens.over ASetter (Expr a c) (Expr b c) (Expr a c) (Expr b c)
    forall (f :: * -> *) s a t b.
    Applicative f =>
    (Expr s a -> f (Expr t b)) -> Expr s a -> f (Expr t b)
    unsafeSubExpressions ((a -> b) -> Expr a c -> Expr b c
    forall a b c. (a -> b) -> Expr a c -> Expr b c
    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 = (b -> c) -> Expr a b -> Expr a c
    forall a b. (a -> b) -> Expr a a -> Expr a b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap