{-# LANGUAGE ScopedTypeVariables #-} module Rvarsample where { import qualified System.Random as Random; import Data.Random.Internal.Source(GetPrim(GetPrim)); import Control.Monad.State.Lazy(evalState,State); -- lazy state monad also works import qualified Data.Random as Randomfu; import Data.Random.Source.StdGen(getRandomPrimFromRandomGenState); import Data.Function((&)); -- at least one of the GetPrim type annotations is required rvarsample :: forall a gentype . (Random.RandomGen gentype) => gentype -> Randomfu.RVar a -> a; rvarsample gen r = (GetPrim getRandomPrimFromRandomGenState :: GetPrim (State gentype)) & (Randomfu.runRVar r :: GetPrim (State gentype) -> State gentype a) & ((\state -> evalState state gen) :: State gentype a -> a); }