[Template-haskell] RE: Template Haskell...
Wolfgang Thaller
wolfgang.thaller at gmx.net
Wed Oct 29 22:11:56 EST 2003
> For some time now I've been saying that Tim and I are working on the
> design of some enhancements to Template Haskell. It's taken longer
> than
> I'd hoped, and we aren't done yet, but you can find a draft at
> http://research.microsoft.com/~simonpj/tmp/notes.ps
Great stuff!
I've recently done some TH work again, so let me add something to the
wish-list:
Another thing that I'm really missing with the current Template Haskell
is a "decent" way to pass state between different meta-functions. Let
me provide a few examples of the things I want to do:
I have one meta-function that generates declarations; and I have
another meta function that needs to know what definitions generated by
the first meta function there are (accross module boundaries).
In my case, the first meta function would declare an Objective-C class
and the second one would register all classes with the Objective-C
runtime.
Manuel Chakravarty provided me with a nice workaround involving the use
of (unsafePerformIO $ newIORef ...) global variables from the Q monad.
But to make that scheme work transparently, I would still need things
like
reifyImportedModules :: [String] -- or Q [String]
reifyCurrentModuleName :: String -- or Q String
And of course, using unsafePerformIO is generally not a nice thing to
do, so if somebody could think of a more general solution, that would
be great.
Another "ugly" idiom that I've been using a lot:
I have a function declareClass :: String -> String -> Q [Dec].
$(declareClass "Bar" "Foo")
declares Haskell data types for an Objective-C class "Bar", which is
derrived from another Objecive-C class "Foo".
But it also defines
super_Bar = "Foo"
because another meta-function will require that information. The
identifier "super_Bar" will never be explicitly used by the user of my
template library.
So I have lots of identifiers where the associated meta-information is
stored in separate variables whose name is somehow based on the
original name. It works, but all that text manipulation feels more like
shell scripts than Haskell...
Cheers,
Wolfgang
More information about the template-haskell
mailing list