假设我有一个修改底层状态的过程Int
:
p1 :: ProcessT (State Int) Int Int
p1 = repeatedly $ do
a <- await
lift . modify $ (+a)
yield a
另一个修改底层状态是[Int]
:
p2 :: ProcessT (State [Int]) Int Bool
p2 = repeatedly $ do
a <- await
lift . modify $ (++[a])
as <- get
if length as > 3 then yield True else yield False
我想这样组合它们:
p3 = source [1...6] ~> p1 ~ p2
并像这样运行它们:
flip runState 0 . flip runState [] . runT $ p3
但我得到这个错误:
Couldn't match expected type `Int' with actual type `[Int]'
Expected type: ProcessT (State Int) Int c0
Actual type: ProcessT (State [Int]) Int Bool
In the second argument of `(~>)', namely `p2'
In the expression: source [1 .. 6] ~> p1 ~> p2
建议 p1 和 p2 应该具有相同类型的基础状态。事实上,一个小实验表明 p1 和 p2 实际上正在修改相同的底层状态。我怎么能回避这个?