Haskell version of Idris !-notation (bang notation)

孤人 提交于 2019-12-04 01:38:41

Since every monad is an Applicative (with GHC >= 7.10) we can write

someFunction <$> a <*> b <*> c

Note that if someFunction returns a monadic value of type m T, the above will return m (m T), which is likely not what we want (as @pigworker points out below). We can however join the two layers together:

join $ someFunction <$> a <*> b <*> c

An alternative to @chi's answer is liftA3 someFunction a b c (with join if needed).

Speaking of arrows...

import Control.Arrow

a' = Kleisli $ const a
b' = Kleisli $ const b
c' = Kleisli $ const c

foo = (`runKleisli`()) $
  (a' &&& b') &&& c' >>> uncurry (uncurry someFunction)

Not that I recommend this.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!