10
狀態單子「接口」續單子「接口」
class MonadState s m where
get :: m s
put :: s -> m()
(+返回和結合)允許構建具有國家單子任何可能的計算,而不使用State
構造。例如,State $ \s -> (s+1, s-1)
可以寫成
do s <- get
put (s-1)
return (s+1)
相若方式,我從來沒有使用Reader
構造,因爲我可以創建使用ask
,return
和(>>=)
該計算。準確地說:Reader f == ask >>= return . f
。
是不是同一真正的延續 - 這可能(在MonadCont
的唯一功能)使用callCC
寫的Cont r a
所有實例,返回和綁定,永不鍵入類似Cont (\c -> ...)
?
但是,如果您有分隔延續,我預計會發生這種變化...... – 2010-04-18 13:21:40