
Thanks Tom, David and Claude for your replies.
On 16 Apr 2015, at 4:03 pm, Tom Ellis
wrote: The first thing you should do is define
parseDeviceGPSDataOf constructor parser setField = ( \pl' -> let pld = P.payloadData pl' in if testBit mdm ( fromEnum constructor ) then parser >>= ( \s -> return ( pl' { P.payloadData = setField pld (Just s) } } ) ) else return pl' )
and your chain of binds will become
setgpsData pld = pld { P.gpsData = Just s } ...
parseDeviceDataOf D.GPS parseDeviceGPSData setgpsData >>= parseDeviceDataOf D.GSM parseDeviceDSMData setgsmData >>= parseDeviceDataOf D.COT parseDeviceCOTData setcotData >>= ...
Then I would probably write
deviceSpecs = [ (D.GPS, parseDeviceGPSData, setgpsData) , (D.GSM, parseDeviceDSMData, setgsmData) , (D.COT, parseDeviceCOTData, setcotData) ]
and turn the chain of binds into a fold.
I’ll do as you have suggested Tom. Thanks. Jeff