From g9ks157k at acme.softbase.org Sat Sep 8 18:27:19 2007 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Sat Sep 8 18:17:31 2007 Subject: [Template-haskell] reifyDecl and reifyType not working Message-ID: <200709090027.19745.g9ks157k@acme.softbase.org> Hello, reifyDecl and reifyType seem to be recognized as identifiers and not as part of TH syntax by GHC 6.7.20070903. Take, for example, the following code: {-# LANGUAGE TemplateHaskell #-} x = reifyDecl () If I compile this (with or without -fth), I get the error message ?Not in scope: `reifyDecl'?. What?s wrong here? Best wishes, Wolfgang From simonpj at microsoft.com Mon Sep 10 03:59:45 2007 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Mon Sep 10 03:49:57 2007 Subject: [Template-haskell] reifyDecl and reifyType not working In-Reply-To: <200709090027.19745.g9ks157k@acme.softbase.org> References: <200709090027.19745.g9ks157k@acme.softbase.org> Message-ID: 'reifyDecl' is not a language construct; it's a function. You need to import Language.Haskell.TH to bring it into scope. If the user manual suggests otherwise, could you suggest improved wording? Simon | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On Behalf Of | Wolfgang Jeltsch | Sent: 08 September 2007 23:27 | To: template-haskell@haskell.org | Subject: [Template-haskell] reifyDecl and reifyType not working | | Hello, | | reifyDecl and reifyType seem to be recognized as identifiers and not as part | of TH syntax by GHC 6.7.20070903. Take, for example, the following code: | | {-# LANGUAGE TemplateHaskell #-} | | x = reifyDecl () | | If I compile this (with or without -fth), I get the error message ?Not in | scope: `reifyDecl'?. What?s wrong here? | | Best wishes, | Wolfgang | _______________________________________________ | template-haskell mailing list | template-haskell@haskell.org | http://www.haskell.org/mailman/listinfo/template-haskell From igloo at earth.li Mon Sep 10 08:18:28 2007 From: igloo at earth.li (Ian Lynagh) Date: Mon Sep 10 08:08:47 2007 Subject: [Template-haskell] reifyDecl and reifyType not working In-Reply-To: References: <200709090027.19745.g9ks157k@acme.softbase.org> Message-ID: <20070910121828.GA24338@matrix.chaos.earth.li> On Mon, Sep 10, 2007 at 08:59:45AM +0100, Simon Peyton-Jones wrote: > 'reifyDecl' is not a language construct; it's a function. You need to import Language.Haskell.TH to bring it into scope. It's also just called reify these days. Thanks Ian From g9ks157k at acme.softbase.org Mon Sep 10 12:57:09 2007 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Mon Sep 10 12:47:19 2007 Subject: [Template-haskell] reifyDecl and reifyType not working In-Reply-To: <20070910121828.GA24338@matrix.chaos.earth.li> References: <200709090027.19745.g9ks157k@acme.softbase.org> <20070910121828.GA24338@matrix.chaos.earth.li> Message-ID: <200709101857.09639.g9ks157k@acme.softbase.org> Am Montag, 10. September 2007 14:18 schrieb Ian Lynagh: > On Mon, Sep 10, 2007 at 08:59:45AM +0100, Simon Peyton-Jones wrote: > > 'reifyDecl' is not a language construct; it's a function. You need to > > import Language.Haskell.TH to bring it into scope. > > It's also just called reify these days. This is not what the GHC User?s Guide talks about when discussing reifyDecl and reifyType. In an expression reifyDecl A, A has to be a type constructor or a class, and in an expression reifyType a, a has to be an identifier. So reifyDecl and reifyType cannot be functions but must be language constructs. On the other hand, reify expects a value of type Name as an argument. The problem is that I wanted to use reifyDecl as a workaround to create values of type Name. The Template Haskell library doesn?t seem to provide a way to create a Name value which always refers to the same entity, regardless of the splice where it is used. So I wanted to use workarounds like this: className :: Name ClassD _ className _ _ _ = reifyDecl Class Best wishes, Wolfgang From igloo at earth.li Mon Sep 10 16:13:50 2007 From: igloo at earth.li (Ian Lynagh) Date: Mon Sep 10 16:04:00 2007 Subject: [Template-haskell] reifyDecl and reifyType not working In-Reply-To: <200709101857.09639.g9ks157k@acme.softbase.org> References: <200709090027.19745.g9ks157k@acme.softbase.org> <20070910121828.GA24338@matrix.chaos.earth.li> <200709101857.09639.g9ks157k@acme.softbase.org> Message-ID: <20070910201350.GA14430@matrix.chaos.earth.li> On Mon, Sep 10, 2007 at 06:57:09PM +0200, Wolfgang Jeltsch wrote: > Am Montag, 10. September 2007 14:18 schrieb Ian Lynagh: > > On Mon, Sep 10, 2007 at 08:59:45AM +0100, Simon Peyton-Jones wrote: > > > 'reifyDecl' is not a language construct; it's a function. You need to > > > import Language.Haskell.TH to bring it into scope. > > > > It's also just called reify these days. > > of type Name. The Template Haskell library doesn?t seem to provide a way to > create a Name value which always refers to the same entity, regardless of the > splice where it is used. So I wanted to use workarounds like this: > > className :: Name > ClassD _ className _ _ _ = reifyDecl Class You can get names with the ' and '' syntax: $ ghci -fth Prelude> ''Eq GHC.Base.Eq Prelude> 'id GHC.Base.id Thanks Ian From g9ks157k at acme.softbase.org Mon Sep 10 17:59:15 2007 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Mon Sep 10 17:49:24 2007 Subject: [Template-haskell] reifyDecl and reifyType not working In-Reply-To: <20070910201350.GA14430@matrix.chaos.earth.li> References: <200709090027.19745.g9ks157k@acme.softbase.org> <200709101857.09639.g9ks157k@acme.softbase.org> <20070910201350.GA14430@matrix.chaos.earth.li> Message-ID: <200709102359.15958.g9ks157k@acme.softbase.org> Am Montag, 10. September 2007 22:13 schrieb Ian Lynagh: > On Mon, Sep 10, 2007 at 06:57:09PM +0200, Wolfgang Jeltsch wrote: > > Am Montag, 10. September 2007 14:18 schrieb Ian Lynagh: > > > On Mon, Sep 10, 2007 at 08:59:45AM +0100, Simon Peyton-Jones wrote: > > > > 'reifyDecl' is not a language construct; it's a function. You need > > > > to import Language.Haskell.TH to bring it into scope. > > > > > > It's also just called reify these days. > > > > of type Name. The Template Haskell library doesn?t seem to provide a way > > to create a Name value which always refers to the same entity, regardless > > of the splice where it is used. So I wanted to use workarounds like > > this: > > > > className :: Name > > ClassD _ className _ _ _ = reifyDecl Class > > You can get names with the ' and '' syntax: Oh, I didn?t know about this syntax. Is this documented somewhere? >[?] Best wishes, Wolfgang From bulat.ziganshin at gmail.com Tue Sep 11 02:54:12 2007 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Tue Sep 11 02:56:22 2007 Subject: [Template-haskell] reifyDecl and reifyType not working In-Reply-To: <200709102359.15958.g9ks157k@acme.softbase.org> References: <200709090027.19745.g9ks157k@acme.softbase.org> <200709101857.09639.g9ks157k@acme.softbase.org> <20070910201350.GA14430@matrix.chaos.earth.li> <200709102359.15958.g9ks157k@acme.softbase.org> Message-ID: <1147061520.20070911105412@gmail.com> Hello Wolfgang, Tuesday, September 11, 2007, 1:59:15 AM, you wrote: >> > > > 'reifyDecl' is not a language construct; it's a function. You need >> You can get names with the ' and '' syntax: > Oh, I didn?t know about this syntax. Is this documented somewhere? afair, reifyDecl was described in the first TH paper while reify and '/'' in the second one: http://www.haskell.org/ghc/docs/papers/th2.ps you may also look at http://www.haskell.org/bz/thdoc.htm (written by me) which describes whole TH -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From simonpj at microsoft.com Tue Sep 11 04:22:34 2007 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Tue Sep 11 04:12:46 2007 Subject: [Template-haskell] reifyDecl and reifyType not working In-Reply-To: <1147061520.20070911105412@gmail.com> References: <200709090027.19745.g9ks157k@acme.softbase.org> <200709101857.09639.g9ks157k@acme.softbase.org> <20070910201350.GA14430@matrix.chaos.earth.li> <200709102359.15958.g9ks157k@acme.softbase.org> <1147061520.20070911105412@gmail.com> Message-ID: I'll improve the documentation too S | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On Behalf Of | Bulat Ziganshin | Sent: 11 September 2007 07:54 | To: Wolfgang Jeltsch | Cc: template-haskell@haskell.org | Subject: Re[2]: [Template-haskell] reifyDecl and reifyType not working | | Hello Wolfgang, | | Tuesday, September 11, 2007, 1:59:15 AM, you wrote: | >> > > > 'reifyDecl' is not a language construct; it's a function. You need | | >> You can get names with the ' and '' syntax: | | > Oh, I didn?t know about this syntax. Is this documented somewhere? | | afair, reifyDecl was described in the first TH paper while reify and | '/'' in the second one: http://www.haskell.org/ghc/docs/papers/th2.ps | | you may also look at http://www.haskell.org/bz/thdoc.htm (written by me) | which describes whole TH | | -- | Best regards, | Bulat mailto:Bulat.Ziganshin@gmail.com | | _______________________________________________ | template-haskell mailing list | template-haskell@haskell.org | http://www.haskell.org/mailman/listinfo/template-haskell From b.hilken at ntlworld.com Tue Sep 11 08:03:04 2007 From: b.hilken at ntlworld.com (Barney Hilken) Date: Tue Sep 11 07:53:17 2007 Subject: [Template-haskell] Generating classes Message-ID: <4BD597E3-1888-4709-81EE-B513E22A3755@ntlworld.com> Here's a fun exercise in TH. I've noticed in several bits of Haskell code how people define a concrete datatype to represent some data, but also a typeclass with corresponding member functions in case someone wants to use a different representation. Mathematically the relationship between the type and the class is like the relationship between a free algebra and the class of all algebras. Logically, it's like the relationship between the abstract syntax and the class of models. I've been meaning to try out Template Haskell, so why not write some TH code to do it all automatically? So here it the exercise: 1. Write a TH function which takes (the name of) a recursive datatype, and declares the corresponding typeclass. 2. Extend it to declare the type an instance of the class. These are pretty straightforward, once you've got the hang of TH. The key mathematical property of term algebras is that they are initial: you can map them (uniquely) into any algebra. This extends to any recursive definition, provided it is functorial in the recursion (so T = X -> T is ok, but T = T -> X is not). 3. Automatically generate the polymorphic function from the datatype to an arbitrary type in the class. This is as far as I've got. But we could easily go further: 4. Add support for record labels and the terminal coalgebra property. 5. Generalise to turn n mutually recursive datatypes into an n- parameter typeclass. If the TH 'reify' function wasn't limited to '98 datatypes, we could try: 6. How about existentials? 7. GADTs? I've appended my solution to parts 1-3. If anyone's interested, I'll have a go at 4 & 5. Is this kind of code of any use to anyone? Barney. Attachments: UnivAlg.hs defines the function which does all the work, Test.hs gives some recursive datatypes for testing, and FunctorN.hs generalises the functor class to multiple arguments. -------------- next part -------------- A non-text attachment was scrubbed... Name: UnivAlg.hs Type: application/octet-stream Size: 6697 bytes Desc: not available Url : http://www.haskell.org/pipermail/template-haskell/attachments/20070911/437d69fe/UnivAlg-0001.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: Test.hs Type: application/octet-stream Size: 892 bytes Desc: not available Url : http://www.haskell.org/pipermail/template-haskell/attachments/20070911/437d69fe/Test-0001.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: FunctorN.hs Type: application/octet-stream Size: 606 bytes Desc: not available Url : http://www.haskell.org/pipermail/template-haskell/attachments/20070911/437d69fe/FunctorN-0001.obj From g9ks157k at acme.softbase.org Thu Sep 13 16:25:08 2007 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Thu Sep 13 16:25:11 2007 Subject: [Template-haskell] type quotation brackets work! Message-ID: <200709132225.08803.g9ks157k@acme.softbase.org> Hello, wow, I didn?t know that the [t|?|] syntax has been implemented already. The GHC User?s Guide says, it isn?t. Could someone please update it? Best wishes, Wolfgang From simonpj at microsoft.com Fri Sep 14 04:59:57 2007 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Fri Sep 14 04:59:55 2007 Subject: [Template-haskell] type quotation brackets work! In-Reply-To: <200709132225.08803.g9ks157k@acme.softbase.org> References: <200709132225.08803.g9ks157k@acme.softbase.org> Message-ID: Yes type *quotes* are implemented, but type *splices* are not. I think the current user manual reflects this, certainly in HEAD. Simon | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On Behalf Of | Wolfgang Jeltsch | Sent: 13 September 2007 21:25 | To: template-haskell@haskell.org | Subject: [Template-haskell] type quotation brackets work! | | Hello, | | wow, I didn?t know that the [t|?|] syntax has been implemented already. The | GHC User?s Guide says, it isn?t. Could someone please update it? | | Best wishes, | Wolfgang | _______________________________________________ | template-haskell mailing list | template-haskell@haskell.org | http://www.haskell.org/mailman/listinfo/template-haskell