gpt4 book ai didi

haskell - ST monad 声明的语法

转载 作者:行者123 更新时间:2023-12-04 07:50:22 28 4
gpt4 key购买 nike

我最近开始在 Hackage 上查看核心库,并且有一个反复出现的习惯用法我不明白。这是 ST module 中的一个示例:

instance Monad (ST s) where
{-# INLINE (>>=) #-}
(>>) = (*>)
(ST m) >>= k
= ST (\ s ->
case (m s) of { (# new_s, r #) ->
case (k r) of { ST k2 ->
(k2 new_s) }})

尤其看不懂 (# new_s, r #) .我假设第二个哈希是指未装箱的值,但其余的对我来说是个谜(大概与“新状态”有关)。

最佳答案

(# x, y, z #)是一个包含三个元素的未装箱元组。请参阅 https://downloads.haskell.org/~ghc/6.8.3/docs/html/users_guide/primitives.html 上的“8.2.2. 未装箱元组” .

其余的基本上只是状态的一个实现。

关于haskell - ST monad 声明的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43288067/

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