Is State monad needed/useful in a language with mutable (local) variables (such as Scala)?
问题 I understand that in Haskell the State monad is useful because there are no mutable variables (unless we are in the IO monad). However, what is the deal with Scala ? Is State Monad useful in a language where there are mutable variables ? In some sense all the State Monad allows is to use some local mutable variables within the Monad context. For example here: newtype Labeled anytype = Labeled (S -> (S, anytype)) instance Monad Labeled where return contents = Labeled (\st -> (st, contents))