Skip to content

Instantly share code, notes, and snippets.

@tydeu
Created August 17, 2019 19:32
Show Gist options
  • Save tydeu/9ecdf536ba397cd85215ca811525ca7c to your computer and use it in GitHub Desktop.
Save tydeu/9ecdf536ba397cd85215ca811525ca7c to your computer and use it in GitHub Desktop.
Rebindable Templates
import SpliceI
import SpliceS
main :: IO ()
main = testI >> testS
{-# LANGUAGE
TemplateHaskell
#-}
module Quote where
import Language.Haskell.TH
num :: Integer
num = 8
magic :: Integer -> Q Exp
magic n = [| n |]
fromInteger :: Integer -> String
fromInteger = show
{-# LANGUAGE
TemplateHaskell, RebindableSyntax
#-}
module SpliceI where
import Prelude
import Quote hiding (fromInteger)
testI :: IO ()
testI = putStrLn $ show $(magic num)
{-# LANGUAGE
TemplateHaskell, RebindableSyntax
#-}
module SpliceS where
import Prelude hiding (fromInteger)
import Quote
testS :: IO ()
testS = putStrLn $ show $(magic num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment