私はしばらく探していましたが、切り替えに関する基本的なことを誤解していると思います。次のコードを検討してください
mywire :: HasTime t s => Wire s () IO a Int
mywire = pure 10
mycont :: HasTime t s => Wire s () IO a (Wire s () IO a Int)
mycont = after 10 . pure (pure 20)
mycont' :: HasTime t s => Wire s () IO a (Event (Wire s () IO a Int))
mycont' = now . mycont
mything :: HasTime t s => Wire s () IO a (Int, Event (Wire s () IO a Int))
mything = (,) <$> mywire <*> mycont'
mainwire :: (Monad m, HasTime t s) => Wire s () m a Int
mainwire = switch mything
main :: IO ()
main = testWire clockSession_ mainwire
関係するいくつかのタイプの感覚を得るために、ここでは非常に冗長になっていることに注意してください。出力に期待しているのは、10が10秒間繰り返された後、mainwire
から返されたイベントに切り替えることですmything
(からのイベントmything
は10秒遅れているため)。代わりに表示されているのはメインワイヤです。 10秒間抑制し、続いて20秒間抑制します。スイッチの前に最初に10が出力されないのはなぜですか?切り替えがどのように機能するのか誤解していると思いますので、ご説明いただければ幸いです。ありがとうございました。
問題は内にありますnow . mycont
。now
anya
を直接に変換するためEvent a
、switch
直接mycont
ワイヤに切り替わります。このワイヤは10秒間禁止されてから、を出力します20
。必要な効果を実現するには、次のat
関数を使用できます。
import Prelude hiding ((.))
import Control.Wire
mywire :: (Monad m, HasTime t s) => Wire s () m a Int
mywire = pure 10
mycont :: (Monad m, HasTime t s) => Wire s () m a (Event (Wire s () m a Int))
mycont = at 10 . pure (pure 20)
mything :: (Monad m, HasTime t s) => Wire s () m a (Int, Event (Wire s () m a Int))
mything = (,) <$> mywire <*> mycont
mainwire :: (Monad m, HasTime t s) => Wire s () m a Int
mainwire = switch mything
main :: IO ()
main = testWire clockSession_ mainwire
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加