Hello.
DrIFT which i am now maintaining can derive such utility functions out of the box. just add a {-!deriving: update -} to get update functions for every labeled field in a datatype. quite useful, I have not updated the web page yet, but the new DrIFT homepage will be at
Nothing against DrIFT, but it requieres running preprocessing before real compilation; I don't like it for short programs, that I have defined just in one module and I'm debugging/modificating them. I've thought about syntax for set/update functions some time ago too. What I though about is: ({assignments}) desugars to \x->x{assignments} x{as, field =, bs} desugars to \y->x{as, field = y, bs} x{as, field, bs} desugars to \f->x{as, field = f (field x), bs} Then set function would be just ({field =}) and apply ({field}) (it does not need to create some artificial names for them that could colide with user names). Not really sure it does not conflict with rest of syntax, though. Zdenek Dvorak
Anyway I'd prefer to have some way to 'derive' apply and set functions. Something like
data MyData = MyData { foo :: fooType, bar :: ..., .... } deriving (Set, Apply)
Using the keyword "deriving" would probably be a bad idea though :) The set and apply functions could be derived with a standard postfix or maybe prefix... fooAp or apFoo. Maybe we could introduce sintax to specify it...
deriving (Set with "set", Apply with "ap")
I don't know... I'm just brainstorming right now. Having actual functions is important. I don't think I have to explain why to people in this mailing list :-)
Anyway, does such a thing exist, and, if not, is there any chance it could exist, or is it just syntactic salt to too many people? :) I whish you better luck than I've had so far whenever making posts about this same issue ;)
_________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx