Iain Barnett iainspeed at gmail.com
Wed Sep 24 17:44:52 EDT 2008

```On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote:
>  For one approach, check
> out 'replicate' to make copies of something, and then 'sequence' to
> run them and return a list.
>

Thanks, I haven't found anything that explains 'sequence' well yet,
but I'll keep looking.

On 24 Sep 2008, at 10:13 pm, John Van Enk wrote:
> And the one liner:
>
> (rand 1 10) >>= return . (\v -> take v [1..10])
>

my last attempt before emailing was

(rand 1 10 ) >>= (\x -> take x [1..10])

So close! :)

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.

On 24 Sep 2008, at 10:25 pm, Henning Thielemann wrote:
>
> If you only need arbitrary numbers, not really random ones, you
> should stay away from IO:

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

> On Wed, Sep 24, 2008 at 5:10 PM, Lev Walkin <vlm at lionet.info> wrote:
> forgot return, of course:
>
>
> > myTake :: IO [Int]
> > myTake = do
> >     n <- rand 1 10
> >     return \$ take n [1..10]
>
>
>
> Lev Walkin wrote:
> Iain Barnett wrote:
> Hi,
>
> I have a function, that produces a random number between two given
> numbers
>
> rand :: Int -> Int -> IO Int
> rand low high = getStdRandom (randomR (low,high))
>
>
> (Naively) I'd like to write something like
>
> take (rand 1 10 ) [1..10]
>
> and see [1,2,3,4] ... or anything but nasty type-error messages.
>
> myTake :: IO [Int]
> myTake = do
>    n <- rand 1 10
>    take n [1..10]
>
> or
>
> myTake = rand 1 10 >>= \n -> take n [1..10]
>
> or
>
> myTake = rand 1 10 >>= flip take [1..10]
>
> 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.
>
> 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.
>
>
> and a few of my friends.
>
>
> _______________________________________________