#apache #archlinux #asterisk #centos #debian #gentoo #haskell #kde #kubuntu #lisp #math #mysql #perl #python #ruby-lang #rubyonrails #suse #ubuntu #vim #wikipedia 0 1 2 3 4 5 6 7 8 9 
Top Prev 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 Next

#haskell

<sorear> IRC limitations encourage obfuscated one liners
<darrint> Ok, I'm about to pull hairs out. Docs say: "The ghc-pkg tool knows where this file should be located, and will create it if it doesn't exist" But really, it just complains about it not existing and fails.
<sorear> that code I sent was a full lagged fibbonacci PRNG
<nmessenger> @type fmap (randomRs (1,10)) newStdGen
<lambdabot> forall t. (Num t, Random t) => IO [t]
<sorear> darrint: mkdir -p?
<nmessenger> ^^ that'll give you an IO stream of random Ints or whatever
<darrint> Been there, did that.
<darrint> It wants the file to exist and be of proper syntax.
<siti> is there a way to make timers in haskell without using glib/gtk2hs bindings?
<darrint> I did both just mkdir -p and touched the file.
<sorear> siti: threadDelay
<iron32> > randomRs(1,10)( mkStdGen 8 )
<lambdabot> [6,6,1,10,10,10,10,10,9,4,3,3,4,1,7,2,3,7,10,9,2,8,3,10,8,5,7,5,4,7,2,5,3,3,...
<nmessenger> helpful commands: @help @run @type @src @docs @source @pl @undo, also LB listens to /msgs if you want to play
<iron32> > take 8 ( randomRs(1,10)( mkStdGen 8 ) )
<lambdabot> [6,6,1,10,10,10,10,10]
<siti> sorear: a nice way :p e.g. timerCall 500 (somefunction)
<sorear> @pl \n f -> forkIO (threadDelay n >> f) --siti
<lambdabot> (forkIO .) . (>>) . threadDelay
<darrint> sorear: I got it. I put "[]" in package.conf and ghc-pkg was happy.
<iron32> so if I take 1 from a stream of random numbers then it is a Int and not within a Monad ?
<siti> hmm forkIO wont interact well with gtk2hs, and os level threads are to expensive I suppose I will just use gtk2hs functions then :p
<nmessenger> if you use mkStdGen, you get a pure RNG, so it won't be in the monad
<nmessenger> but if you just want one, you should just use randomR
<nmessenger> > randomR (1,10) (mkStdGen 42)
<lambdabot> (2,1720602 40692)
<nmessenger> > randomR (1,10) (read "1720602 40692")
<lambdabot> Add a type signature
<iron32> nmessenger I think you are missing a s it is "randomRs"
<nmessenger> the -s versions give you an infinite list, the non-s versions give you one value and an updated RNG.
<iron32> Hmm I have a lot to learn
<iron32> oh I see so I can get just one
<nmessenger> > fst $ randomR (1,10) (mkStdGen 42)
<lambdabot> 2
<nmessenger> > randomR (1,10) (snd $ randomR (1,10) (read mkStdGen 42)) -- using the updated RNG
<lambdabot> Couldn't match expected type `String'
<nmessenger> bleh
<nmessenger> > randomR (1,10) (snd $ randomR (1,10) (mkStdGen 42)) -- had 'read' for some reason :/
<lambdabot> (2,128694412 1655838864)
<nmessenger> basically, when you call a function it returns a (value, updatedRng) pair. You can use the value and pass the updated RNG into the next call.
<iron32> well this should make my life so much easier thanks all
<iron32> actually your random numbers did not seem to work they retun the same number everytime I guess thats why I need a monad since that is strcitly a side effect
<nmessenger> it looked like it worked, it just returned 2 twice
<sendark> @hoogle Parse error in pattern
<lambdabot> Did you mean: Parse Error In Pattern
<sendark> yes
<iron32> I returns 2 every single time for me
<sendark> @hoogle Parse Error In Pattern
<lambdabot> No matches, try a more general search

Previous Page  Next Page

Search ircarchive.info