I need to wrap my head around the state monad in haskell and I have some problems with that. The task is to implement a function countConcat which concatenates string with the state monad and a function extractCC which gets the result of this function.
So extractCC ((return 0) >>= countConcat "a" >>= countConcat "b" >>= countConcat "c")
would yield (3,"abc")
As far as I understand countConcat would be kind of a manipulator function and extractCC should contain some kind of runState, right?
Any tipps or ressources getting me into the right direction are highly appreciated. (I´ve been through the wiki and the learnyouahaskell section, but still feeling quite stupid with this)
String -> (Int, String) -> (Int, String)
. Then look at State explanation again to see how that function maps to the monad. Also the initial state would be(0, "")
(in the firstreturn
). – Cat Plus Plus