<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div>On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote:</div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><div> For one approach, check</div><div>out 'replicate' to make copies of something, and then 'sequence' to</div><div>run them and return a list.</div><div><br></div></blockquote><br></div><div>Thanks, I haven't found anything that explains 'sequence' well yet, but I'll keep looking.</div><div><br></div></div><div><div>On 24 Sep 2008, at 10:13 pm, John Van Enk wrote:</div><blockquote type="cite"><div dir="ltr">And the one liner:<div><br></div><div>(rand 1 10) >>= return . (\v -> take v [1..10])<br><br></div></div></blockquote><div><br></div><div>my last attempt before emailing was</div><div><br></div><div>(rand 1 10 ) >>= (\x -> take x [1..10])</div><div><br></div><div>So close! :)</div><div><br></div><div>I can see now, with all the examples, why the return is needed, but not why the composition operator is. Something for me to look into. Thanks for the input.</div><div><br></div><div><br></div><div><div>On 24 Sep 2008, at 10:25 pm, Henning Thielemann wrote:</div><blockquote type="cite"><blockquote type="cite"></blockquote><div><br></div><div>If you only need arbitrary numbers, not really random ones, you should stay away from IO:</div><div>  <a href="http://www.haskell.org/haskellwiki/Humor/Erlk%C3%B6nig">http://www.haskell.org/haskellwiki/Humor/Erlk%C3%B6nig</a></div><div>  <a href="http://www.haskell.org/haskellwiki/Haskell_programming_tips#Separate_IO_and_data_processing">http://www.haskell.org/haskellwiki/Haskell_programming_tips#Separate_IO_and_data_processing</a></div></blockquote></div><div><br></div><div>You're right, arbritary will be fine. It's relatively easy to get random numbers in other languages so I just started there, but while researching I had seen a few people lament the tying up of IO with rands, but I couldn't understand some of the other solutions presented. Thanks for the links, I'll give them a read.</div><div><br></div><div><br></div><br><blockquote type="cite"><div dir="ltr"><div><div class="gmail_quote">On Wed, Sep 24, 2008 at 5:10 PM, Lev Walkin <span dir="ltr">&lt;<a href="mailto:vlm@lionet.info">vlm@lionet.info</a>></span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">forgot return, of course:<div class="Ih2E3d"><br> <br> > myTake :: IO [Int]<br> > myTake = do<br> >     n &lt;- rand 1 10<br></div> >     return $ take n [1..10]<div class="Ih2E3d"><br> <br> <br> Lev Walkin wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Iain Barnett wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Hi,<br> <br> I have a function, that produces a random number between two given numbers<br> <br> rand :: Int -> Int -> IO Int<br> rand low high = getStdRandom (randomR (low,high))<br> <br> <br> (Naively) I'd like to write something like<br> <br> take (rand 1 10 ) [1..10]<br> <br> and see [1,2,3,4] ... or anything but nasty type-error messages.<br> </blockquote> <br> myTake :: IO [Int]<br> myTake = do<br>    n &lt;- rand 1 10<br>    take n [1..10]<br> <br> or<br> <br> myTake = rand 1 10 >>= \n -> take n [1..10]<br> <br> or<br> <br> myTake = rand 1 10 >>= flip take [1..10]<br> <br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> I'm reading about 6 tutorials on monads simultaneously but still can't crack this simple task, and won't pain you with all the permutations of code I've already tried. It's a lot, and it ain't pretty.<br> <br> Would anyone be able to break away from C/C++ vs Haskell to help? Just a point in the right direction or a good doc to read, anything that helps will be much appreciated.<br> </blockquote> <br> <br> Monad enlightenment happens after 7'th monad tutorial. Verified by me<br> and a few of my friends.<br> <br> </blockquote> <br></div><div><div></div><div class="Wj3C7c"> _______________________________________________<br> Haskell-Cafe mailing list<br> <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br> </div></div></blockquote></div><br><br clear="all"><br>-- <br>/jve<br> </div></div></blockquote></div><br></body></html>