“〜”在Haskell中的含义是什么? [英] What does `~` mean in Haskell?

查看:107
本文介绍了“〜”在Haskell中的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 mtl 图书馆,并试图自己做一些MonadTransformers。我正在检查 Control.Monad.State.StateT 声明,并且在所有代码中,我看到了这个语法:

I'm studying the mtl library and trying to do some MonadTransformers of my own. I was checking the Control.Monad.State.StateT declaration, and across all the code, I see this syntax:

execStateT :: (Monad m) => StateT s m a -> s -> m s
execStateT m s = do
  ~(_, s') <- runStateT m s
  return s'

这是操作数是什么意思?

What does this ~ operand mean?

推荐答案

这是Haskell中一个懒惰模式的符号。我不能说我对它很熟悉,但从这里

This is the notation for a lazy pattern in Haskell. I can't say that I'm familiar with it but from here:


它被称为懒惰模式,具有
形式〜pat。懒惰模式是
无可辩驳的:匹配值v
反对〜pat总是成功,
不管轻拍。在操作上,
在讲话中,如果pat中的标识符在
后面used在右边,则
将被绑定到
的那个部分,如果v是
才能成功匹配pat,否则⊥

It is called a lazy pattern, and has the form ~pat. Lazy patterns are irrefutable: matching a value v against ~pat always succeeds, regardless of pat. Operationally speaking, if an identifier in pat is later "used" on the right-hand-side, it will be bound to that portion of the value that would result if v were to successfully match pat, and ⊥ otherwise.

另外,本节可能有用。

这篇关于“〜”在Haskell中的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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