Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: pattern match vs. pure function (Bastian Erdn??)
2. Creating lists of random numbers (Tom Hobbs)
3. Re: Creating lists of random numbers (Daniel Fischer)
4. Re: Creating lists of random numbers (Johan Tibell)
5. Yampa (Luca Ciciriello)
----------------------------------------------------------------------
Message: 1
Date: Thu, 21 Oct 2010 13:29:07 +0200
From: Bastian Erdn?? <[email protected]>
Subject: Re: [Haskell-beginners] pattern match vs. pure function
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Oct 20, 2010, at 15:14, Brent Yorgey wrote:
> But honestly, I don't think this is the sort of thing you should
> really be worrying about. Write your programs in the most natural,
> elegant way you can think of, and trust that the compiler will try
> very hard to turn it into efficient code. If it later turns out to be
> too slow and profiling seems to indicate there's room for improvement,
> THEN you can start worrying about this sort of thing.
I buy that.
Cheers,
Bastian
------------------------------
Message: 2
Date: Thu, 21 Oct 2010 13:58:45 +0100
From: Tom Hobbs <[email protected]>
Subject: [Haskell-beginners] Creating lists of random numbers
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi all,
I'm trying to create a list of random integers (either 0s or 1s).
I've got one way to work, but I'm trying to use replicate to replace
this implementation but it's not going well. Can anyone help, please?
Here's the version I want to replace;
ugly :: Int -> [Int]
ugly 0 = []
ugly s = ugly (s-1) ++ [ran]
where
ran = unsafePerformIO (randomRIO (0,1)) :: Int
This one works as expected.
Here's the broken version;
broken :: Int -> [Int]
broken s = replicate s ran
where
ran = unsafePerformIO (randomRIO (0,1)) :: Int
The problem with broken is that "ran" seems to be evaluated once and
then replicated, so my list contains the same random number s times.
I'd like it to be re-evaluated with each replication.
Also, I've heard of the dangers of using unsafePerformIO. Can anyone
suggest a different way to generate random numbers?
(Finally, a question that doesn't involve serialisation!)
Cheers,
Tom
------------------------------
Message: 3
Date: Thu, 21 Oct 2010 15:21:14 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Creating lists of random numbers
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Thursday 21 October 2010 14:58:45, Tom Hobbs wrote:
> Hi all,
>
> I'm trying to create a list of random integers (either 0s or 1s).
> I've got one way to work, but I'm trying to use replicate to replace
> this implementation but it's not going well. Can anyone help, please?
>
> Here's the version I want to replace;
>
> ugly :: Int -> [Int]
> ugly 0 = []
> ugly s = ugly (s-1) ++ [ran]
> where
> ran = unsafePerformIO (randomRIO (0,1)) :: Int
>
> This one works as expected.
>
> Here's the broken version;
>
> broken :: Int -> [Int]
> broken s = replicate s ran
> where
> ran = unsafePerformIO (randomRIO (0,1)) :: Int
>
> The problem with broken is that "ran" seems to be evaluated once and
> then replicated, so my list contains the same random number s times.
Right, ran is just a plain Int, it doesn't need to be evaluated more than
once.
You could try
stillUgly :: Int -> [Int]
stillUgly n = replicate n (f ())
where
{-# NOINLINE f #-}
f () = unsafePerformIO (randomRIO (0,1))
but you shouldn't.
> I'd like it to be re-evaluated with each replication.
>
> Also, I've heard of the dangers of using unsafePerformIO. Can anyone
> suggest a different way to generate random numbers?
A) pass the generator explicitly
ranList :: StdGen -> Int -> [Int]
ranList sg n = take n $ randomRs (0,1) sg
and then, if you must,
B)
bearable :: Int -> [Int]
bearable n = unsafePerformIO $ do
sg <- getStdGen
return $ ranList sg n
but really, pass the generator. If that's too inconvenient, use MonadRandom
(I've forgotten the name of the package, search hackage).
>
> (Finally, a question that doesn't involve serialisation!)
>
> Cheers,
>
> Tom
------------------------------
Message: 4
Date: Thu, 21 Oct 2010 15:34:20 +0200
From: Johan Tibell <[email protected]>
Subject: Re: [Haskell-beginners] Creating lists of random numbers
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi Tom,
What Daniel said. If you need a faster random number generator use:
http://hackage.haskell.org/package/mwc-random
Use the 'create' function to create an initial seed and then call
'uniform' repeatedly to create new random Bools.
Johan
------------------------------
Message: 5
Date: Thu, 21 Oct 2010 18:21:31 +0200
From: Luca Ciciriello <[email protected]>
Subject: [Haskell-beginners] Yampa
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi All.
I've started to use Haskell regularly in my job in industry. My job is to
develop software for UAVs (Unmanned Aerial Vehicle). In particular I want to
use Yampa to handle the sensor gimbal of the vehicle.
Is there someone with some kind of experience in the industrial use of Yampa?
Where can I find (if exists...) documentation to guide me in using Yampa in
the real world?
Thanks for any answer.
Luca.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 28, Issue 34
*****************************************