[Haskell-cafe] Advice needed on how to improve some code
Andrew Butterfield
Andrew.Butterfield at scss.tcd.ie
Thu Apr 16 08:32:45 UTC 2015
> On 16 Apr 2015, at 09:22, Tom Ellis <tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:
>
> I rather like the >>= invocations. `do` notation would require naming
> intermediate variables.
But the >>= requires such intermediate variables anyway: all the pl' after the \
>
>> On Wed, Apr 15, 2015 at 8:57 PM, Jeff <jeff at datalinktech.com.au> wrote:
>>
>>> return pl ) >>=
>>> ( \pl' -> let pld = P.payloadData pl' in
>>> if testBit mdm ( fromEnum D.GPS )
>>> then
>>> parseDeviceGPSData >>=
>>> ( \s -> return ( pl' { P.payloadData = pld {
>>> P.gpsData = Just s } } ) )
>>> else
>>> return pl' ) >>=
>>> ( \pl' -> let pld = P.payloadData pl' in
>>> if testBit mdm ( fromEnum D.GSM )
>>> then
>>> parseDeviceGSMData >>=
>>> ( \s -> return ( pl' { P.payloadData = pld {
>>> P.gsmData = Just s } } ) )
>>> else
>>> return pl' ) >>=
>>> ( \pl' -> let pld = P.payloadData pl' in
>>> if testBit mdm ( fromEnum D.COT )
>>> then
>>> parseDeviceCOTData >>=
>>> ( \s -> return ( pl' { P.payloadData = pld {
>>> P.cotData = Just s } } ) )
>>> else
>>> return pl' ) >>=
Do notation is just syntax sugar for the above
do
pl' <- .....
pl' <- ....
pl' <- ...
No additional variable invention required !
Andrew Butterfield
School of Computer Science & Statistics
Trinity College
Dublin 2, Ireland
More information about the Haskell-Cafe
mailing list