RE: [Template-haskell] Records and generating splices
Template Haskell is indeed poorly documented. I keep hoping that someone will undertake the task of writing better documentation, since that is something that doesn't have to be done at GHC HQ. Meanwhile, your best bets are a) the user manual http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell .html including the "notes2.ps" pointed to from the user manual, and the original paper b) the Template Haskell mailing list... but no one has replied to your message. You could try ghc-users for a wider audience c) when it comes to the exact name for each constructor and function, you need the online library documentation, but I think you've found that already. It's not clear from your message, but I think you want to do something like what is described in Section 8 of http://research.microsoft.com/~simonpj/tmp/notes2.ps. If so, I'm afraid that isn't implemented yet, and (somewhat to my surprise) no one has been yelling for it. It's not trivial to implement unfortunately. It's also not essential: you can drop down to the explicit-constructor level described in the original paper. Simon | -----Original Message----- | From: template-haskell-bounces@haskell.org [mailto:template-haskell-bounces@haskell.org] On | Behalf Of Rene de Visser | Sent: 08 July 2005 13:40 | To: template-haskell@haskell.org | Subject: [Template-haskell] Records and generating splices | | Hello, | | In the following code I wish to generate the invidual accessors, i.e. the | add_rel1, add_rel2, etc. | | I have tried using | | test = [| add_rel1 value = modify (\db -> db{ rel1 = Set.insert value (rel1 | db)}) |] | | with some splicing, but it does not seem possible to splice in the rel1 | before the '='. | Also how do I splice in the add_rel1? | | According to the documentation it is only possible to splice in complete | expressions. This seems quite limiting. Does this mean you always have to | construct the expressions by hand? | | The library documention seems very thin. Its hard to tell how to create a | record accessor and setter from the haddock documentation. | | Note that I have no experience with template haskell. | | It would also be nice to generate the type declaration, but I am finding | this even more difficult. | | Can any one provide some example code to do this. | | Rene. | | | {-# OPTIONS -fglasgow-exts #-} | module DataBase where | | import Control.Monad.State | import qualified Data.Set as Set | -- Does this really need to be extensible??? | -- Entries need to be based on sets, or something similar... | data SmallDB = SmallDB { rel1 :: Set.Set String | , rel2 :: Set.Set Integer } deriving Show | | emptyDB = SmallDB Set.empty Set.empty | | add_rel1 :: (MonadState SmallDB m) => String -> m () | add_rel1 value = modify (\db -> db{ rel1 = Set.insert value (rel1 db)}) | | add_rel2 :: (MonadState SmallDB m) => Integer -> m () | add_rel2 value = modify (\db -> db{ rel2 = Set.insert value (rel2 db)}) | | | _______________________________________________ | template-haskell mailing list | template-haskell@haskell.org | http://www.haskell.org/mailman/listinfo/template-haskell
participants (1)
-
Simon Peyton-Jones