Bulat Ziganshin wrote:
as you can see, it don't supports reification, recovery and
information about currently compiled module just because there is no
such information when program runs. and of course, you can't add new
fields or new functions at run-time. isntead typical technique is:

$(transform [d| data D = X {f::Int, g::String} |] )

where 'transform' parses declaration passed and generates something
like this

data D = X {unique::Int, f::Int, g::String}


Thanks - by coincidence I was also coming to this conclusion after reading the tutorial because it avoids the nusiance of being left with unwanted data/instance decls in the module (and the need to rename everything when generating the extended data/instance decls to avoid conflicts with field names etc).

The solution seems to be something like:

   $(extend_data [d|
           data D = X {f::Int, g::String}
       |])

   $(extend_instance [d|
           instance Obj D where
               ...
       |])

for some fairly trivial extend functions which will just add the AST for the extra field and method to the AST of the data and instance respectively, and by the idea in http://www.haskell.org/bz/th3.htm I can just use ghci to get the extra syntax trees to copy and paste into my extend functions.

Still it's too late tonight to do any more programming so I'll have to leave this for tomorrow... ! ;-)

Best regards, Brian.
--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to