Skip to content

Instantly share code, notes, and snippets.

@jfischoff
Created May 25, 2018 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfischoff/7ee09a7c30e61d6b93cac1baa7f833cf to your computer and use it in GitHub Desktop.
Save jfischoff/7ee09a7c30e61d6b93cac1baa7f833cf to your computer and use it in GitHub Desktop.
{-# LANGUAGE RecordWildCards #-}
module TH where
import Language.Haskell.TH
import System.FilePath
import Control.Monad ((<=<))
import System.Directory (getCurrentDirectory, canonicalizePath)
fileRelativeToAbsolute :: String -> Q Exp
fileRelativeToAbsolute = stringE <=< fileRelativeToAbsoluteStr
fileRelativeToAbsoluteStr :: String -> Q String
fileRelativeToAbsoluteStr relativeFilePath = do
Loc {..} <- location
currentDir <- runIO getCurrentDirectory
let baseDir = takeDirectory loc_filename
runIO $ canonicalizePath $ currentDir </> baseDir </> relativeFilePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment