gpt4 book ai didi

syntax - `~` 在 Haskell 中意味着什么?

转载 作者:行者123 更新时间:2023-12-02 05:54:45 25 4
gpt4 key购买 nike

我正在研究mtl库并尝试做一些我自己的MonadTransformers。我正在检查 Control.Monad.State.StateT 声明,在所有代码中,我看到了以下语法:

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

这个~操作数是什么意思?

最佳答案

这是 Haskell 中惰性模式的表示法。我不能说我很熟悉但是from here :

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.

此外,this section可能有用。

关于syntax - `~` 在 Haskell 中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2263541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com