[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    Re: [Haskell-cafe] foldlWhile
From:       Jorge Adriano Aires <jadrian () mat ! uc ! pt>
Date:       2004-11-20 16:55:08
Message-ID: 200411201655.08590.jadrian () mat ! uc ! pt
[Download RAW message or body]

(opss just noticed I did a reply-to)

> > The following is closer to the original, but doesn't work when the whole
> > list is folded (i.e., p always satisfied):
> > foldlWhile f p a = head . dropWhile p . scanl f a
>
> Serge's version returns the last 'a' that satisfies 'p', while yours
Not really.

> returns the first 'a' that does not satisfy 'p'.  This should be an
> equivalent version:
Yeap, just like his, 

foldlWhile :: (a -> b -> a) -> (a -> Bool) -> a -> [b] -> a
foldlWhile    f                p              a    bs  =
<snip>
(_,     False) -> a
<snip>

It tests the accumulator with p, and returns it on "false".

J.A.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic