Nicolas Henin
Nicolas Henin

Reputation: 3334

Replacing do by >>= for a scotty post

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

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

Upvotes: 3

Views: 139

Answers (2)

AJF
AJF

Reputation: 11923

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

Upvotes: 3

Cubic
Cubic

Reputation: 15703

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

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

Upvotes: 5

Related Questions