单价的情况 [英] case on monadic value

查看:72
本文介绍了单价的情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以对存储在monad中的值执行大小写操作而不必将名称绑定到该值?

Is there a way to perform a case on the value stored within a monad without having to bind a name to it?

即而不是这样做:

c <- getChar
case c of
  ...

有没有办法做到这一点:

Is there a way to do this:

mcase getChar of
  ...

或者,如果可以部分应用case语句,那就很好了:

Alternatively, it would be nice if the case statement could be partially applied so:

case of
  ...

将被视为:

\a -> case a of
  ...

所以您可以这样做:

getChar >>= case of
              ...

推荐答案

答案是否定的.在Haskell 98中,不能在不使用名称的情况下使用case语句.但是,有一个提案用于添加对case-lambda的支持.他们提出的语法也与您提出的相同.

The answer is no. In Haskell 98, you can't use a case statement without using a name inside it. But there is a proposal for adding support for case-lambdas. The syntax they propose is the same you propose too.

这篇关于单价的情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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