Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
addTopDecls example for Template Haskell
{-# LANGUAGE TemplateHaskell #-}
module AddTopDecls where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
importDoubleToDouble :: String -> ExpQ
importDoubleToDouble fname = do
n <- newName fname
d <- forImpD CCall unsafe fname n [t|Double -> Double|]
addTopDecls [d]
[|$(varE n)|]
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import AddTopDecls
main :: IO ()
main = do
print ($(importDoubleToDouble "sin") pi)
print ($(importDoubleToDouble "cos") pi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.