{-# LANGUAGE UndecidableInstances #-} module Cfg.Deriving.ConfigValue where import GHC.Generics import Cfg.Parser.ValueParser import Cfg.Parser import Data.Coerce newtype ConfigValue a = ConfigValue {forall a. ConfigValue a -> a unConfigValue :: a} instance Generic a => Generic (ConfigValue a) where type Rep (ConfigValue a) = Rep a to :: forall x. Rep (ConfigValue a) x -> ConfigValue a to = a -> ConfigValue a forall a. a -> ConfigValue a ConfigValue (a -> ConfigValue a) -> (Rep a x -> a) -> Rep a x -> ConfigValue a forall b c a. (b -> c) -> (a -> b) -> a -> c . Rep a x -> a forall a x. Generic a => Rep a x -> a forall x. Rep a x -> a to from :: forall x. ConfigValue a -> Rep (ConfigValue a) x from (ConfigValue a x) = a -> Rep a x forall x. a -> Rep a x forall a x. Generic a => a -> Rep a x from a x instance (Generic a, GValueParser (Rep a)) => ValueParser (ConfigValue a) where parser :: Parser (ConfigValue a) parser = Parser a -> Parser (ConfigValue a) forall a b. Coercible a b => a -> b coerce (Parser a -> Parser (ConfigValue a)) -> (Parser a -> Parser (ConfigValue a)) -> Parser a -> Parser (ConfigValue a) forall a. a -> a -> a `asTypeOf` (a -> ConfigValue a) -> Parser a -> Parser (ConfigValue a) forall a b. (a -> b) -> ParsecT Void Text Identity a -> ParsecT Void Text Identity b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> ConfigValue a forall a. a -> ConfigValue a ConfigValue (Parser a -> Parser (ConfigValue a)) -> Parser a -> Parser (ConfigValue a) forall a b. (a -> b) -> a -> b $ forall a. (Generic a, GValueParser (Rep a)) => Parser a defaultValueParser @a instance (Generic a, GValueParser (Rep a)) => NestedParser (ConfigValue a)