Skip to content

Instantly share code, notes, and snippets.

@Saul-Mirone
Created July 27, 2018 01:38
Show Gist options
  • Save Saul-Mirone/a2ac7e3fa05b338152752d0e625c6f75 to your computer and use it in GitHub Desktop.
Save Saul-Mirone/a2ac7e3fa05b338152752d0e625c6f75 to your computer and use it in GitHub Desktop.
A mini file-embed using Template Haskell
{-# LANGUAGE TemplateHaskell #-}
module TH
( embedFile )
where
import Data.String (IsString (..))
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
embedFile :: FilePath -> Q Exp
embedFile path = do
str <- runIO (readFile path)
addDependentFile path
[| fromString str |]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment