<div dir="ltr">And the one liner:<div><br></div><div>(rand 1 10) &gt;&gt;= return . (\v -&gt; take v [1..10])<br><br><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>&gt;</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>
&gt; myTake :: IO [Int]<br>
&gt; myTake = do<br>
&gt; &nbsp; &nbsp; n &lt;- rand 1 10<br></div>
&gt; &nbsp; &nbsp; 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 -&gt; Int -&gt; IO Int<br>
rand low high = getStdRandom (randomR (low,high))<br>
<br>
<br>
(Naively) I&#39;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>
 &nbsp; &nbsp;n &lt;- rand 1 10<br>
 &nbsp; &nbsp;take n [1..10]<br>
<br>
or<br>
<br>
myTake = rand 1 10 &gt;&gt;= \n -&gt; take n [1..10]<br>
<br>
or<br>
<br>
myTake = rand 1 10 &gt;&gt;= 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&#39;m reading about 6 tutorials on monads simultaneously but still can&#39;t crack this simple task, and won&#39;t pain you with all the permutations of code I&#39;ve already tried. It&#39;s a lot, and it ain&#39;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&#39;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>