[英]Haskell: How does MonadState's put work?
http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/html/src/Control-Monad-State-Lazy.html http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/html/src/Control-Monad-State-Lazy.html
instance (Monad m) => MonadState s (StateT s m) where
get = StateT $ \s -> return (s, s)
put s = StateT $ \_ -> return ((), s)
What does the () do in the definition of put? ()在put的定义中做了什么?
The () is the return value of the action. ()是动作的返回值。 Since
put
is used for its side effect (change state), it doesn't return anything useful. 由于
put
用于其副作用(更改状态),因此它不会返回任何有用的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.