用>> =代替do撰写文章 [英] Replacing do by >>= for a scotty post

查看:99
本文介绍了用>> =代替do撰写文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

您将如何删除do并使用>> =进行更改?

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

推荐答案

以下是将do-表示法重写为>>=>>的方法:(注意:换行符以类似c的表示法变为;选项,我在这里使用.)

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

所以它变成:

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

这篇关于用&gt;&gt; =代替do撰写文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆