基になる状態を変更するプロセスがあるとしましょう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 が実際には同じ基礎となる状態を変更していることがわかります。どうすればこれを回避できますか?