
On Jan 11, 2008 2:01 AM, Michael Roth
Hello list, Exists there a way to write this cleaner without writing countless "set_xyz" helper functions?
The "set_xyz" methods have to be written, but that doesn't mean *you* have to write them. You can use Template Haskell to automatically derive setter functions for you. Writing the TH derivations is a little fiddly, but luckily others have already encountered the same problem. These blog posts can point you to a few implementations: http://luqui.org/blog/archives/2007/08/05/haskell-state-accessors-second-att... (http://tinyurl.com/2ve2zw) http://twan.home.fmf.nl/blog/haskell/overloading-functional-references.detai... (http://tinyurl.com/2ustba) In particular, take a look at Luke's code, because it also contains helper functions for combining these getters and setters with MonadState. Stuart