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
>> 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
> 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
___
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
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
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
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 (
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
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