<div><div dir="auto">You want to use a stateT esque monad that does a split within the bind. Quickcheck should have an example of this. </div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 17, 2020 at 2:47 AM Dannyu NDos <<a href="mailto:ndospark320@gmail.com">ndospark320@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Though it is reasonable to make utilities monadic, they lack a crucial property: <b>laziness</b>.</div><div><br></div><div>I have the following datatype:</div><div><br></div><div>newtype ArbReal = ArbReal (Word -> Integer)</div><div><br></div><div>This represents arbitrary real numbers by being able to compute arbitrary decimal places after the decimal point. For example, to compute pi, let f be the function passed to constructor ArbReal. Then f 0 = 3, f 1 = 31, f 2 = 314, and so on.</div><div><br></div><div>I can implement instance Random ArbReal:</div><div><br></div><div>instance Random ArbReal where<br>    random g = let<br>        (h, i) = split g<br>        d:digits = randomRs (0 :: Word, 9) h<br>        getNum [] = 0<br>        getNum (d:ds) = toInteger d + 10 * getNum ds<br>        takeDigits n = getNum (reverse (take n digits)) + toInteger (fromEnum (d >= 5))<br>        in (ArbReal (takeDigits . fromIntegral), i)<br>    randomR (lo, hi) g = let<br>        (x, h) = random g<br>        in (lo + x * (hi - lo), h)</div><div><br></div><div>But I see no way to implement an instance of UniformRange ArbReal, for it relies on randomRs, which is lazy. Neither ST nor IO is able to contain such laziness.<br></div></div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div></div>