[Haskell-cafe] How to write such a code elegantly ?

z_axis z_axis at 163.com
Mon Jan 10 01:44:26 CET 2011


betterStdGen :: IO StdGen
betterStdGen = alloca $ \p -> do
   h <- openBinaryFile "/dev/urandom" ReadMode
   hGetBuf h p $ sizeOf (undefined :: Int)
   hClose h
   mkStdGen <$> peek p

picoSec :: IO Integer
picoSec = do
    t <- ctPicosec `liftM` (getClockTime >>= toCalendarTime)
    return t

The pseudo-code is :

if doesFileExist "/dev/urandom" 
    then myGen = betterStdGen
    else myGen = (mkStdGen . fromTnteger) <$> picoSec

How to write these pseudo-code elegantly ?

Sincerely!

-----
e^(π.i) + 1 = 0
-- 
View this message in context: http://haskell.1045720.n5.nabble.com/How-to-write-such-a-code-elegantly-tp3334329p3334329.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list