本文介绍了Haskell:在liftM2中删除括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除标有
你可以通过使用 $ 来摆脱最后一个,但是另一个不能在不引入新名字的情况下明显被删除。更好的解决方案可能是使用以下事实:任何 Monad m 也应该是 Applicative 和 Functor (和将,来自GHC 7.10)
然后您的示例变为
import Control.Applicative((< $>,(*))
(+)< ; $> somefunc arg1(get arg2)* somefunc arg3(get arg3)
How to remove the parentheses marked with ^, without introducing new names? (better if it can be splitted into multiple lines)
liftM2 (+) (somefunc arg1 (get arg2)) (somefunc arg3 (get arg3)) ^ ^ ^ ^ -
解决方案
You can get rid of the last one by using $, but the other one cannot obviously be removed without introducing new names. A better solution may be to use the fact that any Monad m should also be Applicative and Functor (and will be, come GHC 7.10)
Your example then becomes
import Control.Applicative ((<$>), (<*>)) (+) <$> somefunc arg1 (get arg2) <*> somefunc arg3 (get arg3)
这篇关于Haskell:在liftM2中删除括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!