random tune
Ian Lynagh
igloo at earth.li
Fri Jul 17 11:33:24 EDT 2009
On Thu, Jul 09, 2009 at 11:42:20AM +0200, Laszlo Nagy wrote:
>
> I also run the hlint program
> against the random library and applied the recommendations. Here are
> the patches:
>
> http://sites.google.com/site/rizsotto/patches/random-hlintclean.darcs
Thanks for taking the time to look into this.
I'd be interested in other people's opinions on whether the hlint
recommendations are an improvement or not.
In my opinion there are a handful of things that are slightly less clear
for no real benefit:
createStdGen :: Integer -> StdGen
-createStdGen s = mkStdGen32 $ fromIntegral s
+createStdGen = mkStdGen32 . fromIntegral
randoms :: RandomGen g => g -> [a]
- randoms g = (\(x,g') -> x : randoms g') (random g)
+ randoms = (\(x,g') -> x : randoms g') . random
theStdGen :: IORef StdGen
-theStdGen = unsafePerformIO $ do
- rng <- mkStdRNG 0
- newIORef rng
+theStdGen = unsafePerformIO $ mkStdRNG 0 >>= newIORef
In fact, I would change randoms to:
randoms g = case random g of
(x,g') -> x : randoms g'
And the rest aren't really better or worse in my opinion, e.g.:
instance Random Int where
- randomR (a,b) g = randomIvalInteger (toInteger a, toInteger b) g
- random g = randomR (minBound,maxBound) g
+ randomR (a,b) = randomIvalInteger (toInteger a, toInteger b)
+ random = randomR (minBound,maxBound)
> http://sites.google.com/site/rizsotto/patches/random-time.darcs
Thanks; I'll take a look at adding time to GHC's corelibs, and then
apply this.
Thanks
Ian
More information about the Libraries
mailing list