- You need two files,
th.hs
andThlib.hs
. Put them in the same directory. - Put this in
th.hs
:{-# LANGUAGE TemplateHaskell #-}
import Thlib
main :: IO [Char]
main = return $(hello)
- Put this in
Thlib.hs
:{-# LANGUAGE TemplateHaskell #-}
module Thlib where
import Language.Haskell.TH
hello :: Q Exp
hello = [|"hello world"|] - Go to your command line UI, and with the directory containing the two files above as the current working directory, type
runghc th.hs
- Let me know if this doesn't work.
2013-03-02 at 12:57 am
Template Haskell: Hello World
Template Haskell is one of the standard tools for meta-programming in Haskell. I have no idea why it's so hard to find an example like this. (That's a lie - Haskell is an esoteric research language for people who have better things to do. And Template Haskell is an order beyond.) So I'm blogging what seemed to work for me.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment