From golubovsky at gmail.com Wed Apr 5 05:31:35 2006 From: golubovsky at gmail.com (Dimitry Golubovsky) Date: Wed Apr 5 05:27:06 2006 Subject: [Template-haskell] instance Show Info ? Message-ID: Why there isn't one? At least in "latest" (6.4.x), only instance Ppr Info shows up. It might be useful to be able to print raw results of reification. -- Dimitry Golubovsky Anywhere on the Web From simonpj at microsoft.com Mon Apr 10 11:46:32 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Mon Apr 10 11:41:47 2006 Subject: [Template-haskell] Renaming in pretty printer Message-ID: <036EAC76E7F5EC4996A3B3C3657D41160514F96F@EUR-MSG-21.europe.corp.microsoft.com> I've no idea. It certainly seems that Language.Haskell.TH.PprLib implements a pretty-printing Doc type that does renaming as it goes. I guess that he wanted to have shorter variable names. It's done using a state monad, which looks fragile to me: it appears to rely utterly on printing TH syntax trees with NameUs that do not involve shadowing; which is probably the case, but is not part of the specification. I'm not sure who wrote it: Don Stewart perhaps. Simon | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On | Behalf Of Andy Gill | Sent: 28 March 2006 18:58 | To: template-haskell@haskell.org | Subject: [Template-haskell] Renaming in pretty printer | | Template Haskell appears to be doing renaming during pretty printing. | Take this example, that both prints the AST directly, as well as | pretty printing. | | *Main> runQ ([| let x = 1 in x |]) >>= \x -> print (pprint x,x) | ("let x_0 = 1\n in x_0",LetE [ValD (VarP x_7) (NormalB (LitE | (IntegerL 1))) []] (VarE x_7)) | | The var x has name x_7 in the AST, but x_0 in the pretty printed | version. | | Can someone comment on why this is done? | | Andy Gill From simonpj at microsoft.com Mon Apr 10 11:49:25 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Mon Apr 10 11:44:40 2006 Subject: [Template-haskell] instance Show Info ? Message-ID: <036EAC76E7F5EC4996A3B3C3657D41160514F97A@EUR-MSG-21.europe.corp.microsoft.com> No very good reason. You can always use 'ppr'. Neverthless, since the rest of Exp is in Show, I'll add Info too. Simon | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On | Behalf Of Dimitry Golubovsky | Sent: 05 April 2006 10:32 | To: template-haskell@haskell.org | Subject: [Template-haskell] instance Show Info ? | | Why there isn't one? | | At least in "latest" (6.4.x), only instance Ppr Info shows up. | | It might be useful to be able to print raw results of reification. | | -- | Dimitry Golubovsky | | Anywhere on the Web From simonpj at microsoft.com Fri Apr 14 08:09:03 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Fri Apr 14 08:04:05 2006 Subject: [Template-haskell] quasi quotes and Q monad In-Reply-To: <43BBDF65.9030402@infosun.fmi.uni-passau.de> Message-ID: <036EAC76E7F5EC4996A3B3C3657D4116051DC12C@EUR-MSG-21.europe.corp.microsoft.com> Christoph You have probably forgotten all about this, but it's been in my mailbox all along... Anyway, since today is a peaceful day, I have taken a look. Sorry for the long delay. I attach the same file you attached, to give the context. The short answer is: yes, the two versions of f do the same thing. I still can't figure out why you are worried. You say "Somehow I felt the need to connect the argument of g with the monad of which the value of g's result belongs to", but I'm not sure what you mean. Nor did I understand your last paragraph. In any case, is there a problem here? The quasi-quoted version of f works just fine. Simon | -----Original Message----- | From: Ch. A. Herrmann [mailto:herrmann@infosun.fmi.uni-passau.de] | Sent: 04 January 2006 14:45 | To: Simon Peyton-Jones | Cc: template-haskell@haskell.org | Subject: Re: [Template-haskell] quasi quotes and Q monad | | Hi Simon, | | I have reduced the program to the parts interesting for | our topic. The program is attached. | | Function f looks nice with the quasi quotation, but in case | we have to use the low-level style the argument to | g must be a monadic value, which I did here by using | return, e.g. (return (VarE x)). | | I worried whether the function f in low-level style with this | use of return is equivalent to the quasi-quoted version. | Somehow I felt the need to connect the argument of g with | the monad of which the value of g's result belongs to. It | appeared to me that this is what the quotation brackets [|y|] are | establishing, because y is also in the scope of the outer brackets. | | On the one hand, I wonder why the name generation history, when | code generation for a quotation part is finished, is not reset to the state | before. This would be the case with the separate monad for g's | argument. On the other hand, it must be possible to nest quotation | brackets and still establish that names at the different levels are | distinct, if it is wanted. | | Many thanks in advance for any enlighting explanation | -- | Christoph | | Simon Peyton-Jones wrote: | | >I've read your message, but I can't figure out what problem you are | >trying to solve. | > | >Can you give a small example that demonstrates it? | > | >Simon | > | >| -----Original Message----- | >| From: template-haskell-bounces@haskell.org | >[mailto:template-haskell-bounces@haskell.org] On | >| Behalf Of Ch. A. Herrmann | >| Sent: 02 January 2006 16:17 | >| To: template-haskell@haskell.org | >| Subject: [Template-haskell] quasi quotes and Q monad | >| | >| Dear TH experts, | >| | >| I have a problem concerning the interaction of quasi quotes and the | >| quotation monad. Assume a code generating function f (... -> Q Exp) | >| which is parameterized by a code generating function g (of type | >| Exp -> Q Exp, or(?) Q Exp -> Q Exp). | >| | >| Expressing the problem in the simplest form, the actual instance for g | >| is (\x -> [| h($x) |]), where h is a toplevel Haskell function working | >| on arbitrary types, and function f instantiates x | >| with an expression which consists just of a single variable (VarE). In | >| order to splice x in the code ($x), the type of x must be (Q Exp). The | >| reason for that, as mentioned in the 2002 paper | >| by Sheard and Peyton Jones "Template Metaprogramming for Haskell", is | >| that the computation of x must be able to access the Q monad. The | >place | >| inside f where the actual name for the variable x is generated, has | >| already access to the Q monad and the *result* of g is | >| embedded in this monad, no problem. However, I cannot figure out how | >| this monad can be passed as an *argument* to g and conceptually, there | >| is no justification to pass this monad: it is just an offspring | >version | >| of the one where the lexical scope of g belongs to. | >| | >| The value I want to pass for x is of type Exp. Of course, I could turn | >| this type into (Q Exp) by applying return, but this artificial | >instance | >| of the Q monad would come from nowhere, not being connected with the | >| regular instance used, e.g., for the fresh name generation. | >| | >| Especially, I have the following questions: | >| * Is there a simple solution to this problem? If so, please tell me | >and | >| forget about the following questions. | >| * Is the quasi quote mechanism at all appropriate for what I want to | >do | >| or should one better change to the concrete AST representation? | >That | >| | >| would be unfortunate because my aim is to develop Template Haskell | >| examples which demonstrate ease of use. | >| * If return is used to turn an expression into monadic form before | >| splicing, is it possible that | >| (a) the consistency of fresh name generation is lost, even if one | >| does the name generation for the spliced expression oneself, | >| (b) something else goes wrong? | >| | >| Many thanks in advance and a Happy New Year | >| -- | >| Christoph Herrmann | >| | >| | >| | >| _______________________________________________ | >| template-haskell mailing list | >| template-haskell@haskell.org | >| http://www.haskell.org/mailman/listinfo/template-haskell | > | > -------------- next part -------------- A non-text attachment was scrubbed... Name: Gen.hs Type: application/octet-stream Size: 1014 bytes Desc: Gen.hs Url : http://www.haskell.org//pipermail/template-haskell/attachments/20060414/561f26e8/Gen.obj From andy at galois.com Mon Apr 17 00:57:28 2006 From: andy at galois.com (Andy Gill) Date: Mon Apr 17 00:52:25 2006 Subject: [Template-haskell] Question about local bindings Message-ID: <8BBF00A8-5766-4D92-9778-B1826B829CF5@galois.com> Fellow Templaters, Why does test2 () = runQ [| foldr f z xs |] (f,z,xs) = undefined compile fine, but test2 () = runQ [| foldr f z xs |] where (f,z,xs) = undefined fail with this message: ./Language/Haskell/ER/Equation.hs:108:25: Can't splice the polymorphic local variable `f' In the first argument of `foldr', namely `f' In the first argument of `runQ', namely `[| foldr f z xs |]' In the definition of `test2': test2 () = runQ [| foldr f z xs |] where (f, z, xs) = undefined Andy Gill From simonpj at microsoft.com Tue Apr 18 08:01:45 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Tue Apr 18 07:56:36 2006 Subject: [Template-haskell] Question about local bindings In-Reply-To: <8BBF00A8-5766-4D92-9778-B1826B829CF5@galois.com> Message-ID: <036EAC76E7F5EC4996A3B3C3657D411605237238@EUR-MSG-21.europe.corp.microsoft.com> Check out Section 9.2 in the original TH paper. What you are trying to do is akin to 'genSwap' in that section. In general f depends on the arguments to test2, and so must be converted to code. The paper says this at greater length. Simon | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On | Behalf Of Andy Gill | Sent: 17 April 2006 05:57 | To: template-haskell@haskell.org | Subject: [Template-haskell] Question about local bindings | | Fellow Templaters, | | Why does | | test2 () = runQ [| foldr f z xs |] | (f,z,xs) = undefined | | compile fine, but | | test2 () = runQ [| foldr f z xs |] | where (f,z,xs) = undefined | | fail with this message: | | ./Language/Haskell/ER/Equation.hs:108:25: | Can't splice the polymorphic local variable `f' | In the first argument of `foldr', namely `f' | In the first argument of `runQ', namely `[| foldr f z xs |]' | In the definition of `test2': | test2 () | = runQ [| foldr f z xs |] | where | (f, z, xs) = undefined | | Andy Gill | | _______________________________________________ | template-haskell mailing list | template-haskell@haskell.org | http://www.haskell.org/mailman/listinfo/template-haskell From oleg.myrk at gmail.com Sun Apr 23 17:52:31 2006 From: oleg.myrk at gmail.com (=?ISO-8859-1?Q?Oleg_M=FCrk?=) Date: Sun Apr 23 17:47:04 2006 Subject: [Template-haskell] Type inference Message-ID: <1dd3af250604231452n3ccf736y91571bea60c71a5e@mail.gmail.com> Hello, I have the following problem. I'd like to infer types of local bindings using 'reify': ------------------------------------ testValue = let a = 10 in $(do VarI _ t _ _ <- reify 'a lift (pprint t) ) ------------------------------------- But this code prints only: ------------------------------------- *Debug> testValue "t_0" ------------------------------------- Is this intended behavior? Are there any workarounds? Things work fine if symbol is defined in another module. I do realise that in general $(...) may add additional constraints on local variables. OM -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org//pipermail/template-haskell/attachments/20060423/99f59224/attachment-0001.htm From bulat.ziganshin at gmail.com Mon Apr 24 05:47:35 2006 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Mon Apr 24 11:55:26 2006 Subject: [Template-haskell] Type inference In-Reply-To: <1dd3af250604231452n3ccf736y91571bea60c71a5e@mail.gmail.com> References: <1dd3af250604231452n3ccf736y91571bea60c71a5e@mail.gmail.com> Message-ID: <1291066067.20060424134735@gmail.com> Hello Oleg, Monday, April 24, 2006, 1:52:31 AM, you wrote: > I have the following problem. I'd like to infer types of local bindings using 'reify': > ------------------------------------ > testValue = > ??? let > ??? ??? a = 10 > ??? in > ??? ??? $(do > ??? ??? ??? VarI _ t _ _ <- reify 'a > ??? ??? ??? lift (pprint t) > ??? ??? ) what a type "a" should have here? :) try the (10::Int) to make compiler happy -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From simonpj at microsoft.com Tue Apr 25 03:52:35 2006 From: simonpj at microsoft.com (Simon Peyton-Jones) Date: Tue Apr 25 03:47:03 2006 Subject: [Template-haskell] Type inference In-Reply-To: <1dd3af250604231452n3ccf736y91571bea60c71a5e@mail.gmail.com> Message-ID: <036EAC76E7F5EC4996A3B3C3657D41160535387D@EUR-MSG-21.europe.corp.microsoft.com> It's expected but unfortunate. Template Haskell runs *during* type checking. So when you reify a local type, it may not yet be fully worked out. In this case it would be worse if you said let a=10 in ( $(...reify 'a...), a+1::Int ) Here it's "clear" that a has type Int, but it won't be clear to Template Haskell until after it's typechecked the whole expression. But it has to run the splice before that! That's a shortcoming I don't know how to solve at the moment. Simon ________________________________ From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On Behalf Of Oleg M?rk Sent: 23 April 2006 22:53 To: template-haskell@haskell.org Subject: [Template-haskell] Type inference Hello, I have the following problem. I'd like to infer types of local bindings using 'reify': ------------------------------------ testValue = let a = 10 in $(do VarI _ t _ _ <- reify 'a lift (pprint t) ) ------------------------------------- But this code prints only: ------------------------------------- *Debug> testValue "t_0" ------------------------------------- Is this intended behavior? Are there any workarounds? Things work fine if symbol is defined in another module. I do realise that in general $(...) may add additional constraints on local variables. OM -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org//pipermail/template-haskell/attachments/20060425/608b5642/attachment.htm