The generic model for stateful computation (S -> S x R) provides a convenient mechanism of threading stateful computation results since the functor λR . S -> S x R is monadic. But what happens if we want to thread state itself? Well, the mapping λS. S -> S x R is not even functorial! But it turns out it can become so with a bit of trickery. This snippet demonstrates a way to lift, project or inject stateful computations into ambient state monads.
8 people like thisPosted: 6 years ago by Eirik Tsarpalis
This is 100% based on tomas petricek blog article. there has been some small additions in regards to adding Result type and handling Monoids for the Writer Part. go check the following blog article : http://tomasp.net/blog/2014/update-monads/ Comment appreciated + bear in mind that performance wise, the Monoid Combine operator, could be greatly improved and more.
3 people like thisPosted: 1 year ago by Fahd Abdeljallal