This file is indexed.

/usr/share/doc/libghc-random-fu-doc/html/Data-Random-RVar.html is in libghc-random-fu-doc 0.2.7.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Data.Random.RVar</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script src="file:///usr/share/javascript/mathjax/MathJax.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Data-Random-RVar.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Data-Random-RVar.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">random-fu-0.2.7.0: Random number generation</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell98</td></tr></table><p class="caption">Data.Random.RVar</p></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">type</span> <a href="#t:RVar">RVar</a> = <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor-Identity.html#t:Identity">Identity</a></li><li class="src short"><a href="#v:runRVar">runRVar</a> :: <a href="Data-Random.html#t:RandomSource">RandomSource</a> m s =&gt; <a href="Data-Random-RVar.html#t:RVar">RVar</a> a -&gt; s -&gt; m a</li><li class="src short"><span class="keyword">data</span> <a href="#t:RVarT">RVarT</a> m a :: (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a></li><li class="src short"><a href="#v:runRVarT">runRVarT</a> :: (<a href="Data-Random-Lift.html#t:Lift">Lift</a> n m, <a href="Data-Random.html#t:RandomSource">RandomSource</a> m s) =&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; s -&gt; m a</li><li class="src short"><a href="#v:runRVarTWith">runRVarTWith</a> :: <a href="Data-Random.html#t:RandomSource">RandomSource</a> m s =&gt; (<span class="keyword">forall</span> t. n t -&gt; m t) -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; s -&gt; m a</li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><span class="keyword">type</span> <a id="t:RVar" class="def">RVar</a> = <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor-Identity.html#t:Identity">Identity</a> <a href="#t:RVar" class="selflink">#</a></p><div class="doc"><p>An opaque type modeling a &quot;random variable&quot; - a value 
 which depends on the outcome of some random event.  <code><a href="Data-Random-RVar.html#t:RVar">RVar</a></code>s 
 can be conveniently defined by an imperative-looking style:</p><pre>normalPair =  do
    u &lt;- stdUniform
    t &lt;- stdUniform
    let r = sqrt (-2 * log u)
        theta = (2 * pi) * t
        
        x = r * cos theta
        y = r * sin theta
    return (x,y)</pre><p>OR by a more applicative style:</p><pre>logNormal = exp &lt;$&gt; stdNormal</pre><p>Once defined (in any style), there are several ways to sample <code><a href="Data-Random-RVar.html#t:RVar">RVar</a></code>s:</p><ul><li>In a monad, using a <code><a href="Data-Random.html#t:RandomSource">RandomSource</a></code>:</li></ul><pre>runRVar (uniform 1 100) DevRandom :: IO Int</pre><ul><li>In a monad, using a <code><a href="Data-Random.html#t:MonadRandom">MonadRandom</a></code> instance:</li></ul><pre>sampleRVar (uniform 1 100) :: State PureMT Int</pre><ul><li>As a pure function transforming a functional RNG:</li></ul><pre>sampleState (uniform 1 100) :: StdGen -&gt; (Int, StdGen)</pre><p>(where <code>sampleState = runState . sampleRVar</code>)</p></div></div><div class="top"><p class="src"><a id="v:runRVar" class="def">runRVar</a> :: <a href="Data-Random.html#t:RandomSource">RandomSource</a> m s =&gt; <a href="Data-Random-RVar.html#t:RVar">RVar</a> a -&gt; s -&gt; m a <a href="#v:runRVar" class="selflink">#</a></p><div class="doc"><p>&quot;Run&quot; an <code><a href="Data-Random-RVar.html#t:RVar">RVar</a></code> - samples the random variable from the provided
 source of entropy.</p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a id="t:RVarT" class="def">RVarT</a> m a :: (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a>) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Kind.html#t:-42-">*</a> <a href="#t:RVarT" class="selflink">#</a></p><div class="doc"><p>A random variable with access to operations in an underlying monad.  Useful
 examples include any form of state for implementing random processes with hysteresis,
 or writer monads for implementing tracing of complicated algorithms.</p><p>For example, a simple random walk can be implemented as an <code><a href="Data-Random-RVar.html#t:RVarT">RVarT</a></code> <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a></code> value:</p><pre>rwalkIO :: IO (RVarT IO Double)
rwalkIO d = do
    lastVal &lt;- newIORef 0
    
    let x = do
            prev    &lt;- lift (readIORef lastVal)
            change  &lt;- rvarT StdNormal
            
            let new = prev + change
            lift (writeIORef lastVal new)
            return new
        
    return x</pre><p>To run the random walk it must first be initialized, after which it can be sampled as usual:</p><pre>do
    rw &lt;- rwalkIO
    x &lt;- sampleRVarT rw
    y &lt;- sampleRVarT rw
    ...</pre><p>The same random-walk process as above can be implemented using MTL types
 as follows (using <code>import Control.Monad.Trans as MTL</code>):</p><pre>rwalkState :: RVarT (State Double) Double
rwalkState = do
    prev &lt;- MTL.lift get
    change  &lt;- rvarT StdNormal
    
    let new = prev + change
    MTL.lift (put new)
    return new</pre><p>Invocation is straightforward (although a bit noisy) if you're used to MTL:</p><pre>rwalk :: Int -&gt; Double -&gt; StdGen -&gt; ([Double], StdGen)
rwalk count start gen = 
    flip evalState start .
        flip runStateT gen .
            sampleRVarTWith MTL.lift $
                replicateM count rwalkState</pre></div><div class="subs instances"><p id="control.i:RVarT" class="caption collapser" onclick="toggleSection('i:RVarT')">Instances</p><div id="section.i:RVarT" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:RVarT:MonadTrans:1" class="instance expander" onclick="toggleSection('i:id:RVarT:MonadTrans:1')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/transformers-0.5.2.0/Control-Monad-Trans-Class.html#t:MonadTrans">MonadTrans</a> <a href="Data-Random-RVar.html#t:RVarT">RVarT</a></span></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div id="section.i:id:RVarT:MonadTrans:1" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:lift">lift</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> m =&gt; m a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> m a <a href="#v:lift" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:RVarT:MonadPrompt:2" class="instance expander" onclick="toggleSection('i:id:RVarT:MonadPrompt:2')"></span> MonadPrompt <a href="file:///usr/share/doc/libghc-random-source-doc/html/Data-Random-Internal-Source.html#t:Prim">Prim</a> (<a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n)</span></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div id="section.i:id:RVarT:MonadPrompt:2" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:prompt">prompt</a> :: <a href="file:///usr/share/doc/libghc-random-source-doc/html/Data-Random-Internal-Source.html#t:Prim">Prim</a> a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a</p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:RVarT:Monad:3" class="instance expander" onclick="toggleSection('i:id:RVarT:Monad:3')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad.html#t:Monad">Monad</a> (<a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n)</span></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div id="section.i:id:RVarT:Monad:3" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:-62--62--61-">(&gt;&gt;=)</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; (a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b) -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b <a href="#v:-62--62--61-" class="selflink">#</a></p><p class="src"><a href="#v:-62--62-">(&gt;&gt;)</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b <a href="#v:-62--62-" class="selflink">#</a></p><p class="src"><a href="#v:return">return</a> :: a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a <a href="#v:return" class="selflink">#</a></p><p class="src"><a href="#v:fail">fail</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-String.html#t:String">String</a> -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a <a href="#v:fail" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:RVarT:Functor:4" class="instance expander" onclick="toggleSection('i:id:RVarT:Functor:4')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor.html#t:Functor">Functor</a> (<a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n)</span></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div id="section.i:id:RVarT:Functor:4" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:fmap">fmap</a> :: (a -&gt; b) -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b <a href="#v:fmap" class="selflink">#</a></p><p class="src"><a href="#v:-60--36-">(&lt;$)</a> :: a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a <a href="#v:-60--36-" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:RVarT:Applicative:5" class="instance expander" onclick="toggleSection('i:id:RVarT:Applicative:5')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Applicative.html#t:Applicative">Applicative</a> (<a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n)</span></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div id="section.i:id:RVarT:Applicative:5" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:pure">pure</a> :: a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a <a href="#v:pure" class="selflink">#</a></p><p class="src"><a href="#v:-60--42--62-">(&lt;*&gt;)</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n (a -&gt; b) -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b <a href="#v:-60--42--62-" class="selflink">#</a></p><p class="src"><a href="#v:-42--62-">(*&gt;)</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b <a href="#v:-42--62-" class="selflink">#</a></p><p class="src"><a href="#v:-60--42-">(&lt;*)</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n b -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a <a href="#v:-60--42-" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:RVarT:MonadIO:6" class="instance expander" onclick="toggleSection('i:id:RVarT:MonadIO:6')"></span> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-IO-Class.html#t:MonadIO">MonadIO</a> m =&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Monad-IO-Class.html#t:MonadIO">MonadIO</a> (<a href="Data-Random-RVar.html#t:RVarT">RVarT</a> m)</span></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div id="section.i:id:RVarT:MonadIO:6" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:liftIO">liftIO</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> m a <a href="#v:liftIO" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:RVarT:MonadRandom:7" class="instance expander" onclick="toggleSection('i:id:RVarT:MonadRandom:7')"></span> <a href="Data-Random.html#t:MonadRandom">MonadRandom</a> (<a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n)</span></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div id="section.i:id:RVarT:MonadRandom:7" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:getRandomPrim">getRandomPrim</a> :: <a href="file:///usr/share/doc/libghc-random-source-doc/html/Data-Random-Internal-Source.html#t:Prim">Prim</a> t -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n t <a href="#v:getRandomPrim" class="selflink">#</a></p><p class="src"><a href="#v:getRandomWord8">getRandomWord8</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Word.html#t:Word8">Word8</a> <a href="#v:getRandomWord8" class="selflink">#</a></p><p class="src"><a href="#v:getRandomWord16">getRandomWord16</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Word.html#t:Word16">Word16</a> <a href="#v:getRandomWord16" class="selflink">#</a></p><p class="src"><a href="#v:getRandomWord32">getRandomWord32</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Word.html#t:Word32">Word32</a> <a href="#v:getRandomWord32" class="selflink">#</a></p><p class="src"><a href="#v:getRandomWord64">getRandomWord64</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Word.html#t:Word64">Word64</a> <a href="#v:getRandomWord64" class="selflink">#</a></p><p class="src"><a href="#v:getRandomDouble">getRandomDouble</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Prelude.html#t:Double">Double</a> <a href="#v:getRandomDouble" class="selflink">#</a></p><p class="src"><a href="#v:getRandomNByteInteger">getRandomNByteInteger</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Int.html#t:Int">Int</a> -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Prelude.html#t:Integer">Integer</a> <a href="#v:getRandomNByteInteger" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:RVarT:Sampleable:8" class="instance expander" onclick="toggleSection('i:id:RVarT:Sampleable:8')"></span> <a href="Data-Random-Lift.html#t:Lift">Lift</a> m n =&gt; <a href="Data-Random-Sample.html#t:Sampleable">Sampleable</a> (<a href="Data-Random-RVar.html#t:RVarT">RVarT</a> m) n t</span> <a href="src/Data-Random-Sample.html#line-28" class="link">Source</a> <a href="#t:Sampleable" class="selflink">#</a></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div id="section.i:id:RVarT:Sampleable:8" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:sampleFrom">sampleFrom</a> :: <a href="Data-Random.html#t:RandomSource">RandomSource</a> n s =&gt; s -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> m t -&gt; n t <a href="src/Data-Random-Sample.html#sampleFrom" class="link">Source</a> <a href="#v:sampleFrom" class="selflink">#</a></p></div></div></td></tr><tr><td class="src clearfix"><span class="inst-left"><span id="control.i:id:RVarT:Lift:9" class="instance expander" onclick="toggleSection('i:id:RVarT:Lift:9')"></span> <a href="Data-Random-Lift.html#t:Lift">Lift</a> (<a href="Data-Random-RVar.html#t:RVarT">RVarT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor-Identity.html#t:Identity">Identity</a>) (<a href="Data-Random-RVar.html#t:RVarT">RVarT</a> m)</span> <a href="src/Data-Random-Lift.html#line-43" class="link">Source</a> <a href="#t:Lift" class="selflink">#</a></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><div id="section.i:id:RVarT:Lift:9" class="inst-details hide"><div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:lift">lift</a> :: <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Functor-Identity.html#t:Identity">Identity</a> a -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> m a <a href="src/Data-Random-Lift.html#lift" class="link">Source</a> <a href="#v:lift" class="selflink">#</a></p></div></div></td></tr></table></div></div></div><div class="top"><p class="src"><a id="v:runRVarT" class="def">runRVarT</a> :: (<a href="Data-Random-Lift.html#t:Lift">Lift</a> n m, <a href="Data-Random.html#t:RandomSource">RandomSource</a> m s) =&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; s -&gt; m a <a href="src/Data-Random-RVar.html#runRVarT" class="link">Source</a> <a href="#v:runRVarT" class="selflink">#</a></p><div class="doc"><p>Like <code><a href="Data-Random-RVar.html#v:runRVarTWith">runRVarTWith</a></code>, but using an implicit lifting (provided by the 
 <code><a href="Data-Random-Lift.html#t:Lift">Lift</a></code> class)</p></div></div><div class="top"><p class="src"><a id="v:runRVarTWith" class="def">runRVarTWith</a> :: <a href="Data-Random.html#t:RandomSource">RandomSource</a> m s =&gt; (<span class="keyword">forall</span> t. n t -&gt; m t) -&gt; <a href="Data-Random-RVar.html#t:RVarT">RVarT</a> n a -&gt; s -&gt; m a <a href="#v:runRVarTWith" class="selflink">#</a></p><div class="doc"><p>&quot;Runs&quot; an <code><a href="Data-Random-RVar.html#t:RVarT">RVarT</a></code>, sampling the random variable it defines.</p><p>The first argument lifts the base monad into the sampling monad.  This 
 operation must obey the &quot;monad transformer&quot; laws:</p><pre>lift . return = return
lift (x &gt;&gt;= f) = (lift x) &gt;&gt;= (lift . f)</pre><p>One example of a useful non-standard lifting would be one that takes
 <code>State s</code> to another monad with a different state representation (such as
 <code>IO</code> with the state mapped to an <code>IORef</code>):</p><pre>embedState :: (Monad m) =&gt; m s -&gt; (s -&gt; m ()) -&gt; State s a -&gt; m a
embedState get put = \m -&gt; do
    s &lt;- get
    (res,s) &lt;- return (runState m s)
    put s
    return res</pre><p>The ability to lift is very important - without it, every <code><a href="Data-Random-RVar.html#t:RVar">RVar</a></code> would have
 to either be given access to the full capability of the monad in which it
 will eventually be sampled (which, incidentally, would also have to be 
 monomorphic so you couldn't sample one <code><a href="Data-Random-RVar.html#t:RVar">RVar</a></code> in more than one monad)
 or functions manipulating <code><a href="Data-Random-RVar.html#t:RVar">RVar</a></code>s would have to use higher-ranked 
 types to enforce the same kind of isolation and polymorphism.</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.17.2</p></div></body></html>