RE: [Template-haskell] instance of Lift for Exp
Thanks for the offer. Has anyone else encountered a need for this? Duncan, would you like to give some motivating examples? For the present, I'm inclined to leave it as a user library. Simon | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On | Behalf Of Duncan Coutts | Sent: 08 June 2004 19:45 | To: Template Haskell List | Subject: [Template-haskell] instance of Lift for Exp | | Hi all, | | the Exp type is not an instance of the Lift class. This is the sensible | thing most of the time so that you do not lift an expression when you | meant to splice it instead. | | However in my experience it's sometimes useful (particularly when | writing code that generates code), so attached is a module which makes | it an instance. Like Text.Show.Functions, you should only import it if | you want it, not import it by default. | | If people find this useful, I'd be quite happy to have it added to the | standard GHC TH libs. I've named it Language.Haskell.TH.LiftExp and | released it under GHC's BSD-style licence. | | Issues: | * At the moment it also exports instances for Ratio, Maybe, | PackedString, (,) and (,,). In my opinion these instances should | be exported from Language.Haskell.TH already in which case they | could be deleted from this module. (Exporting the instance for | PackedString and Ratio is not strictly necessary and perhaps not | desirable.) | * The encoding for unboxed integers is not pleasant. (Unboxed Ints | are used in the definition of Name). If anyone can find a more | straightforward encoding please tell me. | | Duncan
On Tue, 2004-07-20 at 11:06, Simon Peyton-Jones wrote:
Thanks for the offer.
Has anyone else encountered a need for this? Duncan, would you like to give some motivating examples?
I probably overestimated its general usefulness. I use it (actually something very similar) to help write TH programs that manipulate and produce other TH programs. (TH can't directly represent TH programs so we have to use encodings)
For the present, I'm inclined to leave it as a user library.
Seems reasonable. It's quite simple so I might try & get it to use the new simple library build spec. Also, Ian thought it would not work well with ghc's bootstrap build system. He thought that the libs get build with a stage2 ghc which does not have ghci and therefore does not have TH enabled so my library would not build anyway if it were distributed with ghc. Is this right? Can libs distributed with ghc not use TH syntax? While on the topic of TH, let me float "yet another idea"TM Include {-# #-} pragmas in the TH abstract syntax. Why? Because it would allow domain/library-specific hints and annotations. data Pragma = PragmaGhcRule ... PragmaGhcSpecialise ... PragmaOther String --free form My application of this might be to let the user indicate binding times when doing partial evaluation, eg: {-# BT foo :: Static -> Dynamic -> Dynamic #-} foo :: Int -> Int -> int foo x y = ... Duncan
participants (2)
-
Duncan Coutts -
Simon Peyton-Jones