Re[2]: [Haskell-cafe] Cont, ContT and IO()

2009-07-04 Thread Bulat Ziganshin
Hello Matthias, Saturday, July 4, 2009, 6:39:30 PM, you wrote: > Or use a fold: >> process' = foldl op True files >> op True file = doit file >> op False _ = False foldM, probably, otherwise you will need to execute all actions before running fold -- Best regards, Bulat

Re: [Haskell-cafe] Cont, ContT and IO()

2009-07-04 Thread Matthias Görgens
>> process' = foldl op True files >> op True file = doit file >> op False _ = False Please pardon me. 'doit' should surely be able to do some IO: > import Data.Foldable > import System.IO > process' = foldlM op True files > op True file = doit file > op False _ = return False were DoIt has the

Re: [Haskell-cafe] Cont, ContT and IO()

2009-07-04 Thread Matthias Görgens
> process [] = return () > process (file:files) = do x <- doit file >                          if x>0 then process files >                                 else return () Or use a fold: > process' = foldl op True files > op True file = doit file > op False _ = False ___

Re: [Haskell-cafe] Cont, ContT and IO()

2009-07-03 Thread Bulat Ziganshin
Hello Günther, Saturday, July 4, 2009, 3:11:23 AM, you wrote: > I've got an IO action, some file system IO, traversing one level only and > iterating over files found. I wish to build in an "early" exit, ie. if an > IO action in the loop encounters a particular value I want it to abort the > loop

Re: [Haskell-cafe] Cont, ContT and IO()

2009-07-03 Thread wren ng thornton
Günther Schmidt wrote: Hi, I've got an IO action, some file system IO, traversing one level only and iterating over files found. I wish to build in an "early" exit, ie. if an IO action in the loop encounters a particular value I want it to abort the loop. Now so far, pls don't shoot, I hav

Re: [Haskell-cafe] Cont, ContT and IO()

2009-07-03 Thread jeff p
Couldn't resist taking the bait... > Well, continuations come from Scheme, and by and large, they are usually > used in languages like Scheme (i.e. PLT web server), or Smalltalk (Seaside > web server), > For a fuller history of continuatios, please see "The Discoveries of Continuations" by John Re

Re: [Haskell-cafe] Cont, ContT and IO()

2009-07-03 Thread Thomas Schilling
Here's some code I wrote the other day: hasCycle :: (Applicative m, MonadIO m) => Node -> m Bool hasCycle n0 = runContT (*callCC* go) return where go *abort* = do visit [] IM.empty n0 return False where visit preds h n = do nid <- nodeId n h' <- foldM (

Re: [Haskell-cafe] Cont, ContT and IO()

2009-07-03 Thread Tim Wawrzynczak
Well, continuations come from Scheme, and by and large, they are usually used in languages like Scheme (i.e. PLT web server), or Smalltalk (Seaside web server), but they can be very useful in e.g. cases like yours for making a convenient way to make a local exit. I did this in one toy game program

[Haskell-cafe] Cont, ContT and IO()

2009-07-03 Thread Günther Schmidt
Hi, I've got an IO action, some file system IO, traversing one level only and iterating over files found. I wish to build in an "early" exit, ie. if an IO action in the loop encounters a particular value I want it to abort the loop. Now so far, pls don't shoot, I have done this by throwi