<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>