[Haskell-beginners] question about any

Chaddaï Fouché chaddai.fouche at gmail.com
Thu Dec 29 10:59:46 CET 2011


On Thu, Dec 29, 2011 at 8:29 AM, Tim Baumgartner
<baumgartner.tim at googlemail.com> wrote:
> 2011/12/29 Manfred Lotz <manfred.lotz at arcor.de>
>>
>> Hi there,
>> might be trivial but anyway.
>>
>> I have a usage of 'any' and 'all' but I only have a predicate
>> p :: a -> IO Bool.
>>
>> I wrote my own functons for this:
>>
>>
>> mor :: Monad m => [m Bool] -> m Bool
>> mor = liftM or . sequence
....
>> myall p = mand . and' p
>>
>
> Hi Manfred,
>
> have a look here:
> http://hackage.haskell.org/packages/archive/monad-loops/latest/doc/html/Control-Monad-Loops.html#v:allM
>

Note that your functions and those of Control.Monad.Loops don't do the
same thing : yours don't short circuit, they have to apply the
predicate to all the list elements, C.M.L gives you short-circuiting
combinators, that answer as soon as possible. You probably want C.M.L
behaviour for performance. (I'm lying a bit here, in fact in certain
monads (lazy ones), yours could be short-circuiting too, but in IO for
instance, that is not the case)

-- 
Jedaï



More information about the Beginners mailing list