From d1446a8435a3cf06371eb6d4ebe25d6491612f4d Mon Sep 17 00:00:00 2001 From: stuebinm Date: Wed, 22 May 2024 00:04:30 +0200 Subject: a generic, multi-source config interface --- src/Conftrack/Value.hs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Conftrack/Value.hs (limited to 'src/Conftrack/Value.hs') diff --git a/src/Conftrack/Value.hs b/src/Conftrack/Value.hs new file mode 100644 index 0000000..c5768cc --- /dev/null +++ b/src/Conftrack/Value.hs @@ -0,0 +1,38 @@ +{-# 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 -- cgit v1.2.3