How to implement a global counter using Monad?

前端 未结 4 1236
[愿得一人]
[愿得一人] 2020-12-30 07:09

I need a global counter, starting from 0, 1, 2, 3, ..... I kind of understand that this \"impure\" code should be separately implemented... I am just starting to understand

4条回答
  •  误落风尘
    2020-12-30 07:57

    What you can look into is state monad. This is a general purpose monad which can be used to manage state. In your case the counter is just a state that you want to maintain.

    http://www.haskell.org/haskellwiki/State_Monad

提交回复
热议问题