Created
February 12, 2015 02:49
-
-
Save mainland/f18cf3827c4b0b64b835 to your computer and use it in GitHub Desktop.
addTopDecls example for Template Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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)|] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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