#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 10 11 12
Top Prev 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 Next
#haskell
<LoganCapaldo> nmessenger, that doesn't exist, shh!
<LoganCapaldo> implementation detail, implementation detail!
<iron32> nmessenger PerformUnsfeIO is evil
<nmessenger> :)
<nmessenger> do pureInt <- someIoInt; return (someFunctionOn pureInt)
<allbery_b> do { x <- something_producing_IO_Int; return (myPureFunc x) } where myPureFunc n = {- pure code here -}
<nmessenger> heh
<nmessenger> @undo do x <- action; return (f x)
<lambdabot> action >>= \ x -> return (f x)
<nmessenger> @pl action >>= \ x -> return (f x)
<lambdabot> f `fmap` action
<nmessenger> ^^ another way to write the same thing.
<allbery_b> something_producing_IO_Int >>= return . myPureFunc {- yet another way to write it -}
<beelsebob_> (or darcs knowledgable people)
<LoganCapaldo> @type liftM2 (+)
<lambdabot> forall a1 (m :: * -> *). (Num a1, Monad m) => m a1 -> m a1 -> m a1
<LoganCapaldo> liftM2 (+) ioInt (return pureInt)
<LoganCapaldo> for yet another way
<nmessenger> but that's ugly! To much IO!
<nmessenger> too* even
<allbery_b> (+3) `liftM` ioInt -- :)
<LoganCapaldo> I'll let lambdabot tells me when it's too ugly :)
<allbery_b> lambdabot doesn't care about ugly :)
<nmessenger> You use (>>=) to connect actions together, the reason you can't escape the monad is because (>>=) requires its second argument to eventually end up in the same monad.
<allbery_b> @quote flip-stream
<lambdabot> fishkandy says: xpika, apparently pl also doubles as the command for producing an unintelligible flip-stream :-)
<LoganCapaldo> (+pureInt) `liftM` ioInt -- you mean
<nmessenger> but in the meantime, it uses the pure value from the first action when making the second action
<allbery_b> sure, but I was using (+3) earlier as my example
<nmessenger> @type (>>=)
<lambdabot> forall (m :: * -> *) a b. (Monad m) => m a -> (a -> m b) -> m b
<LoganCapaldo> Bah!
<svref> how do I check if there's a file at /home/foo/blah.txt?
<LoganCapaldo> Open it
<LoganCapaldo> just kidding
<svref> no probeFile then...
<allbery_b> there's also getFileStatus on POSIXish systems
<allbery_b> Win32 has its own functions for that kind of thing as well, but I can't help there
<svref> Opening it sounds like the portable way.
<LoganCapaldo> svref, sometimes people get mad when I suggest things like that
<LoganCapaldo> So I throw on the just kidding just in case
<LoganCapaldo> ;)
<svref> AHA! I KNEW YOU WERE SERIOUS! PREPARE TO DIE!
<svref> hehe
<allbery_b> well, open for read can be unfortunate when it's a unix device file or fifo (and won't work for AF_UNIX sockets)
<sjanssen> svref: I think the best way to do it is with System.Directory
<sjanssen> @type \f -> liftM2 (||) (System.Directory.doesFileExist f) (System.Directory.doesDirectoryExist f)
<lambdabot> FilePath -> IO Bool
<svref> doesFileExist? Wonder why that didn't show when I hoogled "exist"?
<svref> ah, I hoogled "exists". Newbie error.
Previous Page Next Page