<div dir="ltr">Hi,<br><br>The following piece of code runs just fine, if I say:<br><br><span style="font-family: courier new,monospace;">instance Random RGB where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; random&nbsp; = color</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; randomR = colorR</span><br style="font-family: courier new,monospace;">
<br>instead of:<br><br><span style="font-family: courier new,monospace;">instance Random RGB where</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp; random&nbsp; = color2</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp; randomR = colorR<br><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">When I use </span>random&nbsp; = color2</span><span style="font-family: courier new,monospace;"><span style="font-family: arial,helvetica,sans-serif;"> I encounter a stack space overflow:<br>
<br><span style="font-family: courier new,monospace;">cetin@linux-d312:~/lab/test/colors&gt; ./var2 +RTS -K30000000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Stack space overflow: current size 30000000 bytes.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Use `+RTS -Ksize&#39; to increase it.</span><br style="font-family: arial,helvetica,sans-serif;"></span></span>

<br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">I think I</span>&#39;m doing something wrong with the definition of colorR.<br><br>Can anyone explain me what&#39;s wrong?<br>
<br><span style="font-family: courier new,monospace;">import GHC.Word</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import Data.Word</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">import System.Random</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import System.Random.Mersenne.Pure64</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">type RGB = (Int,Int,Int)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">instance Bounded RGB where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; minBound = minRGB</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; maxBound = maxRGB</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">minRGB = (0&nbsp; ,0&nbsp; ,0&nbsp; )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">maxRGB = (255,255,255)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance Random RGB where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; random&nbsp; = color2</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; randomR = colorR</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">color2 :: RandomGen g $B"M(B g $B"*(B (RGB,g)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">color2 = colorR (minRGB,maxRGB)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">color :: RandomGen g $B"M(B g $B"*(B (RGB,g)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">color s0 = ((r,g,b),s3)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; (r,s1) = q s0</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; (g,s2) = q s1</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; (b,s3) = q s2</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; q = randomR (0,255)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace; color: rgb(255, 0, 0);">colorR :: RandomGen g $B"M(B (RGB,RGB) $B"*(B g $B"*(B (RGB,g)</span><br style="font-family: courier new,monospace; color: rgb(255, 0, 0);">
<span style="font-family: courier new,monospace; color: rgb(255, 0, 0);">colorR ((a,b,c),(x,y,z)) s0 = ((r,g,b),s3)</span><br style="font-family: courier new,monospace; color: rgb(255, 0, 0);"><span style="font-family: courier new,monospace; color: rgb(255, 0, 0);">&nbsp; where</span><br style="font-family: courier new,monospace; color: rgb(255, 0, 0);">
<span style="font-family: courier new,monospace; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp; (r,s1) = q (a,x) s0</span><br style="font-family: courier new,monospace; color: rgb(255, 0, 0);"><span style="font-family: courier new,monospace; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp; (g,s2) = q (b,y) s1</span><br style="font-family: courier new,monospace; color: rgb(255, 0, 0);">
<span style="font-family: courier new,monospace; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp; (b,s3) = q (c,z) s2</span><br style="font-family: courier new,monospace; color: rgb(255, 0, 0);"><span style="font-family: courier new,monospace; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp; q = randomR</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">main :: IO ()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">main = do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; mt $B"+(B newPureMT</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; let cs = randoms mt :: [RGB]</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; print cs</span><br><br>------------------------------------------<br><br>This one also just works fine:<br><br><span style="font-family: courier new,monospace;">import Data.Word</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">import System.Random.Mersenne</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">type RGB = (Word8,Word8,Word8)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance MTRandom RGB where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; random m = do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; r $B"+(B random m :: IO Word8</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; g $B"+(B random m :: IO Word8</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; b $B"+(B random m :: IO Word8</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; return (r,g,b)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">main :: IO ()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">main = do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; g&nbsp; $B"+(B newMTGen Nothing</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; cs $B"+(B randoms g :: IO [RGB]</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; print cs<br><font face="arial,helvetica,sans-serif"><br>but I really need the range constraints colorR might provide me and would greatly appreciate any help to understand/solve the issue.<br>
<br>Best Regards,<br>Cetin<br><br>P/s:<br><span style="font-family: courier new,monospace;">uname -a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Linux linux-d312 2.6.25.16-0.1-default #1 SMP 2008-08-21 00:34:25 +0200 x86_64 x86_64 x86_64 GNU/Linux</span><br>
</font></span></div>