<div dir="ltr">And the one liner:<div><br></div><div>(rand 1 10) >>= return . (\v -> take v [1..10])<br><br><div class="gmail_quote">On Wed, Sep 24, 2008 at 5:10 PM, Lev Walkin <span dir="ltr"><<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 <- 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 <- 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>