{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE QuantifiedConstraints #-} {-# LANGUAGE ImpredicativeTypes #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE AllowAmbiguousTypes #-} module Conftrack.Value (Value(..), ConfigError(..), Key(..), ConfigValue(..), Origin(..)) where import Data.Text(Text) import Data.List.NonEmpty (NonEmpty) data Value = ConfigText Text | ConfigInteger Integer | ConfigOther Text Text deriving Show newtype Key = Key (NonEmpty Text) deriving newtype (Eq, Ord, Show) data ConfigError = ParseError | NotPresent deriving Show class ConfigValue a where fromConfig :: Value -> Either ConfigError a data Origin = Origin Key Text deriving Show instance ConfigValue Text where fromConfig (ConfigText a) = Right a fromConfig _ = Left ParseError instance ConfigValue Integer where fromConfig (ConfigInteger a) = Right a fromConfig _ = Left ParseError