Improving Random
Alexey Khudyakov
alexey.skladnoy at gmail.com
Wed May 27 09:59:17 UTC 2020
On 27.05.2020 05:13, Carter Schonwald wrote:
> Zemyla!
>
> Yeah, absolutely agree that their pr has the wrong shape for monad
> random, which is why I’m confused by dominics pronouncement :), though
> its a great contrib.
>
> It should be (ignoring m being applicative vs monad)
> (For context, their design is roughly ... MonadRandom m s g | m,g -> s
> ? I’m typing on a phone so i might be restating it wrong ... :) )
>
>
> The *better* choice is
> Class PRNG g => MonadRandom m g | m-> g where ...
>
> And then their example instance should be something like
>
> Newtype MWCT m a = ... newtype wrapper around StateT m a threading an
> MWC indexed by the state token of the underlying PrimMonad
> (Or newtype MWCT s m a = .... stateT thing)
>
> Instance (PrimMonad m) => MonadRandom (MWCT m) (MCWGen (PrimState m))
> where ...
>
> Or something along those lines. It absolutely shouldn’t be in the style
> of being on any PrimMonad, but part of a stack that provides that instance.
>
One couldn't use StateT to thread state token for two reasont. First
StateT from transformer since it allows to thread values of kind * and
IO's state token is #.
State transformer threading state token on top of some other monad
_will_ cause problems if it's placed on top of list monad causing
unwanted buffer sharing and possibly loss of referential transparency
> This is ignoring the freeze/thaw stuff which really is just “record and
> restore RNG state”, and i think is an artifact of ther design choice in
> their PR. Which has a lot of great stuff I’m reviewing and poking at.
>
Frozen/thaw (or immutable/mutable) distinction is inevitable once one
starts working with in place mutation. In order to get snapshot of PRNG
state at some particular point it have to be copied.
More information about the Libraries
mailing list