
4 Jul
2008
4 Jul
'08
9:29 a.m.
Hi,
busNum n | (isBusId n) = $(modify 'query) ($(set 'queryBusNumber) (Just n)) | otherwise = id
The solution I am using is creating for each record type @Rec@, and each of its fields @fieldName :: T@ an updater updateFieldName :: (T -> T) -> Rec -> Rec This way you can write busNum n | (isBusId n) = updateQuery $ updateQueryBusNumber $ const (Just n) | otherwise = id The task of creating updaters can be automated using TH, this is what the attached library does: all you need is to say $(genUpdaters ''Opts) $(genUpdaters ''Query) Cheers, Misha