summaryrefslogtreecommitdiffstats
path: root/tv/5pkgs/haskell/xmonad-tv/src/THEnv/JSON.hs
blob: 2a3a0e5239c47788376d88813eb364703a526c56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{-# LANGUAGE ScopedTypeVariables #-}

module THEnv.JSON where

import Data.Aeson (eitherDecode,FromJSON)
import Data.ByteString.Lazy.Char8 (pack)
import Language.Haskell.TH.Syntax (Exp,Lift(lift),Q)
import THEnv (getCompileEnv)
import Control.Monad

getCompileEnvJSON :: (FromJSON a) => String -> Q a
getCompileEnvJSON name =
    either error (id :: a -> a) . eitherDecode . pack <$>  getCompileEnv name

getCompileEnvJSONExp ::
  forall proxy a. (FromJSON a, Lift a) => proxy a -> String -> Q Exp
getCompileEnvJSONExp _ =
    (lift :: a -> Q Exp) <=< getCompileEnvJSON