{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DerivingVia                #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RankNTypes                 #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE StandaloneDeriving         #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE TypeOperators              #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}

module Composite.Dhall (TextTemplate (TextTemplate, unTextTemplate), runTextTemplate, F (F, unF), CoF (CoF, unCoF)) where

import           Composite.Record
import           Control.Applicative
import           Data.Functor.Contravariant
import           Data.Text                  (Text)
import           Data.Void
import qualified Dhall                      as D
import           Dhall.Core                 hiding (File, Text)
import           Dhall.Map
import           Dhall.Src
import           GHC.TypeLits

unsafeExpectRecordLit ::
  Text -> Expr Src Void -> Dhall.Map.Map Text (RecordField Src Void)
unsafeExpectRecordLit :: Text -> Expr Src Void -> Map Text (RecordField Src Void)
unsafeExpectRecordLit Text
_ (RecordLit Map Text (RecordField Src Void)
kvs) =
  Map Text (RecordField Src Void)
kvs
unsafeExpectRecordLit Text
name Expr Src Void
expression =
  Text -> forall b. b
Dhall.Core.internalError
    (Text
name forall a. Semigroup a => a -> a -> a
<> Text
": Unexpected constructor: " forall a. Semigroup a => a -> a -> a
<> forall a. Pretty a => a -> Text
Dhall.Core.pretty Expr Src Void
expression)

unsafeExpectRecord ::
  Text -> Expr Src Void -> Dhall.Map.Map Text (RecordField Src Void)
unsafeExpectRecord :: Text -> Expr Src Void -> Map Text (RecordField Src Void)
unsafeExpectRecord Text
_ (Record Map Text (RecordField Src Void)
kts) =
  Map Text (RecordField Src Void)
kts
unsafeExpectRecord Text
name Expr Src Void
expression =
  Text -> forall b. b
Dhall.Core.internalError
    (Text
name forall a. Semigroup a => a -> a -> a
<> Text
": Unexpected constructor: " forall a. Semigroup a => a -> a -> a
<> forall a. Pretty a => a -> Text
Dhall.Core.pretty Expr Src Void
expression)

instance D.ToDhall (Rec f '[]) where
  injectWith :: InputNormalizer -> Encoder (Rec f '[])
injectWith = forall (f :: * -> *) a. Applicative f => a -> f a
pure (D.Encoder {forall {s} {a}. Expr s a
forall {p} {s} {a}. p -> Expr s a
embed :: Rec f '[] -> Expr Src Void
declared :: Expr Src Void
declared :: forall {s} {a}. Expr s a
embed :: forall {p} {s} {a}. p -> Expr s a
..})
    where
      embed :: p -> Expr s a
embed p
_ = forall s a. Map Text (RecordField s a) -> Expr s a
RecordLit forall a. Monoid a => a
mempty
      declared :: Expr s a
declared = forall s a. Map Text (RecordField s a) -> Expr s a
Record forall a. Monoid a => a
mempty

instance D.FromDhall (Rec f '[]) where
  autoWith :: InputNormalizer -> Decoder (Rec f '[])
autoWith InputNormalizer
_ = D.Decoder {forall {s} {a}. Validation ExpectedTypeErrors (Expr s a)
forall {f :: * -> *} {p} {a :: * -> *}.
Applicative f =>
p -> f (Rec a '[])
extract :: Expr Src Void -> Extractor Src Void (Rec f '[])
expected :: Expector (Expr Src Void)
expected :: forall {s} {a}. Validation ExpectedTypeErrors (Expr s a)
extract :: forall {f :: * -> *} {p} {a :: * -> *}.
Applicative f =>
p -> f (Rec a '[])
..}
    where
      extract :: p -> f (Rec a '[])
extract p
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {u} (a :: u -> *). Rec a '[]
RNil
      expected :: Validation ExpectedTypeErrors (Expr s a)
expected = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall s a. Map Text (RecordField s a) -> Expr s a
Record (forall k v. Ord k => [(k, v)] -> Map k v
Dhall.Map.fromList [])

instance (KnownSymbol s, D.FromDhall (Record xs), D.FromDhall x) => D.FromDhall (Record (s :-> x ': xs)) where
  autoWith :: InputNormalizer -> Decoder (Record ((s :-> x) : xs))
autoWith = do
    let nL :: s :-> x
        nL :: s :-> x
nL = forall a. HasCallStack => a
undefined

    let nameL :: Text
nameL = forall (s :: Symbol) a. KnownSymbol s => (s :-> a) -> Text
valName s :-> x
nL

    D.Decoder Expr Src Void -> Extractor Src Void x
extractL Expector (Expr Src Void)
expectedL <- forall a. FromDhall a => InputNormalizer -> Decoder a
D.autoWith @x

    D.Decoder Expr Src Void -> Extractor Src Void (Record xs)
extractR Expector (Expr Src Void)
expectedR <- forall a. FromDhall a => InputNormalizer -> Decoder a
D.autoWith @(Record xs)

    let ktsR :: Validation ExpectedTypeErrors (Map Text (RecordField Src Void))
ktsR = Text -> Expr Src Void -> Map Text (RecordField Src Void)
unsafeExpectRecord Text
"Composite Record" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expector (Expr Src Void)
expectedR

    let expected :: Expector (Expr Src Void)
expected = forall s a. Map Text (RecordField s a) -> Expr s a
Record forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall k v. Ord k => k -> v -> Map k v -> Map k v
Dhall.Map.insert Text
nameL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. Expr s a -> RecordField s a
Dhall.Core.makeRecordField forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expector (Expr Src Void)
expectedL forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Validation ExpectedTypeErrors (Map Text (RecordField Src Void))
ktsR)
    let extract :: Expr Src Void
-> Validation (ExtractErrors Src Void) (Record ((s :-> x) : xs))
extract Expr Src Void
expression = do
          let die :: Validation (ExtractErrors Src Void) (Record ((s :-> x) : xs))
die = forall s a b. Expector (Expr s a) -> Expr s a -> Extractor s a b
D.typeError Expector (Expr Src Void)
expected Expr Src Void
expression

          case Expr Src Void
expression of
            RecordLit Map Text (RecordField Src Void)
kvs ->
              case forall s a. RecordField s a -> Expr s a
Dhall.Core.recordFieldValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k v. Ord k => k -> Map k v -> Maybe v
Dhall.Map.lookup Text
nameL Map Text (RecordField Src Void)
kvs of
                Just Expr Src Void
expressionL ->
                  forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
                    forall a (rs :: [*]) (s :: Symbol).
a -> Rec Identity rs -> Rec Identity ((s :-> a) : rs)
(:*:)
                    (Expr Src Void -> Extractor Src Void x
extractL Expr Src Void
expressionL)
                    (Expr Src Void -> Extractor Src Void (Record xs)
extractR Expr Src Void
expression)
                Maybe (Expr Src Void)
_ -> Validation (ExtractErrors Src Void) (Record ((s :-> x) : xs))
die
            Expr Src Void
_ -> Validation (ExtractErrors Src Void) (Record ((s :-> x) : xs))
die
    forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a.
(Expr Src Void -> Extractor Src Void a)
-> Expector (Expr Src Void) -> Decoder a
D.Decoder Expr Src Void
-> Validation (ExtractErrors Src Void) (Record ((s :-> x) : xs))
extract Expector (Expr Src Void)
expected)

instance (KnownSymbol s, D.ToDhall (Record xs), D.ToDhall x) => D.ToDhall (Record (s :-> x ': xs)) where
  injectWith :: InputNormalizer -> Encoder (Record ((s :-> x) : xs))
injectWith = do
    let f :: s :-> x
        f :: s :-> x
f = forall a. HasCallStack => a
undefined
    let name :: Text
name = forall (s :: Symbol) a. KnownSymbol s => (s :-> a) -> Text
valName s :-> x
f
    let D.Encoder x -> Expr Src Void
embedL Expr Src Void
declaredL = forall a. ToDhall a => Encoder a
D.inject
    let D.Encoder Record xs -> Expr Src Void
embedR Expr Src Void
declaredR = forall a. ToDhall a => Encoder a
D.inject
    let embed :: Record ((s :-> x) : xs) -> Expr Src Void
embed (x
s :*: Record xs
xs) = forall s a. Map Text (RecordField s a) -> Expr s a
RecordLit (forall k v. Ord k => k -> v -> Map k v -> Map k v
Dhall.Map.insert Text
name (forall s a. Expr s a -> RecordField s a
Dhall.Core.makeRecordField (x -> Expr Src Void
embedL x
s)) Map Text (RecordField Src Void)
mapR)
          where
            mapR :: Map Text (RecordField Src Void)
mapR = Text -> Expr Src Void -> Map Text (RecordField Src Void)
unsafeExpectRecordLit Text
"Composite Record" forall a b. (a -> b) -> a -> b
$ Record xs -> Expr Src Void
embedR Record xs
xs
    let declared :: Expr Src Void
declared = forall s a. Map Text (RecordField s a) -> Expr s a
Record (forall k v. Ord k => k -> v -> Map k v -> Map k v
Dhall.Map.insert Text
name (forall s a. Expr s a -> RecordField s a
Dhall.Core.makeRecordField Expr Src Void
declaredL) Map Text (RecordField Src Void)
mapR)
          where
            mapR :: Map Text (RecordField Src Void)
mapR = Text -> Expr Src Void -> Map Text (RecordField Src Void)
unsafeExpectRecord Text
"Composite Record" Expr Src Void
declaredR
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ D.Encoder {Expr Src Void
Record ((s :-> x) : xs) -> Expr Src Void
declared :: Expr Src Void
embed :: Record ((s :-> x) : xs) -> Expr Src Void
embed :: Record ((s :-> x) : xs) -> Expr Src Void
declared :: Expr Src Void
..}

-- | Newtype wrapper for deriving `(Rec f xs)` where f is a `Functor` using DerivingVia.
--
-- @since 0.0.4.0
newtype F f xs = F {forall (f :: * -> *) (xs :: [*]). F f xs -> Rec f xs
unF :: Rec f xs}

-- | Newtype wrapper for deriving `(Rec f xs)` where f is `Contravariant` using DerivingVia.
--
-- @since 0.0.4.0
newtype CoF f xs = CoF {forall (f :: * -> *) (xs :: [*]). CoF f xs -> Rec f xs
unCoF :: Rec f xs}

deriving newtype instance D.FromDhall (F f '[])

deriving newtype instance D.FromDhall (CoF f '[])

instance (KnownSymbol s, Functor f, D.ToDhall (F f xs), D.ToDhall (f x)) => D.ToDhall (F f (s :-> x ': xs)) where
  injectWith :: InputNormalizer -> Encoder (F f ((s :-> x) : xs))
injectWith = do
    let f :: s :-> x
        f :: s :-> x
f = forall a. HasCallStack => a
undefined
    let name :: Text
name = forall (s :: Symbol) a. KnownSymbol s => (s :-> a) -> Text
valName s :-> x
f
    let D.Encoder f x -> Expr Src Void
embedL Expr Src Void
declaredL = forall a. ToDhall a => Encoder a
D.inject @(f x)
    let D.Encoder F f xs -> Expr Src Void
embedR Expr Src Void
declaredR = forall a. ToDhall a => Encoder a
D.inject @(F f xs)
    let embed :: F f ((s :-> x) : xs) -> Expr Src Void
embed (F (f x
s :^: Rec f xs
xs)) = forall s a. Map Text (RecordField s a) -> Expr s a
RecordLit (forall k v. Ord k => k -> v -> Map k v -> Map k v
Dhall.Map.insert Text
name (forall s a. Expr s a -> RecordField s a
Dhall.Core.makeRecordField (f x -> Expr Src Void
embedL f x
s)) Map Text (RecordField Src Void)
mapR)
          where
            mapR :: Map Text (RecordField Src Void)
mapR = Text -> Expr Src Void -> Map Text (RecordField Src Void)
unsafeExpectRecordLit Text
"Composite Rec f (Functor)" forall a b. (a -> b) -> a -> b
$ F f xs -> Expr Src Void
embedR (forall (f :: * -> *) (xs :: [*]). Rec f xs -> F f xs
F Rec f xs
xs)
    let declared :: Expr Src Void
declared = forall s a. Map Text (RecordField s a) -> Expr s a
Record (forall k v. Ord k => k -> v -> Map k v -> Map k v
Dhall.Map.insert Text
name (forall s a. Expr s a -> RecordField s a
Dhall.Core.makeRecordField Expr Src Void
declaredL) Map Text (RecordField Src Void)
mapR)
          where
            mapR :: Map Text (RecordField Src Void)
mapR = Text -> Expr Src Void -> Map Text (RecordField Src Void)
unsafeExpectRecord Text
"Composite Rec f (Functor)" Expr Src Void
declaredR
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ D.Encoder {Expr Src Void
F f ((s :-> x) : xs) -> Expr Src Void
declared :: Expr Src Void
embed :: F f ((s :-> x) : xs) -> Expr Src Void
embed :: F f ((s :-> x) : xs) -> Expr Src Void
declared :: Expr Src Void
..}

instance (KnownSymbol s, Functor f, D.FromDhall (F f xs), D.FromDhall (f x)) => D.FromDhall (F f (s :-> x ': xs)) where
  autoWith :: InputNormalizer -> Decoder (F f ((s :-> x) : xs))
autoWith InputNormalizer
opts =
    let nL :: s :-> x
        nL :: s :-> x
nL = forall a. HasCallStack => a
undefined

        nameL :: Text
nameL = forall (s :: Symbol) a. KnownSymbol s => (s :-> a) -> Text
valName s :-> x
nL

        D.Decoder Expr Src Void -> Extractor Src Void (f x)
extractL Expector (Expr Src Void)
expectedL = forall a. FromDhall a => InputNormalizer -> Decoder a
D.autoWith @(f x) InputNormalizer
opts

        D.Decoder Expr Src Void -> Extractor Src Void (Rec f xs)
extractR Expector (Expr Src Void)
expectedR = forall (f :: * -> *) (xs :: [*]). F f xs -> Rec f xs
unF forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromDhall a => InputNormalizer -> Decoder a
D.autoWith @(F f xs) InputNormalizer
opts

        ktsR :: Validation ExpectedTypeErrors (Map Text (RecordField Src Void))
ktsR = Text -> Expr Src Void -> Map Text (RecordField Src Void)
unsafeExpectRecord Text
"Composite Rec f (Functor)" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expector (Expr Src Void)
expectedR

        expected :: Expector (Expr Src Void)
expected = forall s a. Map Text (RecordField s a) -> Expr s a
Record forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall k v. Ord k => k -> v -> Map k v -> Map k v
Dhall.Map.insert Text
nameL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. Expr s a -> RecordField s a
Dhall.Core.makeRecordField forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expector (Expr Src Void)
expectedL forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Validation ExpectedTypeErrors (Map Text (RecordField Src Void))
ktsR)
        extract :: Expr Src Void
-> Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
extract Expr Src Void
expression = do
          let die :: Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
die = forall s a b. Expector (Expr s a) -> Expr s a -> Extractor s a b
D.typeError Expector (Expr Src Void)
expected Expr Src Void
expression

          case Expr Src Void
expression of
            RecordLit Map Text (RecordField Src Void)
kvs ->
              case forall s a. RecordField s a -> Expr s a
Dhall.Core.recordFieldValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k v. Ord k => k -> Map k v -> Maybe v
Dhall.Map.lookup Text
nameL Map Text (RecordField Src Void)
kvs of
                Just Expr Src Void
expressionL ->
                  forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
                    forall (f :: * -> *) a (rs :: [*]) (s :: Symbol).
Functor f =>
f a -> Rec f rs -> Rec f ((s :-> a) : rs)
(:^:)
                    (Expr Src Void -> Extractor Src Void (f x)
extractL Expr Src Void
expressionL)
                    (Expr Src Void -> Extractor Src Void (Rec f xs)
extractR Expr Src Void
expression)
                Maybe (Expr Src Void)
_ -> Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
die
            Expr Src Void
_ -> Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
die
     in forall (f :: * -> *) (xs :: [*]). Rec f xs -> F f xs
F forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a.
(Expr Src Void -> Extractor Src Void a)
-> Expector (Expr Src Void) -> Decoder a
D.Decoder Expr Src Void
-> Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
extract Expector (Expr Src Void)
expected

instance (KnownSymbol s, D.FromDhall (CoF f xs), Contravariant f, D.FromDhall (f x)) => D.FromDhall (CoF f (s :-> x ': xs)) where
  autoWith :: InputNormalizer -> Decoder (CoF f ((s :-> x) : xs))
autoWith InputNormalizer
opts =
    let nL :: s :-> x
        nL :: s :-> x
nL = forall a. HasCallStack => a
undefined

        nameL :: Text
nameL = forall (s :: Symbol) a. KnownSymbol s => (s :-> a) -> Text
valName s :-> x
nL

        D.Decoder Expr Src Void -> Extractor Src Void (f x)
extractL Expector (Expr Src Void)
expectedL = forall a. FromDhall a => InputNormalizer -> Decoder a
D.autoWith @(f x) InputNormalizer
opts

        D.Decoder Expr Src Void -> Extractor Src Void (Rec f xs)
extractR Expector (Expr Src Void)
expectedR = forall (f :: * -> *) (xs :: [*]). CoF f xs -> Rec f xs
unCoF forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromDhall a => InputNormalizer -> Decoder a
D.autoWith @(CoF f xs) InputNormalizer
opts

        ktsR :: Validation ExpectedTypeErrors (Map Text (RecordField Src Void))
ktsR = Text -> Expr Src Void -> Map Text (RecordField Src Void)
unsafeExpectRecord Text
"Composite Rec f (Contravariant)" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expector (Expr Src Void)
expectedR

        expected :: Expector (Expr Src Void)
expected = forall s a. Map Text (RecordField s a) -> Expr s a
Record forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall k v. Ord k => k -> v -> Map k v -> Map k v
Dhall.Map.insert Text
nameL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. Expr s a -> RecordField s a
Dhall.Core.makeRecordField forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expector (Expr Src Void)
expectedL forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Validation ExpectedTypeErrors (Map Text (RecordField Src Void))
ktsR)
        extract :: Expr Src Void
-> Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
extract Expr Src Void
expression = do
          let die :: Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
die = forall s a b. Expector (Expr s a) -> Expr s a -> Extractor s a b
D.typeError Expector (Expr Src Void)
expected Expr Src Void
expression

          case Expr Src Void
expression of
            RecordLit Map Text (RecordField Src Void)
kvs ->
              case forall s a. RecordField s a -> Expr s a
Dhall.Core.recordFieldValue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k v. Ord k => k -> Map k v -> Maybe v
Dhall.Map.lookup Text
nameL Map Text (RecordField Src Void)
kvs of
                Just Expr Src Void
expressionL ->
                  forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
                    forall {u} (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
(:&)
                    (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap forall (s :: Symbol) a. (s :-> a) -> a
getVal forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr Src Void -> Extractor Src Void (f x)
extractL Expr Src Void
expressionL)
                    (Expr Src Void -> Extractor Src Void (Rec f xs)
extractR Expr Src Void
expression)
                Maybe (Expr Src Void)
_ -> Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
die
            Expr Src Void
_ -> Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
die
     in forall (f :: * -> *) (xs :: [*]). Rec f xs -> CoF f xs
CoF forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a.
(Expr Src Void -> Extractor Src Void a)
-> Expector (Expr Src Void) -> Decoder a
D.Decoder Expr Src Void
-> Validation (ExtractErrors Src Void) (Rec f ((s :-> x) : xs))
extract Expector (Expr Src Void)
expected

deriving via (F Maybe (s :-> x ': xs)) instance (KnownSymbol s, D.ToDhall (F Maybe xs), D.ToDhall x) => D.ToDhall (Rec Maybe (s :-> x ': xs))

deriving via (F [] (s :-> x ': xs)) instance (KnownSymbol s, D.ToDhall (F [] xs), D.ToDhall x) => D.ToDhall (Rec [] (s :-> x ': xs))

deriving via (F Maybe (s :-> x ': xs)) instance (KnownSymbol s, D.FromDhall (F Maybe xs), D.FromDhall x) => D.FromDhall (Rec Maybe (s :-> x ': xs))

deriving via (F [] (s :-> x ': xs)) instance (KnownSymbol s, D.FromDhall (F [] xs), D.FromDhall x) => D.FromDhall (Rec [] (s :-> x ': xs))

deriving via (CoF Predicate (s :-> x ': xs)) instance (KnownSymbol s, D.FromDhall (CoF Predicate xs), D.ToDhall x) => D.FromDhall (Rec Predicate (s :-> x ': xs))

deriving via (CoF Equivalence (s :-> x ': xs)) instance (KnownSymbol s, D.FromDhall (CoF Equivalence xs), D.ToDhall x) => D.FromDhall (Rec Equivalence (s :-> x ': xs))

deriving via (CoF (Op b) (s :-> x ': xs)) instance (KnownSymbol s, D.FromDhall (CoF (Op b) xs), D.FromDhall b, D.ToDhall x) => D.FromDhall (Rec (Op b) (s :-> x ': xs))

-- | The common case where a function from `a -> Text` can be used
-- in a record.
--
-- @since 0.0.3.0
newtype TextTemplate a = TextTemplate {forall a. TextTemplate a -> Op Text a
unTextTemplate :: Op Text a}
  deriving newtype (InputNormalizer -> Decoder (TextTemplate a)
forall a. ToDhall a => InputNormalizer -> Decoder (TextTemplate a)
forall a. (InputNormalizer -> Decoder a) -> FromDhall a
autoWith :: InputNormalizer -> Decoder (TextTemplate a)
$cautoWith :: forall a. ToDhall a => InputNormalizer -> Decoder (TextTemplate a)
D.FromDhall)

deriving newtype instance Contravariant TextTemplate

-- | Run a `TextTemplate` against a value.
--
-- @since 0.0.3.0
runTextTemplate :: TextTemplate a -> a -> Text
runTextTemplate :: forall a. TextTemplate a -> a -> Text
runTextTemplate (TextTemplate (Op a -> Text
f)) = a -> Text
f