MonadState source code'a baktım, neden bu 3 fonksiyonun neden ölü döngüye girmeyeceğini anlamıyorum? Bu nasıl değerlendiriliyor? sınıfı bildiriminde get,put,state
arasındaMonadState'e koyma ve durumu alma
class Monad m => MonadState s m | m -> s where
-- | Return the state from the internals of the monad.
get :: m s
get = state (\s -> (s, s))
-- | Replace the state inside the monad.
put :: s -> m()
put s = state (\_ -> ((), s))
-- | Embed a simple state action into the monad.
state :: (s -> (a, s)) -> m a
state f = do
s <- get
let ~(a, s') = f s
put s'
return a
Neticede 'let 'ifadesindeki' ~ 'ne yapar? – rafalio
@radicality Kalıbı "reddedilemez" yapar. Ama aslında bu durumda hiçbir şey yapmıyor, çünkü izin veren bir düzen içindeki kalıplar zaten reddedilemez. Reddedilemez bir desen eşleşmesi, derleyiciye eşleşen kurucu hakkında doğru olduğunuzu söyler, böylece argümanlarından birinin değeri gerçekten zorlanana kadar yıkımı geciktirebilir. Kullanılan kurucu hakkında yanlış olsaydınız, o sırada bir istisna artırılacak, ancak daha önce değil. – Carl