Replacing do by >>= for a scotty post

Viewed 131
post "/introduceAnIdea"  $ do
        command <- jsonData
        json $ handle command

How would you remove the do and change it with >>= ?

2 Answers
post "/introduceAnIdea" $ jsonData >>= (json . handle)

I don't think that's necessarily better in this case though.

Here's how to rewrite do-notation as >>= and >>: (NB: a newline becomes ; in the c-like notation option, which I use here.)

do { a <- m; b... } = m >>= \a -> do { b... }

do { a; b... } = a >> do { b... }

do { a } = a

So this becomes:

post "/introduceAnIdea"  $ do { command <- jsonData; json $ handle command}
= post "/introduceAnIdea" $ jsonData >>= \command -> do {json $ handle command}
= post "/introduceAnIdea" $ jsonData >>= \c -> json $ handle c
Related