How can I combine the monad of monks and the state monad (or equivalent)?

I am building a code to get an understanding, actually a Solitaire solver. I have a simple brute force implementation that uses the state monad, in fact, just to prove that I can use it (it only contains a count of each move). But now I want to use Unboxed Mutable arrays to record visited boards and thereby speed up the evaluation of paths when I get to the position of the board that has already been visited in a different way. It seems that the ST monad does not allow me to enter an implicit state, but I have to use ST (or IO) to access the Mutable array. Therefore, it seems to me that I should combine two Monads - State to stream state (actually including a Mutable array), and the other (ST) to get Mutable array functions.

  • Is it correct?
  • And if so, is there a better alternative than a combination of data (DataGrid.ST/Control.Monad.ST/Control.Monad.ST and mtl?
  • If I go along this route, does it matter which order I collect ST and State?
  • Should I consider moving my own single Monad based on either ST or ST to avoid using monad transformers?
+3
source share
2 answers

100%, ST- - . , ... " ", , STRef. , .

ST IO, . ( STM, , .)

, , , . - List Monad Error, , . , .

... , ST. , ST .

, , , . , STRef.

+5

ST , , State monad : ! ; , , , . , ST . StateT , , ST , , , .. , . , StateT .

, ReaderT. , , .

+3

All Articles