-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Runtime interpolation of environment variables in records using profunctors -- -- Runtime interpolation of environment variables in records using -- profunctors. See the README. @package interpolator @version 1.1.0 module Data.Interpolation -- | Newtype wrapper for an environment variable key. newtype TemplateKey TemplateKey :: Text -> TemplateKey [unTemplateKey] :: TemplateKey -> Text -- | Newtype wrapper for an environment variable value. newtype TemplateValue TemplateValue :: Text -> TemplateValue [unTemplateValue] :: TemplateValue -> Text -- | Type for a value that is described by -- '_env:ENVIRONMENT_VARIABLE:default' in JSON. data Template a Template :: TemplateKey -> Maybe a -> Template a [_templateKey] :: Template a -> TemplateKey [_templateDefault] :: Template a -> Maybe a -- | Type for a value that can be described either with '_env...' or as -- just a literal value in JSON. data Uninterpolated a Templated :: Template a -> Uninterpolated a Literal :: a -> Uninterpolated a data InterpolationFailure InterpolationFailureKeyNotFound :: TemplateKey -> InterpolationFailure InterpolationFailureValueNotReadable :: TemplateKey -> TemplateValue -> InterpolationFailure newtype InterpolationContext InterpolationContext :: Map TemplateKey TemplateValue -> InterpolationContext [unInterpolationContext] :: InterpolationContext -> Map TemplateKey TemplateValue -- | A class for parsing environment variable values, which should only be -- defined on primitives. Similar to Read except that for -- text-type values it should parse using identity. class FromTemplateValue a parseTemplateValue :: FromTemplateValue a => TemplateValue -> Maybe a -- | A class for showing environment variable values, which should only be -- defined on primitives. Similar to Show except that for -- text-type values it should use identity. class ToTemplateValue a toTemplateValue :: ToTemplateValue a => a -> TemplateValue newtype Interpolator templates identities Interpolator :: (templates -> Reader InterpolationContext (Validation [InterpolationFailure] identities)) -> Interpolator templates identities [runInterpolator] :: Interpolator templates identities -> templates -> Reader InterpolationContext (Validation [InterpolationFailure] identities) -- | Run a template using the interpolation context and failing if the -- value is not found or not readable. runTemplate :: FromTemplateValue a => Interpolator (Uninterpolated a) a mkInterpolationContext :: MonadIO m => m InterpolationContext interpolateWithContext :: (Default Interpolator templates identities, MonadIO m) => templates -> m (Either [InterpolationFailure] identities) interpolateWithContextExplicit :: MonadIO m => Interpolator templates identities -> templates -> m (Either [InterpolationFailure] identities) instance GHC.Classes.Ord Data.Interpolation.InterpolationFailure instance GHC.Classes.Eq Data.Interpolation.InterpolationFailure instance GHC.Show.Show a => GHC.Show.Show (Data.Interpolation.Uninterpolated a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Interpolation.Uninterpolated a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Interpolation.Uninterpolated a) instance GHC.Show.Show a => GHC.Show.Show (Data.Interpolation.Template a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Interpolation.Template a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Interpolation.Template a) instance Data.Aeson.Types.FromJSON.FromJSON Data.Interpolation.TemplateValue instance Data.Aeson.Types.ToJSON.ToJSON Data.Interpolation.TemplateValue instance GHC.Show.Show Data.Interpolation.TemplateValue instance GHC.Classes.Ord Data.Interpolation.TemplateValue instance GHC.Classes.Eq Data.Interpolation.TemplateValue instance Data.Aeson.Types.FromJSON.FromJSON Data.Interpolation.TemplateKey instance Data.Aeson.Types.ToJSON.ToJSON Data.Interpolation.TemplateKey instance GHC.Show.Show Data.Interpolation.TemplateKey instance GHC.Classes.Ord Data.Interpolation.TemplateKey instance GHC.Classes.Eq Data.Interpolation.TemplateKey instance GHC.Base.Functor (Data.Interpolation.Interpolator templates) instance GHC.Base.Applicative (Data.Interpolation.Interpolator templates) instance Data.Profunctor.Unsafe.Profunctor Data.Interpolation.Interpolator instance Data.Profunctor.Product.Class.ProductProfunctor Data.Interpolation.Interpolator instance Data.Profunctor.Product.Class.SumProfunctor Data.Interpolation.Interpolator instance Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator a a instance Data.Interpolation.FromTemplateValue a => Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator (Data.Interpolation.Uninterpolated a) a instance Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator a b => Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator (Data.Map.Internal.Map k a) (Data.Map.Internal.Map k b) instance (Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator a b, GHC.Classes.Ord a, GHC.Classes.Ord b) => Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator (Data.Set.Internal.Set a) (Data.Set.Internal.Set b) instance Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator a b => Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator [a] [b] instance Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator a b => Data.Profunctor.Product.Default.Class.Default Data.Interpolation.Interpolator (GHC.Maybe.Maybe a) (GHC.Maybe.Maybe b) instance Data.Interpolation.ToTemplateValue Data.Text.Internal.Text instance Data.Interpolation.ToTemplateValue GHC.Base.String instance Data.Interpolation.ToTemplateValue GHC.Types.Int instance Data.Interpolation.ToTemplateValue GHC.Types.Bool instance Data.Interpolation.ToTemplateValue a => Data.Aeson.Types.ToJSON.ToJSON (Data.Interpolation.Template a) instance (Data.Interpolation.ToTemplateValue a, Data.Aeson.Types.ToJSON.ToJSON a) => Data.Aeson.Types.ToJSON.ToJSON (Data.Interpolation.Uninterpolated a) instance Data.Interpolation.FromTemplateValue Data.Text.Internal.Text instance Data.Interpolation.FromTemplateValue GHC.Base.String instance Data.Interpolation.FromTemplateValue GHC.Types.Int instance Data.Interpolation.FromTemplateValue GHC.Types.Bool instance Data.Interpolation.FromTemplateValue a => Data.Aeson.Types.FromJSON.FromJSON (Data.Interpolation.Template a) instance (Data.Interpolation.FromTemplateValue a, Data.Aeson.Types.FromJSON.FromJSON a) => Data.Aeson.Types.FromJSON.FromJSON (Data.Interpolation.Uninterpolated a) instance GHC.Show.Show Data.Interpolation.InterpolationFailure instance Test.QuickCheck.Arbitrary.Arbitrary1 Data.Interpolation.Uninterpolated instance Test.QuickCheck.Arbitrary.Arbitrary a => Test.QuickCheck.Arbitrary.Arbitrary (Data.Interpolation.Uninterpolated a) instance Test.QuickCheck.Arbitrary.Arbitrary (Data.Interpolation.Uninterpolated Data.Text.Internal.Text) instance Test.QuickCheck.Arbitrary.Arbitrary Data.Interpolation.TemplateKey module Data.Interpolation.TH -- | Make an instance of Default for Interpolator of an ADT. -- Can't do it for an arbitrary Profunctor p because of partial -- functions. This splice is meant to be used in conjunction with -- makeAdaptorAndInstance for records as a way to project -- Default instances down to all leaves. -- --
-- data Foo' a b = Foo1 a | Foo2 b -- makeInterpolatorSumInstance 'Foo ---- --
-- instance (Default Interpolator a1 b1, Default Interpolator a2 b2) => Default Interpolator (Foo' a1 a2) (Foo' b1 b2) where -- def = Interpolator $ case -- Foo1 x -> Foo1 $ runInterpolator def x -- Foo2 x -> Foo2 $ runInterpolator def x --makeInterpolatorSumInstance :: Name -> Q [Dec] -- | When applied to a simple data type declaration, substitute a -- fully-polymorphic data type (suffixed with a "prime"), and type -- aliases for "normal" and "uninterpolated" variants. -- -- For example, a record or newtype (using record syntax): -- --
-- withUninterpolated [d|
-- data Foo = Foo
-- { fooBar :: String
-- , fooBaz :: Maybe Int
-- } deriving (Eq, Show)
-- |]
--
--
-- Is equivalent to:
--
--
-- data Foo' bar baz = Foo
-- { fooBar :: bar
-- , fooBaz :: baz
-- } deriving (Eq, Show)
-- type Foo = Foo' String (Maybe Int)
-- type UninterpolatedFoo = Foo' (Uninterpolated String) (Maybe (Uninterpolated Int))
--
--
-- Note: the trailing |] of the quasi quote bracket has
-- to be indented or a parse error will occur.
--
-- A simple sum type whose constructors have one argument or less:
--
-- -- withUninterpolated [d| -- data MaybeFoo -- = AFoo Foo -- | NoFoo -- deriving (Eq, Show) ---- -- Expands to: -- --
-- data MaybeFoo' aFoo -- = AFoo aFoo -- | NoFoo -- deriving (Eq, Show) -- type MaybeFoo = MaybeFoo' Foo -- type UninterpolatedMaybeFoo = MaybeFoo' (Foo' (Uninterpolated String) (Maybe (Uninterpolated Int))) -- -- Note: UninterpolatedMaybeFoo ~ MaybeFoo' UninterpolatedFoo ---- -- Whenever the type of a field is one for which an instance of -- FromTemplateValue is present, the type is wrapped in -- Uninterpolated. Otherwise, an attempt is made to push -- Uninterpolated down into the field's type, even if it's a -- type synonym such as one generated by this same macro. -- -- Note: this splice is equivalent to withPolymorphic [d|data Foo ... -- |] followed by deriveUninterpolated ''Foo. withUninterpolated :: Q [Dec] -> Q [Dec] -- | When applied to a simple data type declaration, substitute a -- fully-polymorphic data type (suffixed with a "prime"), and a simple -- type alias which matches the supplied declaration. -- -- This splice does not include the corresponding Uninterpolated -- type, so it can be used separately when needed. For example, if you -- want to define all your record types first, then define/derive the -- Uninterpolated types for each. This can be important because the -- presence of a FromTemplateValue instance, defined before the -- splice, will affect the shape of the derived Uninterpolated type. -- -- For example, a record or newtype (using record syntax): -- --
-- withPolymorphic [d|
-- data Foo = Foo
-- { fooBar :: String
-- , fooBaz :: Maybe Int
-- } deriving (Eq, Show)
-- |]
--
--
-- Is equivalent to:
--
--
-- data Foo' bar baz = Foo
-- { fooBar :: bar
-- , fooBaz :: baz
-- } deriving (Eq, Show)
-- type Foo = Foo' String (Maybe Int)
--
--
-- Note: the trailing |] of the quasi quote bracket has
-- to be indented or a parse error will occur.
withPolymorphic :: Q [Dec] -> Q [Dec]
-- | Given the name of a type alias which specializes a polymorphic type
-- (such as the "simple" type generated by withPolymorphic),
-- generate the corresponding Uninterpolated type alias which
-- replaces each simple type with an Uninterpolated form, taking
-- account for which types have FromTemplateValue instances.
--
-- Use this instead of withUninterpolated when you need to define
-- instances for referenced types, and you need flexibility in the
-- ordering of declarations in your module's source.
deriveUninterpolated :: Name -> Q [Dec]