Neden bu kodun neden sadece bir kez döneceğini ve neden çıktığını anlamıyorum? Ghci'de sadece ilk döngüye cevap verebilirim, o zaman değişken kontrolu yanlış olarak ayarlanmış gibi görünüyor ve cevap verme isteğim yok.StateT ile Döngü: Bu döngü neden dönmez?
sonucudur:
*Main> testLoop1 td10
test
Do you want to continue? (y/N)
y
we continue
test
Do you want to continue? (y/N)
We stop
kodu:
type TDeckSTIO = StateT TableDecks IO
continue = do
putStrLn "Do you want to continue? (y/N)"
c <- getChar
return $ c == 'y'
loop1 :: TDeckSTIO()
loop1 = do
liftIO $ putStrLn "test"
cont<- liftIO continue
if cont
then do
liftIO $ putStrLn "we continue"
liftIO $ testLoop1 td
else liftIO $ putStrLn "We stop"
testLoop1 td = runStateT (loop1) td >> return()
Tam olarak istediklerimi ve daha fazlasını sağla. Sadece kodu değiştirdiğimde ve '\ n 'yi gösteren bir yazdırma s eklediğimde yol bulmadaydım. LiftIO $ testLoop1 td -> loop1 üzerindeki ipucu için teşekkürler. Bu benim önceki testlerimden biriydi ve hangi iki koddan hangisinin değiştirileceğini merak ediyordum. Ve evalState ile iyi nokta. Bu benim statetransformer ve IO ile ilk saldırı oldu. –