【发布时间】:2014-10-14 13:13:26
【问题描述】:
我有这个
newtype State' s a = State' { runState' :: (s, Counts) -> (a, s, Counts) }
现在我想写一个函数
getCounts :: State' s a -> Counts
有什么办法可以做到吗?
【问题讨论】:
-
我猜你想要这样的东西:
getCounts :: State' s Counts? (在你运行你的状态计算之前,你不可能知道计数 - 所以你可能想从状态内部查询计数?) -
@CarstenKönig 我认为应该是
getCounts :: State' s Counts,更准确地说。 -
getCounts = State' (\ (s,c) -> (c,s,c))呢? -
不会
State' s a ~ State (s, Counts) a其中State来自Control.Monad.State?我建议看看get是如何为那个 monad 实现的,以获得一些想法。 -
@dosmath 如果您只是想从该州获得它,
Counts是什么并不重要 - 它实际上只有 anothers在那里(我认为这也是 bheklilr 想说的)