#haskell - Sun 20 May 2007 between 12:02 and 12:09



Saizanproviding a seed
ivanm*nod*
which would require a do-block, right?
maukenothing requires a do block
ivanmif I want a random seed
do block / explicit monadic passing
Saizanyoou can have randomPermIO :: [a] -> IO [a]; randomPermIO list = do g <- newStdGen; return $ randomPerm g list
ivanmyeah
but then I'd need yet another function that would un monadise it
Saizanyou can't unmonadise IO
ivanmoh.....
but I need to...
SaizanIO is a one way monad
dcouttscdsmith: ByteString.readFile is strict, so it reads the whole file and closes it.
ivanmSaizan: but I need to perform more operations on the result :s
cdsmithdcoutts: Hmm... that's not what I'm seeing. (I'm actually using Data.Binary's decodeFile, but it says it uses ByteString)
dcouttscdsmith: ah, that's using a lazy BytString
Saizanivanm, just write your code needing a random seed, you'll eventually get one from your main function that must be in IO
dcouttscdsmith: there's Data.ByteString and Data.ByteString.Lazy
ivanmSaizan: I have a data structure that I need to shuffle in three different ways...
cdsmithdcoutts: Okay. So I should use Data.ByteString explicitly?
ivanmor are you saying to get main to pass through the random seed?
dcouttscdsmith: so with a lazy bytestring, it's lazy in the same way that ordinary readFile is lazy, it closes the file when it's read the whole input
Saizanivanm: exactly, remember that you can get two seeds from one by splitting
dcouttscdsmith: so the ideal way is to read all the stuff you're decoding with Data.Binary, then it'll have read the whole file.
ivanmsplitting?
cdsmithdcoutts: I thought I was doing that.
Saizan?type split
lambdabotforall g. (RandomGen g) => g -> (g, g)
ivanm> split (mkStdGen 42)
lambdabot(44 40692,1720602 2147483398)
ivanmmkStdGen 42
> mkStdGen 42
lambdabot43 1
ivanmok, how did it do that? :s
@src split
lambdabotSource not found. My mind is going. I can feel it.
cdsmith@paste
lambdabotHaskell pastebin: http://hpaste.org/new
ivanmheh

Page: 5 12 19 26 33 40 47 54 61 

IrcArchive