summaryrefslogtreecommitdiffstats
path: root/tv/5pkgs/haskell/th-env/src/THEnv.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2023-09-12 12:56:39 +0200
committertv <tv@krebsco.de>2023-09-13 16:23:38 +0200
commitfbd485cd86c7e9984819357398f912a2d5510845 (patch)
treee1a9e2eedacfa25018d6b0eef3f4628a4d503ebc /tv/5pkgs/haskell/th-env/src/THEnv.hs
parent5370e0485788224126861e076110ac705013d2de (diff)
tv: emigrate
Diffstat (limited to 'tv/5pkgs/haskell/th-env/src/THEnv.hs')
-rw-r--r--tv/5pkgs/haskell/th-env/src/THEnv.hs49
1 files changed, 0 insertions, 49 deletions
diff --git a/tv/5pkgs/haskell/th-env/src/THEnv.hs b/tv/5pkgs/haskell/th-env/src/THEnv.hs
deleted file mode 100644
index b04f2ce0b..000000000
--- a/tv/5pkgs/haskell/th-env/src/THEnv.hs
+++ /dev/null
@@ -1,49 +0,0 @@
-{-# LANGUAGE TemplateHaskell #-}
-module THEnv
- (
- -- * Compile-time configuration
- lookupCompileEnv
- , lookupCompileEnvExp
- , getCompileEnv
- , getCompileEnvExp
- , fileAsString
- ) where
-
-import Control.Monad
-import qualified Data.Text as T
-import qualified Data.Text.IO as T
-import Language.Haskell.TH
-import Language.Haskell.TH.Syntax (Lift(..))
-import System.Environment (getEnvironment)
-
--- Functions that work with compile-time configuration
-
--- | Looks up a compile-time environment variable.
-lookupCompileEnv :: String -> Q (Maybe String)
-lookupCompileEnv key = lookup key `liftM` runIO getEnvironment
-
--- | Looks up a compile-time environment variable. The result is a TH
--- expression of type @Maybe String@.
-lookupCompileEnvExp :: String -> Q Exp
-lookupCompileEnvExp = (`sigE` [t| Maybe String |]) . lift <=< lookupCompileEnv
- -- We need to explicly type the result so that things like `print Nothing`
- -- work.
-
--- | Looks up an compile-time environment variable and fail, if it's not
--- present.
-getCompileEnv :: String -> Q String
-getCompileEnv key =
- lookupCompileEnv key >>=
- maybe (fail $ "Environment variable " ++ key ++ " not defined") return
-
--- | Looks up an compile-time environment variable and fail, if it's not
--- present. The result is a TH expression of type @String@.
-getCompileEnvExp :: String -> Q Exp
-getCompileEnvExp = lift <=< getCompileEnv
-
--- | Loads the content of a file as a string constant expression.
--- The given path is relative to the source directory.
-fileAsString :: FilePath -> Q Exp
-fileAsString = do
- -- addDependentFile path -- works only with template-haskell >= 2.7
- stringE . T.unpack . T.strip <=< runIO . T.readFile