Where is the data constructor for 'State'?

后端 未结 3 529
南笙
南笙 2021-02-12 07:15

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 07:58

    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 :(

提交回复
热议问题