Template Haskell and Types

Hi, Probably very simple question about template haskell: How do I make a type for an argument to splice? Example: data MyData = MyData1 | MyData2 mysplice mytype = [| litE $ stringL $ show mytype |] main = do putStrLn $(mysplice MyData) The above is not accepted, error: Compiling Main ( thtest.hs, thtest.o ) thtest.hs:51:34: Not in scope: data constructor `MyData' So how do I provide type as an argument? Besides: documentation that I found for th is very dated. Could somebody point me to something more up to date about th? Thanks! -- Gracjan

I'm not exactly sure what it is that you're trying to do with that
code, but here's an approximation to that code which prints the
Template Haskell representation of the type MyData:
import Language.Haskell.TH
import Monad
data MyData = MyData1 | MyData2
main = do putStrLn $(liftM (LitE . stringL . show) [t|MyData|])
by the way -- does anyone happen to know why Q isn't an instance of
Functor? It's obviously a functor by virtue of being a monad.
- Cale
On 12/09/05, Gracjan Polak
Hi,
Probably very simple question about template haskell: How do I make a type for an argument to splice? Example:
data MyData = MyData1 | MyData2
mysplice mytype = [| litE $ stringL $ show mytype |]
main = do putStrLn $(mysplice MyData)
The above is not accepted, error:
Compiling Main ( thtest.hs, thtest.o )
thtest.hs:51:34: Not in scope: data constructor `MyData'
So how do I provide type as an argument?
Besides: documentation that I found for th is very dated. Could somebody point me to something more up to date about th? Thanks!
-- Gracjan
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Mon, Sep 12, 2005 at 12:08:14PM +0200, Gracjan Polak wrote:
Probably very simple question about template haskell: How do I make a type for an argument to splice? Example:
data MyData = MyData1 | MyData2
mysplice mytype = [| litE $ stringL $ show mytype |]
main = do putStrLn $(mysplice MyData)
Cale explained how you can quote types in general. In the special case when you simply want the Name of a type-constructor, you can use the '' quoting syntax: putStrLn $(mysplice ''MyData) Best regards Tomasz

Tomasz Zielonka wrote:
On Mon, Sep 12, 2005 at 12:08:14PM +0200, Gracjan Polak wrote:
Probably very simple question about template haskell: How do I make a type for an argument to splice? Example:
data MyData = MyData1 | MyData2
mysplice mytype = [| litE $ stringL $ show mytype |]
main = do putStrLn $(mysplice MyData)
Cale explained how you can quote types in general. In the special case when you simply want the Name of a type-constructor, you can use the '' quoting syntax:
putStrLn $(mysplice ''MyData)
Thanks for responses. Is there any up-to-date documentation avaliable?
Best regards Tomasz

On Tuesday 13 September 2005 09:16, Gracjan Polak wrote:
Tomasz Zielonka wrote:
On Mon, Sep 12, 2005 at 12:08:14PM +0200, Gracjan Polak wrote:
Probably very simple question about template haskell: How do I make a type for an argument to splice? Example:
data MyData = MyData1 | MyData2
mysplice mytype = [| litE $ stringL $ show mytype |]
main = do putStrLn $(mysplice MyData)
Cale explained how you can quote types in general. In the special case when you simply want the Name of a type-constructor, you can use the '' quoting syntax:
putStrLn $(mysplice ''MyData)
Thanks for responses. Is there any up-to-date documentation avaliable?
The only I know of is the TH 'update' paper, where e.g. the single ('a) and double (''a) quote syntax is explained: http://research.microsoft.com/~simonpj/tmp/notes2.ps Ben
participants (4)
-
Benjamin Franksen
-
Cale Gibbard
-
Gracjan Polak
-
Tomasz Zielonka