[Haskell-cafe] Help with triple stack monad

Christopher Howard ch.howard at zoho.com
Tue Jun 21 06:12:54 UTC 2016

Hi, I was expanding on my earlier learning, to try a triple monad stack:

{-# LANGUAGE GeneralizedNewtypeDeriving #-}


import System.Random
import Control.Monad.Random
import Control.Monad.State.Lazy
import Control.Monad.Reader

newtype ReaderStateRandom r s g a = RSR {
  rSR :: ReaderT r (StateT s (Rand g)) a
  } deriving (Monad, MonadReader r, MonadState s)

However, it seems that I must implement MonadRandom myself, as there is
no instance for this sort of arrangement already. Probably this is
trivial, but I'm having trouble wrapping my mind around how to do it.
Would anybody perhaps assist me in implementing one function, to help
guide me in the correct direction?

instance MonadRandom (ReaderStateRandom r s g) where

  getRandom = ...?

To protect my privacy, please use PGP encryption. It's free and easy
to use! My public key ID is 0x340EA95A (pgp.mit.edu).

More information about the Haskell-Cafe mailing list