Where is the data constructor for 'State'?

后端 未结 3 1052
无人共我
无人共我 2021-02-12 07:32

After reading a couple of tutorials on Haskell state monads I wanted to try them out myself. The tutorials I read claim that the Control.Monad.State provide the following defini

3条回答
  •  误落风尘
    2021-02-12 08:03

    A while ago the MTL switched from

    newtype State s a = State ...
    

    to

    type State s = StateT s Identity
    

    since otherwise we had to duplicate the logic for every monad and its transformer. Instead you can now use the state function

    state :: (s -> (a, s)) -> State s a
    

    Sadly, RWH and LYAH both are out of date in this respect :(

提交回复
热议问题